1 line
8 KiB
JavaScript
1 line
8 KiB
JavaScript
|
function PageFrontEditInit($){var buttons=$(".pw-edit-buttons");var ckeditors={};var tinymces={};var isTouch="ontouchstart"in window||navigator.MaxTouchPoints>0||navigator.msMaxTouchPoints>0;var busy=false;function setBusy(value){busy=value;if(busy){$("body").addClass("pw-busy")}else{$("body").removeClass("pw-busy")}}function loadCSS(file){$("<link/>",{rel:"stylesheet",type:"text/css",href:file}).appendTo("head")}function ckeBlurEvent(event){var editor=event.editor;if(editor.checkDirty()){var el=$(editor.element.$);if(el.length){el.closest(".pw-edit").addClass("pw-changed")}}}function inlineEditEvent(e,t,orig,copy){if(t.hasClass("pw-editing")||busy)return;var copyID=copy.attr("id");var name=t.attr("data-name");t.addClass("pw-editing pw-edited");if(!copy.data("prev"))copy.data("prev",copy.html());orig.hide();copy.show();buttons.show();if(t.hasClass("pw-edit-InputfieldCKEditor")&&typeof CKEDITOR!=="undefined"){if(typeof ckeditors[copyID]=="undefined"){var editor=CKEDITOR.inline(copyID,ProcessWire.config["InputfieldCKEditor_"+name]);ckeditors[copyID]=editor;editor.on("blur",function(e){t.removeClass("pw-editing");ckeBlurEvent(e)});editor.on("change",ckeBlurEvent)}}else if(t.hasClass("pw-edit-InputfieldTinyMCE")){if(typeof tinymces[copyID]==="undefined"){InputfieldTinyMCE.init("#"+copyID,"PageFrontEdit");var editor=tinymce.get(copyID);tinymces[copyID]=editor;editor.on("dirty change",function(e){t.addClass("pw-changed")})}}setTimeout(function(){copy.trigger("focus")},250)}function inlineInitEditableRegion(t){var orig=t.children(".pw-edit-orig");var copy=t.children(".pw-edit-copy");var name=t.attr("data-name");copy.hide();orig.show();if(isTouch)orig.on("pwdoubletap",function(e){inlineEditEvent(e,t,orig,copy);return false});orig.on("dblclick",function(e){inlineEditEvent(e,t,orig,copy);return false});if(t.is("span")){copy.on("keydown",function(e){if(e.keyCode==13){e.preventDefault();$(this).trigger("blur")}})}if(orig.find("a").length){var clicks=0,timer=null,allowClick=false;orig.on("click","a",function(){var $a=jQuery(this);if(allowClick){allowClick=false;return true}clicks++;if(clicks===1){timer=setTimeout(function(){clicks=0;allowClick=true;$a[0].click();return true},700)}else{clearTimeout(timer);allowClick=false;clicks=0;orig.trigger("dblclick")}return false});orig.on("dblclick","a",function(){return false})}if(!t.hasClass("pw-edit-InputfieldCKEditor")&&!t.hasClass("pw-edit-InputfieldTinyMCE")){copy.on("blur",function(){var copy=$(this);var t=copy.closest(".pw-editing");if(t.length==0)return;if(copy.html()!=copy.data("prev")){t.addClass("pw-changed")}t.removeClass("pw-editing")})}}function inlineAbandonAllChanges(){$(".pw-edited").each(function(){var t=$(this);var copy=t.children(".pw-edit-copy");var orig=t.children(".pw-edit-orig");copy.hide().html(copy.data("prev"));orig.show();copy.data("prev",null);t.removeClass("pw-changed pw-edited pw-editing")});buttons.hide()}function inlineCancelClickEvent(){if($(".pw-changed").length>0){if(confirm(ProcessWire.config.PageFrontEdit.labels.cancelConfirm)){inlineAbandonAllChanges();buttons.hide()}else{}}else{inlineAbandonAllChanges()}return false}function inlineSaveClickEvent(){if(busy)return;setBusy(true);var pageID=parseInt($("#Inputfield_id").val());var langID=parseInt($("#pw-edit-lang").val());var btnSave=$(".pw-edit-save");var btnCancel=$(".pw-edit-cancel");var btnSaving=$(".pw-edit-saving");var btnSaved=$(".pw-edit-saved");var edited=$(".pw-changed");var postData={action:"PageFrontEditSave",id:pageID,language:langID,fields:{}};var postToken=$("input._post_token");var csrfName=postToken.attr("name");var csrfValue=postToken.val();postData[csrfName]=csrfValue;edited.each(function(){var t=$(this);var name=t.attr("data-name");var page=parseInt(t.attr("data-page"));var orig=t.children(".pw-edit-orig");var copy=t.children(".pw-edit-copy");var key=page+"__"+name;if(t.hasClass("pw-edit-InputfieldCKEditor")){var editor=ckeditors[copy.attr("id")];editor.getSelection().reset();editor.getSelection().removeAllRanges();postData.fields[key]=editor.getData()}else if(t.hasClass("pw-edit-Inputfiel
|