function DebugWidget() { //************************ //Private member variables //************************ //Debugger state-keeping variables var _debugOn = false; var _pauseSelector = false; var _elements = new Array(); var _itemSelected = false; //Used to prevent multiple elements from being highlighted //Page elements var _mainDiv; var _textDiv; var _editingDiv; var _unpauseButton; var _closeEditorButtonButton; var _xmlStatusBar; var _saveButton; //Editor state-keeping variables var _currentFilepath; var _currentNodename; var _currentName; var _currentMatch; var _currentNamespace; var createDebugDiv = function() { _mainDiv = $("
", {"id":"debugDiv"}); _mainDiv.css( { "position":"fixed", "font-size":"0.7em", "bottom":"0px", "height":"300px", "width":"100%", "background":"white", "border":"1px black solid", "padding":"5px", "z-index":100 }); _editingDiv = $("
"); var toolBarDiv = $("
"); toolBarDiv.css({"height":"40px"}); var buttonDiv = $("
"); buttonDiv.css("float", "left"); toolBarDiv.append(buttonDiv); _textDiv = $("
"); _textDiv.css({"overflow":"auto", "width":"100%", "height":"260px"}); var pickElementButton = $(""); pickElementButton.click(function() { if(!_debugOn) { pickElementButton.attr("value", "Disable debugging"); $("a").click(function(e) { e.preventDefault(); }); _debugOn = true; } else { pickElementButton.attr("value", "Enable debugging"); $("a").off("click"); clearAll(); _unpauseButton.attr("disabled", "disabled"); _pauseSelector = false; _debugOn = false; } }); _unpauseButton = $(""); _unpauseButton.click(function() { if(_pauseSelector) { _pauseSelector = false; $(this).attr("disabled", "disabled"); } }); _closeEditorButton = $(""); _closeEditorButton.click(function() { if($(this).val() == "Close editor") { $(this).val("Open editor"); _editingDiv.hide(); _mainDiv.css("height", (_mainDiv.height() - 200) + "px"); } else { $(this).val("Close editor"); _editingDiv.show(); _mainDiv.css("height", (_mainDiv.height() + 200) + "px"); } }); _xmlStatusBar = $(""); _xmlStatusBar.css("padding", "5px"); //Check the XML for errors every 2 seconds setInterval(function() { var editor = _editingDiv.find("textarea"); if(editor.length) { var xmlString = editor.val(); try { var xml = $.parseXML('' + xmlString + ""); } catch(error) { console.log(error); _xmlStatusBar.text("XML ERROR! (Mouse over for details)"); _xmlStatusBar.css({"color":"white", "background":"red"}); _xmlStatusBar.attr("title", error); _saveButton.attr("disabled", "disabled"); return; } _xmlStatusBar.text("XML OK!"); _xmlStatusBar.css({"color":"white", "background": "green"}); _xmlStatusBar.removeAttr("title"); if(_saveButton.val() == "Save changes") { _saveButton.removeAttr("disabled"); } } }, 2000); _saveButton = $(""); _saveButton.click(function() { var editor = _editingDiv.find("textarea"); if(editor.length) { var xmlString = editor.val(); try { var xml = $.parseXML('' + xmlString + ""); } catch(error) { alert("Could not save as there is a problem with the XML."); return; } var url = gs.xsltParams.library_name; var parameters = {"a":"g", "rt":"r", "s":"SaveXMLTemplateToFile", "s1.filePath":_currentFilepath, "s1.namespace":_currentNamespace, "s1.nodename":_currentNodename, "s1.xml":xmlString}; if(_currentName && _currentName.length > 0){parameters["s1.name"] = _currentName;} if(_currentMatch && _currentMatch.length > 0){parameters["s1.match"] = _currentMatch;} _saveButton.val("Saving..."); _saveButton.attr("disabled", "disabled"); $.post(url, parameters) .success(function() { $.ajax(gs.xsltParams.library_name + "?a=s&sa=c") .success(function() { alert("The template has been saved successfully."); }) .error(function() { alert("Error reloading collection."); }) .complete(function() { _saveButton.val("Save changes"); _saveButton.removeAttr("disabled"); }); }) .error(function() { alert("There was an error sending the request to the server, please try again."); }); } }); var minimiseButton = $("", {"src":gs.imageURLs.collapse}); minimiseButton.css({"cursor":"pointer", "float":"right", "margin-right":"20px"}); minimiseButton.click(function() { if($(this).attr("src") == gs.imageURLs.collapse) { _textDiv.hide(); $(this).attr("src", gs.imageURLs.expand); _mainDiv.css("height", (_mainDiv.height() - 260) + "px"); } else { _textDiv.show(); $(this).attr("src", gs.imageURLs.collapse); _mainDiv.css("height", (_mainDiv.height() + 260) + "px"); } }); var clear = $(""); clear.css("clear", "both"); toolBarDiv.append(minimiseButton); toolBarDiv.append(clear); buttonDiv.append(pickElementButton); buttonDiv.append(_unpauseButton); buttonDiv.append(_closeEditorButton); buttonDiv.append(_xmlStatusBar); buttonDiv.append(_saveButton); _mainDiv.append(_editingDiv); _mainDiv.append(toolBarDiv); _mainDiv.append(_textDiv); } var clearAll = function() { _itemSelected = false; $(_elements).each(function() { $(this).remove(); }); } var highlightElement = function(e) { var topBorderDiv = $("
"); var bottomBorderDiv = $("
"); var leftBorderDiv = $("
"); var rightBorderDiv = $("
"); topBorderDiv.css({"position":"absolute", "top":e.offset().top + "px", "left":e.offset().left + "px", "height":"0px", "width":e.width() + "px", "border":"1px solid red"}); bottomBorderDiv.css({"position":"absolute", "top":(e.offset().top + e.height()) + "px", "left":e.offset().left + "px", "height":"0px", "width":e.width() + "px", "border":"1px solid red"}); leftBorderDiv.css({"position":"absolute", "top":e.offset().top + "px", "left":e.offset().left + "px", "height":e.height() + "px", "width":"0px", "border":"1px solid red"}); rightBorderDiv.css({"position":"absolute", "top":e.offset().top + "px", "left":(e.offset().left + e.width()) + "px", "height":e.height() + "px", "width":"0px", "border":"1px solid red"}); $("body").append(topBorderDiv, bottomBorderDiv, leftBorderDiv, rightBorderDiv); _elements.push(topBorderDiv); _elements.push(bottomBorderDiv); _elements.push(leftBorderDiv); _elements.push(rightBorderDiv); } var addMouseEventsToInfoContainer = function(infoContainer, filepath, nodename, namespace, name, match) { infoContainer.click(function() { _currentFilepath = filepath; _currentNodename = nodename; _currentNamespace = namespace; _currentName = name; _currentMatch = match; var responseName = "requestedNameTemplate"; var url = gs.xsltParams.library_name + "?a=g&rt=r&s=RetrieveXMLTemplateFromFile&s1.filePath=" + _currentFilepath + "&s1.namespace=" + _currentNamespace + "&s1.nodename=" + _currentNodename; if(_currentMatch && _currentMatch.length > 0){url += "&s1.match=" + _currentMatch; responseName = "requestedMatchTemplate";} if(_currentName && _currentName.length > 0){url += "&s1.name=" + _currentName;} $.ajax(url) .success(function(response) { var template; if(response.search(responseName) != -1) { var startIndex = response.indexOf("<" + responseName + ">") + responseName.length + 2; var endIndex = response.indexOf(""); template = response.substring(startIndex, endIndex); } else { return; } var editArea = $("