/*
 Online Page Editor Add-on
 Version: 1.2.0
 (c) 2011 DMXzone.com
 @build 03-10-2011 15:42:36
*/
(function(b){var x={actionUrl:"dmxPageEditor.asp",activationMethod:"key",activationKey:"ctr+shft+@",activationSelector:"",editDreamweaverRegions:!0,editableRegionsList:"",securityMethod:"user"};b.fn.dmxPageEditor=function(k){function p(){document.location.protocol=="file:"?alert("Can not run Online Page Editor from local file!\nPlease run this page through a web server!"):b(".dmxActivator").length>0||e?(l(),y()):d.securityMethod=="login"?require([g+"jquery.simplemodal.min.js",g+"jquery.crypt.js"],
function(){b.modal('<div id="dmxPageEditorLogin_status">\n<h1>LOGIN</h1><div id="login_response"></div>\n<form id="login" action="">\n<label>Username</label><input type="text" class="txtfield" id="dmx_login_username" name="username"><br />\n<label>Password</label><input type="password" class="txtfield" id="dmx_login_password" name="password"><br />\n<label>&nbsp;</label><input value="Login" name="Login" id="dmxPageEditorLogin_submit" type="submit" />\n<div id="ajax_loading"><img align="absmiddle" src="'+
q+'dmxPageEditor/spinner.gif">&nbsp;Processing...</div>\n</form></div>\n',{containerId:"dmxPageEditorLogin"});r()}):b.ajax({url:i+(h!=""?"?"+h:""),success:function(){c()},error:function(a){a.status==401||a.status==400?alert("Access denied!"):a.status==404&&alert("Can not execute ScriptLibrary/"+d.actionUrl+"\nFile is missing or "+f()+" is not supported on this server!")}})}function r(){b("#dmxPageEditorLogin_status > form").submit(function(){b("#dmxPageEditorLogin_submit").hide();b("#ajax_loading").show();
b.ajax({type:"GET",url:i+"?auth=login&action=token",success:function(a){m=a;a={authorization:b().crypt({method:"md5",source:"username:"+b("#dmx_login_username").val()+":password:"+b("#dmx_login_password").val()+":"+m})};b.ajax({type:"POST",url:i+"?auth=login",data:a,success:function(a){b("#dmxPageEditorLogin_status").ajaxComplete(function(){b("#dmxPageEditorLogin_submit").show();b("#ajax_loading").hide();a=="LOGIN OK"?(s=b("#dmx_login_username").val(),t=b("#dmx_login_password").val(),b.modal.close(),
c()):b("#login_response").html(a)})}})}});return!1})}function c(){u?j():(require([g+"dmxEditor.min.js",g+"css.js!"+q+"dmxEditor.css"],function(){u=!0;j()}),b("body").bind("editor:afterSave",function(a,c){e.html(c.html);var w={page:v,name:e[0].id,html:c.html,type:e.hasClass("dmxActivatorDiv")?"div":"region"};if(d.securityMethod=="login")w.authorization=b().crypt({method:"md5",source:"username:"+s+":password:"+t+":"+m});b.ajax({type:"POST",url:i+"?action=save"+(h!=""?"&"+h:""),data:w,success:function(a){var b=
a.indexOf("ERROR: [");if(b!=-1){var d=a.indexOf("]",b+9);alert("Server Error:\n"+a.substring(b+8,d))}else alert("Save successful!"),l(),window.location.reload(!0)},error:function(a,b,c){a.status==401||a.status==400?alert("Access denied!"):a.status==500?(b=a.responseText,c=b.indexOf("ERROR: ["),c!=-1?(a=b.indexOf("]",c+9),alert("Server Error:\n"+b.substring(c+8,a))):alert("Server Error, response:\n"+a.responseText)):a.status==404?alert("Can not execute ScriptLibrary/"+d.actionUrl+"\nFile is missing or "+
f()+" is not supported on this server!"):alert("Error "+c+", code: "+a.status)}})}),b("body").bind("editor:removed",function(){e&&(n(e),e=null)}))}function j(){if(d.editableRegionsList!=""){var a=("#"+d.editableRegionsList.replace(/\s*,\s*/gi,",#")).replace(/##/gi,"#");n(b(a).addClass("dmxActivatorDiv"))}d.editDreamweaverRegions&&n(b("body").getEditableRegions());b(".dmxPageEditorIcons,.dmxPageEditorIconsBottom").live("click",function(){z(this)})}function f(){return d.actionUrl=="dmxPageEditor.asp"?
"ASP":"PHP"}function n(a){a&&a.addClass("dmxActivator").each(function(){var a=b(this).offset();b(this).prepend('<div class="dmxPageEditorIcons'+(a.top<22?"Bottom":"")+'"><img src="'+q+'dmxEditor/pencil.png" alt="Click to edit this region" title="Click to edit this region" /></div>')})}function y(){b(".dmxActivator").each(function(){b(".dmxPageEditorIcons .dmxPageEditorIconsBottom",this).remove()}).removeClass("dmxActivator");b(".dmxPageEditorIcons,.dmxPageEditorIconsBottom").die("click")}function z(a){if(e){var c=
e.data("dmxEditor");if(c&&c.isDocumentModified())if(confirm("The previous editable area is not saved yet. Changes will be lost if you don't save.\nDo you want to save first?")){c.save();return}else l();else l()}e=b(a).parent();b(a).remove();e.removeClass("dmxActivator");a={page:v,name:e[0].id,type:e.hasClass("dmxActivatorDiv")?"div":"region"};if(d.securityMethod=="login")a.authorization=b().crypt({method:"md5",source:"username:"+s+":password:"+t+":"+m});b.ajax({type:"POST",url:i+"?action=load"+(h!=
""?"&"+h:""),data:a,success:function(a){var b=a.indexOf("ERROR: [");if(b!=-1){var c=a.indexOf("]",b+9);alert("Server Error:\n"+a.substring(b+8,c))}else a=="LOGIN OK"?alert("You have an old version of the Page Editor Server files! Please reapply it on the page!"):(d.editorConfig.content=a,e.dmxEditor(d.editorConfig))},error:function(a,b,c){a.status==401||a.status==400?alert("Access denied!"):a.status==500?(b=a.responseText,c=b.indexOf("ERROR: ["),c!=-1?(a=b.indexOf("]",c+9),alert("Server Error:\n"+
b.substring(c+8,a))):alert("Server Error, response:\n"+a.responseText)):a.status==404?alert("Can not execute ScriptLibrary/"+d.actionUrl+"\nFile is missing or "+f()+" is not supported on this server!"):alert("Error "+c+", code: "+a.status)}})}function l(){if(e){var a=e.data("dmxEditor");a&&a.destruct();n(e);e=null}}var d=b.extend(!0,{},x,k);if(!d.editorConfig)d.editorConfig={};b.extend(!0,d.editorConfig,{width:"100%",autoSaveInterval:0,autoIncludeCss:!0,toolbars:{Common:{items:{save:!0,close:!0}}},
extensions:d.editorConfig.extensions?b.merge(["autosize"],d.editorConfig.extensions):["autosize"]});var u=!1,g=function(){var a=b("script[src$='dmxPageEditor.js']");if(a&&a.length>0)return a[0].src.replace(/dmxPageEditor\.js$/i,"").replace(/\s+/g,"%20");return""}(),q=function(){var a="/styles",c=b('link[href*="dmxPageEditor.css"]');c.length>0&&(a=c[0].href.replace(/dmxPageEditor\.css$/i,""));return a}(),v=function(a){a=a.replace(/\/ScriptLibrary\/?$/i,"");return document.location.href.replace(a,"")}(g),
h=d.securityMethod=="user"?"auth=user":d.securityMethod=="login"?"auth=login":"",m="",s="",t="",i=g+d.actionUrl,e;if(d.activationMethod=="key"&&d.activationSelector==""){var o;switch(d.activationKey){case "ctr+shft+@":o=function(a){return(a.ctrlKey||a.metaKey)&&a.shiftKey&&a.which==50};break;case "ctr+f2":o=function(a){return(a.ctrlKey||a.metaKey)&&a.which==113};break;case "ctr+\\":o=function(a){return(a.ctrlKey||a.metaKey)&&a.which==220}}b(document).keydown(function(a){o(a)&&(p(),a.preventDefault())})}else b(d.activationSelector).live("click",
function(a){p();a.preventDefault()})};b.fn.getEditableRegions=function(){var k=b([]);this.each(function(p,r){for(var c=r.firstChild;c;){if(c.nodeType===8){if(c.data.indexOf("InstanceBeginEditable")!=-1){var j=b(),f=c.data.match(/name="([^"]*)"/),f=f&&f.length>0?f[1]:"editor1",c=c.nextSibling;if(!(c.nodeName=="DIV"&&c.id==f)){for(;c;)if(c.nodeType==8&&c.data.indexOf("InstanceEndEditable")!=-1)break;else j.push(c),c=c.nextSibling;j.wrapAll('<div id="'+f+'" class="dmxEditor" style="width:100%" />')}}}else c.nodeType===
1&&(k=k.add(b(c).getEditableRegions()));c=c.nextSibling}});return b(".dmxEditor")}})(jQuery);

