!function(t){"use strict";function e(t){this.editor=t,this.init()}function i(e){var i=this;i.editor=e,i.undoBuf=[],i.undoPtr=-1,i.mode="none",t(i.editor.txtarea).on("keydown keyup",function(t){var e,o=t.keyCode;if(t.ctrlKey||t.metaKey)switch(o){case 17:return!1;case 89:return"keydown"==t.type&&i.redo(),t.preventDefault(),!1;case 90:return"keydown"==t.type&&i.undo(),t.preventDefault(),!1}else"keyup"==t.type&&(o>=33&&o<=40||o>=63232&&o<=63235?e="moving":8==o||46==o||127==o?e="deleting":13==o||32==o?e="whitespace":27==o?e="escape":(o<16||o>20)&&91!=o&&32!=o&&(e="typing"));"keyup"==t.type&&i.saveState(e)}).on("click drop paste",function(t){var e="paste";"click"==t.type&&(e="moving"),i.saveState(e)}),i.saveState("none")}e.prototype.init=function(){var t=this;t.editor.getSelectionRange(),t.selectionStart=t.editor.txtarea.selectionStart,t.selectionEnd=t.editor.txtarea.selectionEnd,t.scrollTop=t.editor.txtarea.scrollTop,t.value=t.editor.txtarea.value},e.prototype.restore=function(){this.editor.txtarea.value=this.value,this.editor.txtarea.scrollTop=this.scrollTop,this.editor.setSelectionRange(this.selectionStart,this.selectionEnd),t(window).trigger("resize")},e.prototype.isUnchanged=function(){var t=this.editor.txtarea;return this.editor.getSelectionRange(),t.selectionStart==this.selectionStart&&t.selectionEnd==this.selectionEnd&&t.scrollTop==this.scrollTop&&t.value==this.value},i.prototype.updateGui=function(){var t=this.editor.container.find(".ui-natedit-undo"),e=this.editor.container.find(".ui-natedit-redo");this.canUndo()?t.button("enable"):t.button("disable"),this.canRedo()?e.button("enable"):e.button("disable")},i.prototype.canUndo=function(){return this.undoPtr>0},i.prototype.canRedo=function(){return void 0!==this.undoBuf[this.undoPtr+1]},i.prototype.getCurrentState=function(){return this.undoBuf[this.undoPtr]},i.prototype.saveState=function(i){var o=this,n=o.getCurrentState();if(void 0!==n){if(n.isUnchanged())return;if(n.value==o.editor.txtarea.value||"none"!=i&&i==o.mode||"whitespace"===i&&"typing"===o.mode)return t.log("NATEDIT: reuse current state in mode=",i),o.mode=i,void n.init()}t.log("NATEDIT: mode=",i),o.mode=i,o.undoPtr++,t.log("NATEDIT: save state at undoPtr=",o.undoPtr),n=new e(o.editor),o.undoBuf[o.undoPtr]=n,o.undoBuf[o.undoPtr+1]=void 0,o.updateGui()},i.prototype.undo=function(){t.log("NATEDIT: called undo"),this.canUndo()?(this.undoPtr--,t.log("NATEDIT: ... undoing undoPtr=",this.undoPtr),this.undoBuf[this.undoPtr].restore(),this.mode="none",this.updateGui()):t.log("... can't undo")},i.prototype.redo=function(){this.canRedo()?(this.undoPtr++,t.log("NATEDIT: ... redoing undoPtr=",this.undoPtr),this.undoBuf[this.undoPtr].restore(),this.mode="none",this.updateGui()):t.log("NATEDIT: ... can't redo")},t.NatEditor=function(e,o){var n=this,a=t(e);n.opts=t.extend({},o,a.data()),n.txtarea=e,n.id=foswiki.getUniqueID(),n.form=t(e.form),void 0===n.txtarea.selectionStart&&(n.oldIE=!0),t.log("NATEDIT: opts=",n.opts),n.opts.autoResize&&(n.opts.autoMaxExpand=!1,n.opts.resizable=!1),a.addClass("ui-natedit ui-widget"),n.initGui(),n.undoManager=new i(n),n.opts.showToolbar&&n.initToolbar(),n.initForm(),n.opts.autoMaxExpand&&(a.addClass("ui-natedit-autoexpand"),n.autoMaxExpand(),n.container.parent().css("cssText","height: auto !important")),n.opts.autoResize&&(n.initAutoExpand(),n.autoResize()),a.on("keydown",function(t){13==t.keyCode?n.handleLineFeed(t):9==t.keyCode&&n.handleTab(t)})},t.NatEditor.prototype.handleTab=function(t){var e,i,o;this.getSelectionRange(),i=this.txtarea.selectionStart,o=this.txtarea.selectionEnd,t.shiftKey?((e=this.txtarea.value).length,i>2&&" "==e.substring(i-3,i)&&(this.setSelectionRange(i-3,o),this.remove())):(this.insert(" "),this.setCaretPosition(i+3)),t.preventDefault()},t.NatEditor.prototype.handleLineFeed=function(t){var e,i,o,n,a,r,s;for(o=this.txtarea.value,this.getSelectionRange(),e=this.txtarea.selectionStart,i=this.txtarea.selectionEnd;e>0&&13!=o.charCodeAt(e-1)&&10!=o.charCodeAt(e-1);)e--;n=o.substring(e,i),t.shiftKey?n.match(/^((?: {3})+)([AaIi]\.?|\*|\d+| ) /)&&(a=RegExp.$1+RegExp.$2.replace(/./g," ")+" "):n.match(/^( {3})+([AaIi]\.?|\*|\d+) *$/)?a="":n.match(/^((?: {3})+([AaIi]\.?|\*) )/)?a=RegExp.$1:n.match(/^(?:((?: {3})+)(\d+) )/)&&(a=RegExp.$1+(parseInt(RegExp.$2,10)+1)+" "),void 0!==a&&(""==a?(r=o.substr(0,e),s=o.substr(i),i=e):(r=o.substr(0,i),s=o.substr(i),a=this.oldIE?"\r\n"+a:"\n"+a),this.txtarea.value=r+a+s,this.setCaretPosition(r.length+a.length),this.undoManager.saveState("command"),t.preventDefault())},t.NatEditor.prototype.initAutoExpand=function(){var e,i=this,o=t(i.txtarea);i.helper=t('').appendTo("body"),e={fontFamily:o.css("fontFamily")||"",fontSize:o.css("fontSize")||"",fontWeight:o.css("fontWeight")||"",fontStyle:o.css("fontStyle")||"",fontStretch:o.css("fontStretch")||"",fontVariant:o.css("fontVariant")||"",letterSpacing:o.css("letterSpacing")||"",textTransform:o.css("textTransform")||"",textIndent:o.css("textIndent")||"",wordSpacing:o.css("wordSpacing")||"",lineHeight:o.css("lineHeight")||"",padding:o.css("padding")||"",textWrap:"unrestricted"},i.helper.css(e),"onpropertychange"in i.txtarea?"oninput"in i.txtarea?o.on("input.natedit keyup.natedit",function(){i.autoResize()}):o.on("propertychange.natedit",function(t){"value"===t.propertyName&&i.autoResize()}):o.on("input.natedit",function(){i.autoResize()}),t(window).on("resize.natedit",function(){i.autoResize()})},t.NatEditor.prototype.initGui=function(){function e(e){var i=e.currentValues,n=t(e.input).data("permType");t.log("NATEDIT: currentValues="+i.join(", ")),o.setPermission(n,{allow:i.join(", ")})}function i(t){"details"===t.perms?o.showPermDetails(t.permType):(o.hidePermDetails(t.permType),o.setPermission(t.permType,t.perms))}var o=this,n=t(o.txtarea);o.container=n.wrap('
').parent(),o.container.attr("id",o.id),o.container.data("natedit",o),"undefined"!=typeof tinyMCE&&o.container.addClass("ui-natedit-wysiwyg-enabled"),foswiki.getPreference("NatEditPlugin").FarbtasticEnabled&&o.container.addClass("ui-natedit-colorpicker-enabled"),o.opts.resizable&&(void 0===o.txtarea.style.resize?n.resizable():n.css("resize","both")),o.form.find(".ui-natedit-details-container input").on("blur",function(){var e=t(this);e.trigger("AddValue",e.val())}).textboxlist({onSelect:e,onDeselect:e,onClear:e,onReset:e,autocomplete:foswiki.getScriptUrl("view",o.opts.systemWeb,"JQueryAjaxHelper",{section:"user",skin:"text",contenttype:"application/json"})}),o.form.find(".ui-natedit-permissions-form input[type=radio]").on("click",function(){i(t(this).data())}),o.form.find(".ui-natedit-permissions-form input[type=radio]:checked").not(":disabled").each(function(){i(t(this).data())}),"undefined"!=typeof FoswikiTiny?(o.origSwitchToRaw=FoswikiTiny.switchToRaw,FoswikiTiny.switchToRaw=function(e){o.tinyMCEInstance=e,o.origSwitchToRaw(e),o.showToolbar(),t("#"+e.id+"_2WYSIWYG").remove()}):n.removeClass("foswikiWysiwygEdit")},t.NatEditor.prototype.switchToWYSIWYG=function(t){void 0!==this.tinyMCEInstance&&(this.hideToolbar(),tinyMCE.execCommand("mceToggleEditor",null,this.tinyMCEInstance.id),FoswikiTiny.switchToWYSIWYG(this.tinyMCEInstance))},t.NatEditor.prototype.initToolbar=function(){var e=this,i=t(e.txtarea),o=foswiki.getScriptUrl("rest","JQueryPlugin","tmpl",{topic:e.opts.web+"."+e.opts.topic,load:e.opts.toolbar});t.loadTemplate({url:o}).done(function(o){e.toolbar=t(o.render({web:e.opts.web,topic:e.opts.topic})),e.container.prepend(e.toolbar),e.toolbar.find(".ui-natedit-buttons").buttonset({}).on("click",function(i){return e.handleToolbarAction(i,t(i.target).closest("a:not(.ui-natedit-menu-button)")),!1}),e.toolbar.find(".ui-natedit-button").button().on("click",function(i){return e.handleToolbarAction(i,t(this)),!1}),e.toolbar.find(".ui-natedit-menu-button").not(".ui-button").button().end().button("option",{icons:{secondary:"ui-icon-triangle-1-s"}}).on("mousedown",function(i){var o=t(this),n=void 0===o.data("menu")?o.next():t(e.container.find(o.data("menu"))),a=n.data("state")||!1;return n.data("menu-button",this),e.hideMenus(),a?o.removeClass("ui-state-highlight"):(o.addClass("ui-state-highlight"),n.show().position({my:"left top",at:"left bottom+10",of:o}),n.data("state",!0)),!1}).on("click",function(){return!1}),e.toolbar.find(".ui-natedit-menu").each(function(){var i,o=t(this),n=!1;o.menu().on("mouseleave",function(){i=window.setTimeout(function(){},1e3)}).on("mouseenter",function(){void 0!==i&&(window.clearTimeout(i),i=void 0)}).on("menuselect",function(t,i){t.target=o.data("menu-button"),n&&(e.hideMenus(),e.handleToolbarAction(t,i.item.children("a:first")))}).children().on("mouseup",function(t){n=!0,o.menu("select",t),n=!1}).on("click",function(){return!1})}),t(e.container).on("click",function(){e.hideMenus()}),e.opts.autoHideToolbar&&(e.toolbar.hide(),i.focus(function(){window.setTimeout(function(){e.showToolbar()})}),i.blur(function(){window.setTimeout(function(){e.hideToolbar()})})),e.undoManager.updateGui(),t(window).trigger("resize")})},t.NatEditor.prototype.showToolbar=function(){var e;void 0===this.toolbar&&this.initToolbar(),void 0!==this.toolbar&&(e=this.txtarea.value,this.toolbar.show(),this.txtarea.value=e,this.opts.autoMaxExpand&&t(window).trigger("resize"))},t.NatEditor.prototype.hideToolbar=function(){var e;this.toolbar&&(e=this.txtarea.value,this.toolbar.hide(),this.txtarea.value=e,this.opts.autoMaxExpand&&t(window).trigger("resize"))},t.NatEditor.prototype.setPermission=function(e,i){var o,n;this.form.find(".permset_"+e).each(function(){t(this).val("undefined")});for(o in i)i.hasOwnProperty(o)&&(n=i[o],t.log("NATEDIT: setting ."+o+"_"+e+"="+n),this.form.find("."+o+"_"+e).val(n))},t.NatEditor.prototype.showPermDetails=function(e){var i,o=[];this.form.find(".ui-natedit-"+e+"-perms .ui-natedit-details-container").slideDown(300),this.form.find("input[name='Local+PERMSET_"+e.toUpperCase()+"_DETAILS']").each(function(){(i=t(this).val())&&""!=i&&o.push(i)}),o=o.join(", "),t.log("NATEDIT: showPermDetails - names="+o),this.setPermission(e,{allow:o})},t.NatEditor.prototype.hidePermDetails=function(t){this.form.find(".ui-natedit-"+t+"-perms .ui-natedit-details-container").slideUp(300),this.setPermission(t)},t.NatEditor.prototype.showMessage=function(e,i,o){t.pnotify({title:o,text:i,hide:"error"!==e,type:e,sticker:!1,closer_hover:!1,delay:"error"===e?8e3:1e3})},t.NatEditor.prototype.hideMessages=function(){t.pnotify_remove_all()},t.NatEditor.prototype.extractErrorMessage=function(e){return e&&e.match(/^ Saving ... "}),i.form.submit()};return o.length?((e=o.dialog("option","buttons"))[0].click=function(){o.find(".jqCaptcha").data("captcha").validate()&&(o.dialog("close"),n())},o.dialog("option","buttons",e).dialog("open")):n(),!1}),i.form.find(".ui-natedit-checkpoint").on("click",function(e){var o,n=i.opts.topic,a=document.title,r=t("#editcaptcha"),s=function(){var o=t(e.currentTarget).attr("href").replace(/^#/,"");i.form.validate().form()&&(i.beforeSubmit(o),n.match(/AUTOINC|XXXXXXXXXX/)?i.form.submit():i.form.ajaxSubmit({url:foswiki.getScriptUrl("rest","NatEditPlugin","save"),beforeSubmit:function(){i.hideMessages(),document.title="Saving ...",t.blockUI({message:" Saving ...
"})},error:function(t,e,o){var n=i.extractErrorMessage(t.responseText||e);i.showMessage("error",n)},complete:function(e,i){var o=e.getResponseHeader("X-Foswiki-Validation");o&&t("input[name='validation_key']").each(function(){t(this).val("?"+o)}),document.title=a,t.unblockUI()}}))};return r.length?((o=r.dialog("option","buttons"))[0].click=function(){r.find(".jqCaptcha").data("captcha").validate()&&(r.dialog("close"),s())},r.dialog("option","buttons",o).dialog("open")):s(),!1}),i.form.find(".ui-natedit-preview").on("click",function(){return i.form.validate().form()&&(i.beforeSubmit("preview"),i.form.ajaxSubmit({url:foswiki.getScriptUrl("rest","NatEditPlugin","save"),beforeSubmit:function(){i.hideMessages(),t.blockUI({message:" Loading preview ...
"})},error:function(e,o,n){var a=i.extractErrorMessage(e.responseText||o);t.unblockUI(),i.showMessage("error",a)},success:function(e,i){var o=t(window),n=Math.round(parseInt(.6*o.height(),10)),a=Math.round(parseInt(.6*o.width(),10));t.unblockUI(),a<640&&(a=640),e=e.replace(/%width%/g,a).replace(/%height%/g,n),t("body").append(e)}})),!1}),i.form.find(".ui-natedit-cancel").on("click",function(){return i.hideMessages(),t("label.error").hide(),t("input.error").removeClass("error"),t(".jqTabGroup a.error").removeClass("error"),i.beforeSubmit("cancel"),i.form.submit(),!1}),i.form.find(".ui-natedit-replaceform").on("click",function(){return i.beforeSubmit("replaceform"),i.form.submit(),!1}),i.form.find(".ui-natedit-addform").on("click",function(){return i.beforeSubmit("addform"),i.form.submit(),!1}),e=t.extend({},i.form.metadata({type:"attr",name:"validate"})),i.form.validate({meta:"validate",invalidHandler:function(e,o){var n=o.numberOfInvalids(),a=t(o.currentForm);if("action_cancel"==a.find("input[name*='action_'][value='Cancel']").attr("name"))return o.currentForm.submit(),void(o.errorList=[]);n?(t.unblockUI(),i.showMessage("error",t.i18n("One or more fields have not been filled correctly")),t.each(o.errorList,function(){t(this.element).parents(".jqTab").each(function(){var e=t(this).attr("id");t("[data="+e+"]").addClass("error")})})):(i.hideMessages(),a.find(".jqTabGroup a.error").removeClass("error"))},rules:e,ignoreTitle:!0,errorPlacement:function(e,i){i.is("[type=checkbox],[type=radio]")?t("").appendTo(i.parents("tr:first")).append(e):e.insertAfter(i)}}),t.validator.addClassRules("foswikiMandatory",{required:!0}))},t.NatEditor.prototype.handleToolbarAction=function(t,e){var i,o,n=this,a=function(){},r=function(){},s=function(){},d=function(){return{web:n.opts.web,topic:n.opts.topic,selection:n.getSelection()}};void 0!==e&&0!==e.length&&(void 0!==(i=e.data()).markup&&(i.value=n.opts[i.markup]),void 0!==i.value&&("line"===i.type?n.insertLineTag(i.value):n.insertTag(i.value)),void 0!==i.dialog&&(void 0!==i.okayHandler&&"function"==typeof n[i.okayHandler]&&(a=n[i.okayHandler]),void 0!==i.cancelHandler&&"function"==typeof n[i.cancelHandler]&&(r=n[i.cancelHandler]),void 0!==i.openHandler&&"function"==typeof n[i.openHandler]&&(s=n[i.openHandler]),void 0!==i.optsHandler&&"function"==typeof n[i.optsHandler]&&(d=n[i.optsHandler]),o=d.call(n),n.dialog({name:i.dialog,open:function(t){s.call(n,t,o)},data:o,event:t,modal:i.modal,okayText:i.okayText,cancelText:i.cancelText}).then(function(t){a.call(n,t)},function(t){r.call(n,t)})),void 0===i.handler||"function"!=typeof n[i.handler]||n[i.handler].call(n,t,e))},t.NatEditor.prototype.hideMenus=function(){this.container.find(".ui-natedit-menu").each(function(){var e=t(this);t(e.data("menu-button")).removeClass("ui-state-highlight"),e.hide().data("state",!1)})},t.NatEditor.prototype.insert=function(t){var e,i,o,n,a;this.getSelectionRange(),e=this.txtarea.selectionStart,i=this.txtarea.selectionEnd,n=(o=this.txtarea.value).substring(0,e),a=o.substring(i),this.txtarea.value=n+t+a,this.setCaretPosition(e),this.undoManager.saveState("command")},t.NatEditor.prototype.remove=function(){var t,e,i,o;return this.getSelectionRange(),t=this.txtarea.selectionStart,e=this.txtarea.selectionEnd,i=this.txtarea.value,o=i.substring(t,e),this.txtarea.value=i.substring(0,t)+i.substring(e),this.setSelectionRange(t,t),this.undoManager.saveState("command"),o},t.NatEditor.prototype.getSelectionRange=function(){var t,e,i,o,n,a;return this.oldIE&&(t=this.txtarea.value,e="",a=(i=document.selection.createRange()).text||"",(o=i.duplicate()).moveToElementText(this.txtarea),i.text=e,n=o.text.indexOf(e),i.moveStart("character",-1),i.text=a,n<0&&(n=t.length,a=""),this.txtarea.selectionStart=n,this.txtarea.selectionEnd=""==a?n:n+a.length),[this.txtarea.selectionStart,this.txtarea.selectionEnd]},t.NatEditor.prototype.getSelection=function(){var t,e;return this.getSelectionRange(),t=this.txtarea.selectionStart,e=this.txtarea.selectionEnd,this.txtarea.value.substring(t,e)},t.NatEditor.prototype.getSelectionLines=function(){var t,e,i;for(this.getSelectionRange(),t=this.txtarea.selectionStart,e=this.txtarea.selectionEnd,i=this.txtarea.value;t>0&&13!=i.charCodeAt(t-1)&&10!=i.charCodeAt(t-1);)t--;for(;e"),e=e.replace(/\$amp/g,"&"),e=e.replace(/\$dollar/g,"$")},t.NatEditor.prototype.autoMaxExpand=function(){var e=this;window.setTimeout(function(){e.fixHeight(),t(window).one("resize.natedit",function(){e.autoMaxExpand()})})},t.NatEditor.prototype.fixHeight=function(){var e,i,o="undefined"!=typeof tinyMCE&&tinyMCE.activeEditor?t(tinyMCE.activeEditor.contentAreaContainer):null,n=this.form.find(".natEditBottomBar");o&&!tinyMCE.activeEditor.getParam("fullscreen_is_enabled")&&o.is(":visible")?(o.closest(".mceLayout").height("auto"),e=o.children("iframe")):e=t(this.txtarea),e&&e.length&&(i=(n.length?n.position().top:t(window).height()||window.innerHeight)-e.position().top-(e.outerHeight(!0)-e.height())-(this.container.outerHeight(!0)-this.container.height())-4,this.opts.minHeight&&in.opts.maxHeight?(o=n.opts.maxHeight,a.css("overflow-y","scroll")):a.css("overflow-y","hidden"),a.height(o))}))},t.NatEditor.prototype.htmlEntities=function(t){var e,i={"&":"&","<":"<",">":">",'"':"""};for(e in i)i.hasOwnProperty(e)&&(t=t.replace(new RegExp(e,"g"),i[e]));return t},t.NatEditor.prototype.dialog=function(e){var i=this,o={url:void 0,title:t.i18n("Confirmation required"),okayText:t.i18n("OK"),okayIcon:"ui-icon-check",cancelText:t.i18n("Cancel"),cancelIcon:"ui-icon-cancel",width:"auto",modal:!0,position:{my:"center",at:"center",of:window},open:function(){},data:{web:i.opts.web,topic:i.opts.topic,selection:i.getSelection()}};return"string"==typeof e&&(e={data:{text:e}}),void 0===e.url&&void 0!==e.name&&(e.url=foswiki.getScriptUrl("rest","JQueryPlugin","tmpl",{topic:i.opts.web+"."+i.opts.topic,load:"editdialog",name:e.name})),void 0!==(e=t.extend({},o,e)).event&&(e.position={my:"center top",at:"left bottom+30",of:e.event.target}),i.hideMessages(),t.Deferred(function(o){t.loadTemplate({url:e.url,name:e.name}).then(function(n){t(n.render(e.data)).dialog({buttons:[{text:e.okayText,icons:{primary:e.okayIcon},click:function(){return t(this).dialog("close"),o.resolve(this),!0}},{text:e.cancelText,icons:{primary:e.cancelIcon},click:function(){return t(this).dialog("close"),o.reject(),!1}}],open:function(n){var a=t(this),r=a.data("title");void 0!==r&&a.dialog("option","title",r),a.find("input").on("keydown",function(e){var i=t(this);i.is(".ui-autocomplete-input")&&i.data("ui-autocomplete").menu.element.is(":visible")||13==e.keyCode&&(e.preventDefault(),a.dialog("close"),o.resolve(a[0]))}),e.open.call(i,this,e.data)},close:function(e,i){t(this).remove()},show:"fade",modal:e.modal,draggable:!0,resizable:!1,title:e.title,width:e.width,position:e.position})},function(t){i.showMessage("error",t.responseText)})}).promise()},t.NatEditor.prototype.handleSearchReplace=function(e){var i,o=t(e),n=o.find("input[name='search']").val(),a=o.find("input[name='replace']").val(),r=!!o.find("input[name='ignorecase']:checked").length;t.log("NATEDIT: handleSearchReplace, search='"+n+" 'replace='"+a+"' ignoreCase=",r),n.length&&((i=this.searchReplace(n,a,r))?this.showMessage("info",t.i18n("replaced %count% time(s)",{count:i})):this.showMessage("warning",t.i18n("search string '%search%' not found",{search:n})))},t.NatEditor.prototype.searchReplace=function(e,i,o){var n,a,r=this.txtarea.scrollTop,s=this.getCaretPosition(),d=this.txtarea.value,l=0;for(o?(n=d.toLowerCase(),e=e.toLowerCase()):n=d,a=n.indexOf(e);-1!=a;)l++,d=d.substr(0,a)+i+d.substr(a+e.length),a=(n=n.substr(0,a)+i+n.substr(a+e.length)).indexOf(e,a+i.length);return t.log("NATEDIT: count=",l),l&&(this.txtarea.value=d,this.setCaretPosition(s),this.txtarea.scrollTop=r,this.opts.autoMaxExpand&&t(window).trigger("resize"),this.undoManager.saveState("command")),l},t.NatEditor.prototype.handleInsertTable=function(e){var i=t(e),o=i.find("input[name='rows']").val(),n=i.find("input[name='cols']").val(),a=i.find("input[name='heads']").val(),r="true"===i.find("input[name='editable']:checked").val();return this.insertTable({heads:a,rows:o,cols:n,editable:r})},t.NatEditor.prototype.handleInsertLink=function(e){var i=t(e),o={},n=i.find(".jqTab.current");if(n.is(".topic"))o={web:n.find("input[name='web']").val(),topic:n.find("input[name='topic']").val(),text:i.find("input[name='linktext_topic']").val()};else{if(!n.is(".external"))return;o={url:n.find("input[name='url']").val(),text:i.find("input[name='linktext_external']").val()}}return this.insertLink(o)},t.NatEditor.prototype.handleInsertAttachment=function(e){var i=t(e);return this.insertLink({web:i.find("input[name='web']").val(),topic:i.find("input[name='topic']").val(),file:i.find("input[name='file']").val(),text:i.find("input[name='linktext_attachment']").val()})},t.NatEditor.prototype.initColorDialog=function(e,i){var o=t(e),n=(this.getSelection(),o.find("input[name='color']")[0]);return this.fb=t.farbtastic(o.find(".ui-natedit-colorpicker")).setColor("#fafafa").linkTo(n),!1},t.NatEditor.prototype.parseColorSelection=function(){var t=this.getSelection()||"#ff0000";return{web:this.opts.web,topic:this.opts.topic,selection:t}},t.NatEditor.prototype.openDatePicker=function(e,i){var o,n,a=this,r=a.getSelection();if(""===r)n=new Date;else try{n=new Date(r)}catch(e){a.showMessage("error",t.i18n("invalid date '%date%'",{date:r}))}return void 0===a.datePicker&&(o=t('').css("position","absolute").appendTo("body").hide(),a.overlay=t("").addClass("ui-widget-overlay ui-front").hide().appendTo("body").on("click",function(){a.datePicker.hide(),a.overlay.hide()}),a.datePicker=o.datepicker({onSelect:function(){var t=a.datePicker.datepicker("getDate");a.datePicker.hide(),a.overlay.hide(),a.remove(),a.insertTag(["",a.formatDate(t),""])}}).draggable({handle:".ui-widget-header"}).zIndex(a.overlay.zIndex()+1)),a.overlay.show(),a.datePicker.datepicker("setDate",n),a.datePicker.show().focus().position({my:"center",at:"center",of:window}),!1},t.NatEditor.prototype.formatDate=function(t){return(t=t.toDateString().split(/ /))[2]+" "+t[1]+" "+t[3]},t.NatEditor.prototype.handleInsertColor=function(t){var e=this.fb.color;this.remove(),this.insertTag(["",e,""])},t.NatEditor.prototype.handleUndo=function(t){this.undoManager.undo()},t.NatEditor.prototype.handleRedo=function(t){this.undoManager.redo()},t.NatEditor.prototype.handleSortAscending=function(t,e){this.sortSelection("asc")},t.NatEditor.prototype.handleSortDescending=function(t,e){this.sortSelection("desc")},t.NatEditor.prototype.sortSelection=function(e){var i,o,n,a,r,s,d,l=!0;for(i=this.getSelectionLines().split(/\r?\n/),o=[],n=[],d=0;d o?1:0}),"desc"==e&&(o=o.reverse()),t.map(n,function(t){o.splice(t.pos,0,t)}),i=[],t.map(o,function(t){i.push(t.prefix+t.line)}),i=i.join("\n"),t.log("NATEDIT: result=\n'"+i+"'"),this.remove(),this.insertTag(["",i,""])},t.NatEditor.prototype.initLinkDialog=function(e,i){var o,n,a=this,r=t(e),s=0,d=r.find(".ui-natedit-attachment-thumbnail"),l=r.find(".jqTab.current");0===l.length&&(l=r),r.find("input[name='web']").each(function(){t(this).autocomplete({source:foswiki.getScriptUrl("view",a.opts.systemWeb,"JQueryAjaxHelper",{section:"web",skin:"text",contenttype:"application/json"})})}),r.find("input[name='topic']").each(function(){t(this).autocomplete({source:function(e,i){n&&n.abort(),n=t.ajax({url:foswiki.getScriptUrl("view",a.opts.systemWeb,"JQueryAjaxHelper"),data:t.extend(e,{section:"topic",skin:"text",contenttype:"application/json",baseweb:l.find("input[name='web']").val()}),dataType:"json",autocompleteRequest:++s,success:function(t,e){this.autocompleteRequest===s&&i(t)},error:function(t,e){this.autocompleteRequest===s&&i([])}})}})}),r.find(".natEditAttachmentSelector").each(function(){t(this).autocomplete({source:function(e,i){n&&n.abort(),n=t.ajax({url:foswiki.getScriptUrl("rest","NatEditPlugin","attachments"),data:t.extend(e,{topic:l.find("input[name='web']").val()+"."+l.find("input[name='topic']").val()}),dataType:"json",autocompleteRequest:++s,success:function(t,e){this.autocompleteRequest===s&&i(t)},error:function(t,e){this.autocompleteRequest===s&&i([])}})},select:function(t,e){d.length&&d.attr("src",e.item.img).show()},change:function(t,e){d.length&&(e.item?d.attr("src",e.item.img).show():d.hide())}}).data("ui-autocomplete")._renderItem=function(e,i){if(void 0!==i.label)return t("").data("item.autocomplete",i).append(""+(void 0!==i.img?" | ":"")+""+i.label+" "+i.comment+" | ").appendTo(e)}}),void 0!==i.type&&void 0!==(o=r.find(".jqTab."+i.type).attr("id"))&&window.setTimeout(function(){window.location.hash="!"+o})},t.NatEditor.prototype.initAttachmentsDialog=function(e,i){var o=this,n=t(e);t.log("NATEDIT: initAttachmentsDialog on elem=",e),o.initLinkDialog(e,i),n.on("dialogclose",function(){o.hideMessages()}),n.find(".ui-natedit-uploader").each(function(){var e=n.find("input[name='file']"),i=n.find(".ui-natedit-uploader-button"),a=n.find(".ui-natedit-uploader-cancel"),r=!1;o.uploader=t(this).uploader({dragdrop:!1,multi_selection:!1,autoStart:!0,browseButton:".ui-natedit-uploader-button",stopButton:".ui-natedit-uploader-cancel"}).data("uploader"),o.uploader.bind("StateChanged",function(){var n=o.uploader.files[0];o.uploader.state==plupload.STARTED&&(t.log("started upload"),e.attr("disabled","disabled").val(t.i18n("uploading ...")),i.hide(),a.show(),o.hideMessages()),o.uploader.state==plupload.STOPPED&&(t.log("upload stopped"),r||void 0===n||100!=n.percent?(e.val(t.i18n("abording transfer ...")),window.setTimeout(function(){e.removeAttr("disabled").val("").focus()},1e3)):e.removeAttr("disabled").val(n.name).focus(),i.show(),a.hide())}),o.uploader.bind("Error",function(e,i){var n,a=t.parseJSON(i.response);r=!0,n=void 0!==a.error?a.error.message:i,o.showMessage("error",n,t.i18n("Error during upload"))})})},t.NatEditor.prototype.cancelAttachmentsDialog=function(e,i){t(e);t.log("NATEDIT: cancelAttachmentsDialog on elem=",e),void 0!==this.uploader?(t.log("stopping uploader"),this.uploader.trigger("Stop")):t.log("no uploader found")},t.NatEditor.prototype.parseLinkSelection=function(){var t=this.getSelection(),e=this.opts.web,i=this.opts.topic,o="",n="",a="topic",r="(?:file|ftp|gopher|https?|irc|mailto|news|nntp|telnet|webdav|sip|edit)://[^\\s]+?";return t.match(/\s*\[\[(.*?)\]\]\s*/)?(t=RegExp.$1).match("^("+r+")(?:\\]\\[(.*))?$")?(n=RegExp.$1,t=RegExp.$2||"",a="external"):t.match(/^(?:%ATTACHURL(?:PATH)?%\/)(.*?)(?:\]\[(.*))?$/)?(o=RegExp.$1,t=RegExp.$2,a="attachment"):t.match(/^(?:%PUBURL(?:PATH)?%\/)(.*)\/(.*?)\/(.*?)(?:\]\[(.*))?$/)?(e=RegExp.$1,i=RegExp.$2,o=RegExp.$3,t=RegExp.$4,a="attachment"):t.match(/^(?:(.*)\.)?(.*?)(?:\]\[(.*))?$/)?(e=RegExp.$1||e,i=RegExp.$2,t=RegExp.$3||""):(i=t,t=""):t.match("^ *"+r)?(n=t,t="",a="external"):t.match(/^\s*%IMAGE\{"(.*?)"(?:.*?topic="(?:([^\s\.]+)\.)?(.*?)")?.*?\}%\s*$/)?(e=RegExp.$2||e,i=RegExp.$3||i,o=RegExp.$1,t="",a="attachment"):t.match(/^\s*([A-Z][^\s\.]*)\.(A-Z.*?)\s*$/)&&(e=RegExp.$1||e,i=RegExp.$2,t="",a="topic"),{selection:t,web:e,topic:i,file:o,url:n,type:a}},t.NatEditor.defaults={toolbar:"edittoolbar",h1Markup:["---+!! ","%TOPIC%",""],h2Markup:["---++ ","Headline text",""],h3Markup:["---+++ ","Headline text",""],h4Markup:["---++++ ","Headline text",""],h5Markup:["---+++++ ","Headline text",""],h6Markup:["---++++++ ","Headline text",""],verbatimMarkup:["\n","Insert non-formatted text here","\n"],quoteMarkup:["\n","Insert quote here","\n "],boldMarkup:["*","Bold text","*"],italicMarkup:["_","Italic text","_"],monoMarkup:["=","Monospace text","="],underlineMarkup:["","Underlined text",""],strikeMarkup:["","Strike through text",""],superscriptMarkup:["","superscript text",""],subscriptMarkup:["","subscript text",""],leftMarkup:['\n',"Align left","\n "],centerMarkup:['\n',"Center text","\n "],rightMarkup:['\n',"Align right","\n "],justifyMarkup:['\n',"Justify text","\n "],numberedListMarkup:[" 1 ","enumerated item",""],bulletListMarkup:[" * ","bullet item",""],indentMarkup:[" ","",""],outdentMarkup:["","",""],mathMarkup:['\n',"\\sum_{x=1}^{n}\\frac{1}{x}","\n"],signatureMarkup:["-- ",NaN],dataFormMarkup:["","| *Name* | *Type* | *Size* | *Values* | *Description* | *Attributes* | *Default* |","\n"],horizRulerMarkup:["","---","\n"],autoHideToolbar:!1,autoMaxExpand:!1,minHeight:0,maxHeight:0,autoResize:!1,resizable:!1,showToolbar:!0},t.fn.natedit=function(e){var i=t.extend({},t.NatEditor.defaults,e);return this.is(".foswikiWysiwygEdit")&&"undefined"!=typeof tinyMCE&&(i.showToolbar=!1),this.each(function(){t.data(this,"natedit")||t.data(this,"natedit",new t.NatEditor(this,i))})},t(function(){t.NatEditor.defaults.web=foswiki.getPreference("WEB"),t.NatEditor.defaults.topic=foswiki.getPreference("TOPIC"),t.NatEditor.defaults.systemWeb=foswiki.getPreference("SYSTEMWEB"),t.NatEditor.defaults.scriptUrl=foswiki.getPreference("SCRIPTURL"),t.NatEditor.defaults.pubUrl=foswiki.getPreference("PUBURL"),t.NatEditor.defaults.signatureMarkup=["-- ","[["+foswiki.getPreference("WIKIUSERNAME")+"]]"," - "+foswiki.getPreference("SERVERTIME")],t(".natedit").livequery(function(){t(this).natedit()})})}(jQuery);
|