weekly release 4.0dev+
[moodle.git] / lib / editor / atto / yui / build / moodle-editor_atto-editor / moodle-editor_atto-editor-min.js
CommitLineData
e2150f7d
SR
1YUI.add("moodle-editor_atto-editor",function(u,t){var o,r,n,l,s,a={CONTENT:"editor_atto_content",CONTENTWRAPPER:"editor_atto_content_wrap",TOOLBAR:"editor_atto_toolbar",WRAPPER:"editor_atto",HIGHLIGHT:"highlight"},c=window.rangy;function e(){e.superclass.constructor.apply(this,arguments)}function i(){}function h(){}function d(){}function g(){g.superclass.constructor.apply(this,arguments),this._submitEvents={},this._queue=[],this._throttle=null}function p(){}function f(){}function m(){}function v(){}function b(){}function _(){}function y(){}function S(){}u.extend(e,u.Base,{BLOCK_TAGS:["address","article","aside","audio","blockquote","canvas","dd","div","dl","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","header","hgroup","hr","noscript","ol","output","p","pre","section","table","tfoot","ul","video"],PLACEHOLDER_CLASS:"atto-tmp-class",ALL_NODES_SELECTOR:"[style],font[face]",FONT_FAMILY:"fontFamily",_wrapper:null,editor:null,textarea:null,textareaLabel:null,plugins:null,coreDirection:null,_eventHandles:null,initializer:function(){var t,e,i,n;this.textarea=u.one(document.getElementById(this.get("elementid"))),this.textarea&&(e=this.textarea.getAttribute("class"),this._eventHandles=[],i=u.Node.create('<div class="sr-only">'+M.util.get_string("richtexteditor","editor_atto")+"</div>"),this._wrapper=u.Node.create('<div class="'+a.WRAPPER+'" role="application" />'),this._wrapper.appendChild(i),this._wrapper.setAttribute("aria-describedby",i.generateID()),t=u.Handlebars.compile('<div id="{{elementid}}editable" contenteditable="true" role="textbox" spellcheck="true" aria-live="off" class="{{CSS.CONTENT}} '+e+'" />'),this.editor=u.Node.create(t({elementid:this.get("elementid"),CSS:a})),this.textareaLabel=u.one('[for="'+this.get("elementid")+'"]'),this.textareaLabel&&(this.textareaLabel.generateID(),this.editor.setAttribute("aria-labelledby",this.textareaLabel.get("id"))),this.coreDirection=u.one("body").hasClass("dir-rtl")?"rtl":"ltr",this.setupToolbar(),(n=u.Node.create('<div class="'+a.CONTENTWRAPPER+'" />')).appendChild(this.editor),this._wrapper.appendChild(n),this.editor.setStyle("minHeight",20*this.textarea.getAttribute("rows")+8+"px"),0===u.UA.ie&&this.editor.setStyle("height",20*this.textarea.getAttribute("rows")+8+"px"),this.disableCssStyling(),document.queryCommandSupported("DefaultParagraphSeparator")&&document.execCommand("DefaultParagraphSeparator",!1,"p"),this.textarea.get("parentNode").insert(this._wrapper,this.textarea).setAttribute("class","editor_atto_wrap"),this.textarea.hide(),u.mix(u.Node.DOM_EVENTS,{"form:editorUpdated":!0}),this.textarea.on("form:editorUpdated",function(){this.updateEditorState()},this),this.updateFromTextArea(),this.publishEvents(),this.setupSelectionWatchers(),this.setupAutomaticPolling(),this.setupPlugins(),this.setupAutosave(),this.setupNotifications())},focus:function(){return this.editor.focus(),this},publishEvents:function(){return this.publish("change",{broadcast:!0,preventable:!0}),this.publish("pluginsloaded",{fireOnce:!0}),this.publish("atto:selectionchanged",{prefix:"atto"}),this},setupAutomaticPolling:function(){return this._registerEventHandle(this.editor.on(["keyup","cut"],this.updateOriginal,this)),this._registerEventHandle(this.editor.on("paste",this.pasteCleanup,this)),this._registerEventHandle(this.editor.on("drop",this.updateOriginalDelayed,this)),this},updateOriginalDelayed:function(){return u.soon(u.bind(this.updateOriginal,this)),this},setupPlugins:function(){var t,e,i,n,s,a;for(e in this.plugins={},t=this.get("plugins"))if((i=t[e]).plugins)for(n in i.plugins)s=i.plugins[n],a=u.mix({name:s.name,group:i.group,editor:this.editor,toolbar:this.toolbar,host:this},s),"undefined"!=typeof u.M["atto_"+s.name]&&(this.plugins[s.name]=new u.M["atto_"+s.name].Button(a));return this.fire("pluginsloaded"),this},enablePlugins:function(t){this._setPluginState(!0,t)},disablePlugins:function(t){this._setPluginState(!1,t)},_setPluginState:function(t,e){var i="disableButtons";t&&(i="enableButtons"),e?this.plugins[e][i]():u.Object.each(this.plugins,function(t){t[i]()},this)},updateEditorState:function(){var t=this.textarea.hasAttribute("readonly"),e=u.one("#"+this.get("elementid")+"editable");this._setPluginState(!t),e&&e.setAttribute("contenteditable",!t)},_registerEventHandle:function(t){this._eventHandles.push(t)}},{NS:"editor_atto",ATTRS:{elementid:{value:null,writeOnce:!0},contextid:{value:null,writeOnce:!0},plugins:{value:{},writeOnce:!0}}}),u.augment(e,u.EventTarget),u.namespace("M.editor_atto").Editor=e,u.namespace("M.editor_atto.Editor").init=function(t){return new u.M.editor_atto.Editor(t)},o="info",r="warning",i.ATTRS={},i.prototype={messageOverlay:null,hideTimer:null,setupNotifications:function(){var t=new Image,e=new Image;return t.src=M.util.image_url("i/warning","moodle"),e.src=M.util.image_url("i/info","moodle"),this},showMessage:function(t,e,i){var n,s,a="";return null===this.messageOverlay&&(this.messageOverlay=u.Node.create('<div class="editor_atto_notification"></div>'),this.messageOverlay.hide(!0),this.textarea.get("parentNode").append(this.messageOverlay),this.messageOverlay.on("click",function(){this.messageOverlay.hide(!0)},this)),null!==this.hideTimer&&this.hideTimer.cancel(),e===r?a='<img src="'+M.util.image_url("i/warning","moodle")+'" alt="'+M.util.get_string("warning","moodle")+'"/>':e===o&&(a='<img src="'+M.util.image_url("i/info","moodle")+'" alt="'+M.util.get_string("info","moodle")+'"/>'),(n=parseInt(i,10))<=0&&(n=6e4),e="atto_"+e,s=u.Node.create('<div class="'+e+'" role="alert" aria-live="assertive">'+a+" "+u.Escape.html(t)+"</div>"),this.messageOverlay.empty(),this.messageOverlay.append(s),this.messageOverlay.show(!0),this.hideTimer=u.later(n,this,function(){this.hideTimer=null,this.messageOverlay.inDoc()&&this.messageOverlay.hide(!0)}),this}},u.Base.mix(u.M.editor_atto.Editor,[i]),h.ATTRS={},h.prototype={_getEmptyContent:function(){var t
2;return t="rtl"===this.coreDirection?'style="text-align: right;"':'style="text-align: left;"',u.UA.ie&&u.UA.ie<10?'<p dir="'+this.coreDirection+'" '+t+"></p>":'<p dir="'+this.coreDirection+'" '+t+"><br></p>"},updateFromTextArea:function(){return this.editor.setHTML(""),this.editor.append(this._cleanHTML(this.textarea.get("value"),!0)),""===this.editor.getHTML()&&this.editor.setHTML(this._getEmptyContent()),this},updateOriginal:function(){var t=this.textarea.get("value"),e=this.getCleanHTML();return""===e&&this.isActive()&&(e=this._getEmptyContent()),t!==e&&(this.textarea.set("value",e),this.textarea.simulate("change"),this.fire("change")),this}},u.Base.mix(u.M.editor_atto.Editor,[h]),n=5e3,l=6e4,d.ATTRS={autosaveEnabled:{value:!0,writeOnce:!0},autosaveFrequency:{value:60,writeOnce:!0},pageHash:{value:"",writeOnce:!0}},d.prototype={lastText:"",autosaveInstance:null,autosaveTimer:null,setupAutosave:function(){var t,e,i,n=-1,s=null,a=this.get("filepickeroptions");if(this.get("autosaveEnabled")){for(s in this.autosaveInstance=u.stamp(this),a)"undefined"!=typeof a[s].itemid&&(n=a[s].itemid);return e={contextid:this.get("contextid"),action:"resume",draftid:n,elementid:this.get("elementid"),pageinstance:this.autosaveInstance,pagehash:this.get("pageHash")},this.autosaveIo(e,this,{success:function(t){if(null!==t&&t){["<p></p>","<p><br></p>","<br>",'<p dir="rtl" style="text-align: right;"></p>','<p dir="rtl" style="text-align: right;"><br></p>','<p dir="ltr" style="text-align: left;"></p>','<p dir="ltr" style="text-align: left;"><br></p>',"<p>&nbsp;</p>","<p><br>&nbsp;</p>",'<p dir="rtl" style="text-align: right;">&nbsp;</p>','<p dir="rtl" style="text-align: right;"><br>&nbsp;</p>','<p dir="ltr" style="text-align: left;">&nbsp;</p>','<p dir="ltr" style="text-align: left;"><br>&nbsp;</p>'].includes(t.result)&&(t.result=""),t.error||"undefined"==typeof t.result?this.showMessage(M.util.get_string("errortextrecovery","editor_atto"),r,l):t.result!==this.textarea.get("value")&&""!==t.result&&this.recoverText(t.result),this._fireSelectionChanged()}},failure:function(){this.showMessage(M.util.get_string("errortextrecovery","editor_atto"),r,l)}}),i=1e3*parseInt(this.get("autosaveFrequency"),10),this.autosaveTimer=u.later(i,this,this.saveDraft,!1,!0),(t=this.textarea.ancestor("form"))&&this.autosaveIoOnSubmit(t,{action:"reset",contextid:this.get("contextid"),elementid:this.get("elementid"),pageinstance:this.autosaveInstance,pagehash:this.get("pageHash")}),this}},recoverText:function(t){return this.editor.setHTML(t),this.saveSelection(),this.updateOriginal(),this.lastText=t,this.showMessage(M.util.get_string("textrecovered","editor_atto"),o,l),require(["core_editor/events"],function(t){t.notifyEditorContentRestored(this.editor.getDOMNode())}.bind(this)),this},saveDraft:function(){var t,e,i;if(this.editor.getDOMNode())return this.editor.get("hidden")||this.updateOriginal(),(e=this.textarea.get("value"))!==this.lastText&&(M.cfg.wwwroot,this.get("autosaveAjaxScript"),t={sesskey:M.cfg.sesskey,contextid:this.get("contextid"),action:"save",drafttext:e,elementid:this.get("elementid"),pagehash:this.get("pageHash"),pageinstance:this.autosaveInstance},i=function(t){var e=1e3*parseInt(this.get("autosaveFrequency"),10);this.showMessage(M.util.get_string("autosavefailed","editor_atto"),r,e)},this.autosaveIo(t,this,{failure:i,success:function(t){t&&t.error?u.soon(u.bind(i,this,[t])):(this.lastText=e,this.showMessage(M.util.get_string("autosavesucceeded","editor_atto"),o,n))}})),this;this.autosaveTimer.cancel()}},u.Base.mix(u.M.editor_atto.Editor,[d]),s=null,g.NAME="EditorAutosaveIoDispatcher",g.ATTRS={autosaveAjaxScript:{value:"/lib/editor/atto/autosave-ajax.php",readOnly:!0},delay:{value:50,readOnly:!0}},u.extend(g,u.Base,{dispatch:function(t,e,i){this._throttle&&this._throttle.cancel(),this._throttle=u.later(this.get("delay"),this,this._processDispatchQueue),this._queue.push([t,e,i])},_processDispatchQueue:function(){var t=this._queue,i={};this._queue=[],t.length<1||(u.Array.each(t,function(t,e){i[e]=t[0]}),u.io(M.cfg.wwwroot+this.get("autosaveAjaxScript"),{method:"POST",data:u.QueryString.stringify({actions:i,sesskey:M.cfg.sesskey}),on:{start:this._makeIoEventCallback("start",t),complete:this._makeIoEventCallback("complete",t),failure:this._makeIoEventCallback("failure",t),end:this._makeIoEventCallback("end",t),success:this._makeIoEventCallback("success",t)}}))},_makeIoEventCallback:function(o,e){var r=function(){};return function(){var t=arguments[1],a={};"complete"!=o&&"success"!=o||void 0===t||"undefined"==typeof t.responseText||""===t.responseText||(a=JSON.parse(t.responseText)||{}),u.Array.each(e,function(t,e){var i,n=t[1],s=t[2]&&t[2][o]||r;a&&a.error?i=a:a&&(i=a[e]),s.apply(n,[i])})}},_onSubmit:function(t){var i={},e=t.currentTarget.generateID(),n=this._submitEvents[e];!n||n.ios.length<1||(u.Array.each(n.ios,function(t,e){i[e]=t}),u.io(M.cfg.wwwroot+this.get("autosaveAjaxScript"),{method:"POST",data:u.QueryString.stringify({actions:i,sesskey:M.cfg.sesskey}),sync:!0}))},whenSubmit:function(t,e){"undefined"==typeof this._submitEvents[t.generateID()]&&(this._submitEvents[t.generateID()]={event:t.on("submit",this._onSubmit,this),ajaxEvent:t.on(M.core.event.FORM_SUBMIT_AJAX,this._onSubmit,this),ios:[]}),this._submitEvents[t.get("id")].ios.push([e])}}),s=new g,p.prototype={autosaveIo:function(t,e,i){s.dispatch(t,e,i)},autosaveIoOnSubmit:function(t,e){s.whenSubmit(t,e)}},u.Base.mix(u.M.editor_atto.Editor,[p]),f.ATTRS={},f.prototype={getCleanHTML:function(){var t,e=this.editor.cloneNode(!0);return u.each(e.all('[id^="yui"]'),function(t){t.removeAttribute("id")}),e.all(".atto_control").remove(!0),t=e.get("innerHTML"),["<p></p>","<p><br></p>","<br>",'<p dir="rtl" style="text-align: right;"></p>','<p dir="rtl" style="text-align: right;"><br></p>','<p dir="ltr" style="text-align: left;"></p>','<p dir="ltr" style="text-align: left;"><br></p>',"<p>&nbsp;</p>","<p><br>&nbsp;</p>",
3'<p dir="rtl" style="text-align: right;">&nbsp;</p>','<p dir="rtl" style="text-align: right;"><br>&nbsp;</p>','<p dir="ltr" style="text-align: left;">&nbsp;</p>','<p dir="ltr" style="text-align: left;"><br>&nbsp;</p>'].includes(t)?"":this._cleanHTML(t)},cleanEditorHTML:function(){var t=this.editor.get("innerHTML");return this.editor.set("innerHTML",this._cleanHTML(t)),this},_cleanHTML:function(t,e){return t=this._filterContentWithRules(t,[{regex:/<style[^>]*>[\s\S]*?<\/style>/gi,replace:""},{regex:/<!--(?![\s\S]*?-->)/gi,replace:""},{regex:/<\/?(?:title|meta|style|st\d|head\b|font|html|body|link)[^>]*?>/gi,replace:""}]),e&&(t=this._cleanHTMLLists(t)),t},_filterContentWithRules:function(t,e){var i=0;for(i=0;i<e.length;i++)t=t.replace(e[i].regex,e[i].replace);return t},pasteCleanup:function(t){var e,i,n,s,a;if("paste"===t.type){if(e=this.postPasteCleanupDelayed(),!((i=t._event)&&i.clipboardData&&i.clipboardData.getData&&i.clipboardData.types))return this.fallbackPasteCleanupDelayed(),!0;if(s=!1,"function"==typeof(n=i.clipboardData.types).contains?s=n.contains("text/html"):"function"==typeof n.indexOf&&(s=-1<n.indexOf("text/html")),s){try{a=i.clipboardData.getData("text/html")}catch(o){return e.cancel(),this.fallbackPasteCleanupDelayed(),!0}return t.preventDefault(),a=this._cleanPasteHTML(a),this.insertContentAtFocusPoint(a),this.updateOriginal(),!1}try{a=i.clipboardData.getData("text")}catch(o){return e.cancel(),this.fallbackPasteCleanupDelayed(),!0}}return this.updateOriginalDelayed(),!0},postPasteCleanupDelayed:function(){return u.soon(u.bind(this.postPasteCleanup,this)),this},postPasteCleanup:function(){var t=window.rangy.saveSelection(),e=this.editor.get("innerHTML");return this.editor.set("innerHTML",this._cleanHTML(e,!0)),this.updateOriginal(),window.rangy.restoreSelection(t),this},fallbackPasteCleanup:function(){var t=window.rangy.saveSelection(),e=this.editor.get("innerHTML");return this.editor.set("innerHTML",this._cleanHTML(this._cleanPasteHTML(e),!0)),this.updateOriginal(),window.rangy.restoreSelection(t),this},fallbackPasteCleanupDelayed:function(){return u.soon(u.bind(this.fallbackPasteCleanup,this)),this},_cleanPasteHTML:function(t){var e,i;return t&&0!==t.length?(e=[{regex:/<\s*\/html\s*>([\s\S]+)$/gi,replace:""},{regex:/<!--\[if[\s\S]*?endif\]-->/gi,replace:""},{regex:/<!--(Start|End)Fragment-->/gi,replace:""},{regex:/<xml[^>]*>[\s\S]*?<\/xml>/gi,replace:""},{regex:/<\?xml[^>]*>[\s\S]*?<\\\?xml>/gi,replace:""},{regex:/<\/?\w+:[^>]*>/gi,replace:""}],t=this._filterContentWithRules(t,e),0!==(t=this._cleanHTML(t)).length&&t.match(/\S/)?((i=document.createElement("div")).innerHTML=t,t=i.innerHTML,e=[{regex:/(<[^>]*?class\s*?=\s*?")([^>"]*)(")/gi,replace:function(t,e,i,n){return e+(i=(i=i.replace(/(?:^|[\s])[\s]*MSO[_a-zA-Z0-9\-]*/gi,"")).replace(/(?:^|[\s])[\s]*Apple-[_a-zA-Z0-9\-]*/gi,""))+n}},{regex:/<a [^>]*?name\s*?=\s*?"OLE_LINK\d*?"[^>]*?>\s*?<\/a>/gi,replace:i.innerHTML=""}],t=this._cleanStyles(t),t=this._filterContentWithRules(t,e),t=this._cleanHTML(t),t=this._cleanSpans(t)):t):""},_cleanStyles:function(t){var e,i,n,s=document.createElement("div");for(s.innerHTML=t,e=s.querySelectorAll("[style]"),i=i=0;i<e.length;i++)e[i].removeAttribute("style");for(n=s.querySelectorAll("[class]"),i=0;i<n.length;i++)n[i].removeAttribute("class");return s.innerHTML},_cleanSpans:function(t){var e,i,n;return t&&0!==t.length?0!==t.length&&t.match(/\S/)?(e=[{regex:/(<[^>]*?)(?:[\s]*(?:class|style|id)\s*?=\s*?"\s*?")+/gi,replace:"$1"}],t=this._filterContentWithRules(t,e),(i=document.createElement("div")).innerHTML=t,n=i.getElementsByTagName("span"),Array.prototype.slice.call(n,0).forEach(function(t){if(!t.hasAttributes()){for(;t.firstChild;)t.parentNode.insertBefore(t.firstChild,t);t.parentNode.removeChild(t)}}),i.innerHTML):t:""},_cleanHTMLLists:function(t){for(var e,i="",n=t,s=null,a=[],o=null,r=null;s=n.match(/<(\/?)(li|ul|ol)[^>]*>/i);){if(o={tag:s[2],tagLowerCase:s[2].toLowerCase(),fullTag:s[0],isOpen:1!=s[1].length},r=a.length?a[a.length-1]:null,i+=n.slice(0,s.index),n=n.slice(s.index+s[0].length),o.isOpen){if("li"===o.tagLowerCase){if(!r){if(e=(n.match(/<\/(ol)[ >]/gi)||[]).length,(n.match(/<(ol)[ >]/gi)||[]).length<e){n="<ol>"+o.fullTag+n;continue}n="<ul>"+o.fullTag+n;continue}if("li"===r.tagLowerCase){n="</"+r.tag+">"+o.fullTag+n;continue}}a.push({tag:o.tag,tagLowerCase:o.tagLowerCase,position:i.length,length:o.fullTag.length})}else{if(0==a.length)continue;if(r.tagLowerCase===o.tagLowerCase)o.tag!=r.tag&&(o.fullTag=o.fullTag.replace(o.tag,r.tag)),a.pop(),r=a.length?a[a.length-1]:null;else if("li"===o.tagLowerCase&&r.liEnd&&r.liEnd<i.length)i=this._insertString(i,"<"+o.tag+">",r.liEnd);else{if("li"!==o.tagLowerCase||r.liEnd||!(r.position+r.length<i.length)){if("li"!==r.tagLowerCase)continue;n="</"+r.tag+">"+o.fullTag+n;continue}i=this._insertString(i,"<"+o.tag+">",r.position+r.length)}"li"===o.tagLowerCase&&r&&(r.liEnd=i.length+o.fullTag.length)}i+=o.fullTag}if(i+=n,a.length)for(;o=a.pop();)i=o.liEnd?this._insertString(i,"</"+o.tag+">",o.liEnd):i.slice(0,o.position)+i.slice(o.position+o.length);return i},_insertString:function(t,e,i){return t.slice(0,i)+e+t.slice(i)}},u.Base.mix(u.M.editor_atto.Editor,[f]),m.ATTRS={},m.prototype={applyFormat:function(t,e,i,n){var s,a;if(i=i||this,(s=window.rangy.getSelection()).isCollapsed)return a=this.editor.once("input",function o(t,e,i,n,s,a){u.soon(u.bind(function(t,e,i,n,s,a){var o=window.rangy.getSelection(),r=o.getRangeAt(0);r.setStart(s,a),o.setSingleRange(r),e.apply(i,[t,n]),o.collapseToEnd(),this.saveSelection(),this.updateOriginal()},this,t,e,i,n,s,a))},this,e,i,n,s.anchorNode,s.anchorOffset),void this.editor.onceAfter(["click","selectstart"],a.detach,a);e.apply(i,[t,n]),this.saveSelection(),this.updateOriginal()},replaceTags:function(t,e){var i,n,s,a;for(t.setAttribute("data-iterate",!0),i=this.editor.one('[data-iterate="true"]');i;){for(n=u.Node.create("<"+e+" />").setAttrs(i.getAttrs()).removeAttribute("data-iterate"),i.getAttribute(
7029fa05
SR
4"style")&&n.setAttribute("style",i.getAttribute("style")),i.getAttribute("class")&&n.setAttribute("class",i.getAttribute("class")),a=(s=i.getDOMNode().childNodes)[0];void 0!==a;)n.append(a),a=s[0];i.replace(n),i=this.editor.one('[data-iterate="true"]')}},changeToCSS:function(t,e){var i=window.rangy.saveSelection();this.editor.all(".rangySelectionBoundary").setStyle("display",null),this.editor.all(t).addClass(e),this.replaceTags(this.editor.all("."+e),"span"),window.rangy.restoreSelection(i)},changeToTags:function(e,i){var t=window.rangy.saveSelection();this.editor.all(".rangySelectionBoundary").setStyle("display",null),this.replaceTags(this.editor.all('span[class="'+e+'"]'),i),this.editor.all(i+'[class="'+e+'"]').removeAttribute("class"),this.editor.all("."+e).each(function(t){t.wrap("<"+i+"/>"),t.removeClass(e)}),this.editor.all('[class="'+e+'"]').removeAttribute("class"),this.editor.all(i).removeClass(e),window.rangy.restoreSelection(t)}},u.Base.mix(u.M.editor_atto.Editor,[m]),v.ATTRS={},v.prototype={toolbar:null,openMenus:null,setupToolbar:function(){return this.toolbar=u.Node.create('<div class="'+a.TOOLBAR+'" role="toolbar" aria-live="off"/>'),this.openMenus=[],this._wrapper.appendChild(this.toolbar),this.textareaLabel&&this.toolbar.setAttribute("aria-labelledby",this.textareaLabel.get("id")),this.setupToolbarNavigation(),this}},u.Base.mix(u.M.editor_atto.Editor,[v]),b.ATTRS={},b.prototype={_tabFocus:null,setupToolbarNavigation:function(){return this._wrapper.delegate("key",this.toolbarKeyboardNavigation,"down:37,39","."+a.TOOLBAR,this),this._wrapper.delegate("focus",function(t){this._setTabFocus(t.currentTarget)},"."+a.TOOLBAR+" button",this),this},toolbarKeyboardNavigation:function(t){t.preventDefault();var e,i=this.toolbar.all("button"),n=1,s=t.target.ancestor("button",!0),a=t.target.all("button");!s&&a&&(i=a),37===t.keyCode&&(n=-1),(e=this._findFirstFocusable(i,s,n))&&(e.focus(),this._setTabFocus(e))},_findFirstFocusable:function(t,e,i){var n,s,a,o=0;for((a=t.indexOf(e))<-1&&(a=0);o<t.size();)if((a+=i)<0?a=t.size()-1:a>=t.size()&&(a=0),o++,!((n=t.item(a)).hasAttribute("hidden")||n.hasAttribute("disabled")||n.ancestor("[hidden]"))){s=n;break}return s},checkTabFocus:function(){if(this._tabFocus&&(this._tabFocus.hasAttribute("disabled")||this._tabFocus.hasAttribute("hidden")||this._tabFocus.ancestor(".atto_group").hasAttribute("hidden"))){var t=this._findFirstFocusable(this.toolbar.all("button"),this._tabFocus,-1);t&&(this._tabFocus.compareTo(document.activeElement)&&t.focus(),this._setTabFocus(t))}return this},_setTabFocus:function(t){return this._tabFocus&&this._tabFocus.setAttribute("tabindex","-1"),this._tabFocus=t,this._tabFocus.setAttribute("tabindex",0),this.toolbar.setAttribute("aria-activedescendant",this._tabFocus.generateID()),this}},u.Base.mix(u.M.editor_atto.Editor,[b]),_.ATTRS={},_.prototype={_selections:null,_lastSelection:null,_focusFromClick:!1,_gesturestartededitor:!1,setupSelectionWatchers:function(){return this.on("atto:selectionchanged",this.saveSelection,this),this.editor.on("focus",this.restoreSelection,this),this.editor.on("mousedown",function(){this._focusFromClick=!0},this),this.editor.on("blur",function(){this._focusFromClick=!1,this.updateOriginal()},this),this.editor.on(["keyup","focus"],function(t){u.soon(u.bind(this._hasSelectionChanged,this,t))},this),u.one(document.body).on("gesturemovestart",function(t){this._wrapper.contains(t.target._node)?this._gesturestartededitor=!0:this._gesturestartededitor=!1},null,this),u.one(document.body).on("gesturemoveend",function(t){this._gesturestartededitor&&u.soon(u.bind(this._hasSelectionChanged,this,t))},{standAlone:!0},this),this},isActive:function(){var t=c.createRange(),e=c.getSelection();return!!e.rangeCount&&(!(!document.activeElement||!this.editor.compareTo(document.activeElement)&&!this.editor.contains(document.activeElement))&&(t.selectNode(this.editor.getDOMNode()),t.intersectsRange(e.getRangeAt(0))))},getSelectionFromNode:function(t){var e=c.createRange();return e.selectNode(t.getDOMNode()),[e]},saveSelection:function(){this.isActive()&&(this._selections=this.getSelection())},restoreSelection:function(){this._focusFromClick||this._selections&&this.setSelection(this._selections),this._focusFromClick=!1},getSelection:function(){return c.getSelection().getAllRanges()},selectionContainsNode:function(t){return c.getSelection().containsNode(t.getDOMNode(),!0)},selectionFilterMatches:function(e,t,i){var n,s,a,o;return void 0===i&&(i=!0),t=t||this.getSelectedNodes(),n=0<t.size(),s=!1,a=this.editor,o=function(t){return t===a},!!a.one(e)&&(t.each(function(t){i?n&&t.ancestor(e,!0,o)||(n=!1):!s&&t.ancestor(e,!0,o)&&(s=!0)},this),i?n:s)},getSelectedNodes:function(){var t,e,i,n,s,a=new u.NodeList;for((i=(e=c.getSelection()).rangeCount?e.getRangeAt(0):c.createRange()).collapsed&&i.commonAncestorContainer!==this.editor.getDOMNode()&&i.commonAncestorContainer!==u.config.doc&&(i=i.cloneRange()).selectNode(i.commonAncestorContainer),t=i.getNodes(),s=0;s<t.length;s++)n=u.one(t[s]),this.editor.contains(n)&&a.push(n);return a},_hasSelectionChanged:function(t){var e,i=c.getSelection(),n=!1;return e=i.rangeCount?i.getRangeAt(0):c.createRange(),this._lastSelection&&!this._lastSelection.equals(e)?(n=!0,this._fireSelectionChanged(t)):(this._lastSelection=e,n)},_fireSelectionChanged:function(t){this.fire("atto:selectionchanged",{event:t,selectedNodes:this.getSelectedNodes()})},getSelectionParentNode:function(){var t=c.getSelection();return!!t.rangeCount&&t.getRangeAt(0).commonAncestorContainer},setSelection:function(t){c.getSelection().setRanges(t)},insertContentAtFocusPoint:function(t){var e,i,n,s=c.getSelection(),a=u.Node.create(t);return s.rangeCount&&(e=s.getRangeAt(0)),e&&(e.deleteContents(),e.collapse(!1),n=(i=a.getDOMNode()).lastChild||i,e.insertNode(i),e.collapseAfter(n),s.setSingleRange(e)),a}},u.Base.mix(u.M.editor_atto.Editor,[_]),y.ATTRS={},y.prototype={disableCssStyling:function(){try{document.execCommand(
5"styleWithCSS",0,!1)}catch(t){try{document.execCommand("useCSS",0,!0)}catch(e){try{document.execCommand("styleWithCSS",!1,!1)}catch(i){}}}},enableCssStyling:function(){try{document.execCommand("styleWithCSS",0,!0)}catch(t){try{document.execCommand("useCSS",0,!1)}catch(e){try{document.execCommand("styleWithCSS",!1,!0)}catch(i){}}}},toggleInlineSelectionClass:function(t){var e=t.join(" "),i=c.createClassApplier(e,{normalize:!0});i.toggleSelection()},formatSelectionInlineStyle:function(e){var i=this.PLACEHOLDER_CLASS,t=c.createClassApplier(i,{normalize:!0});t.applyToSelection(),this.editor.all("."+i).each(function(t){t.removeClass(i).setStyles(e)},this)},formatSelectionBlock:function(t,e){var i,n,s,a,o,r,l,c=this.getSelectionParentNode();return!!c&&(i=this.editor,(n=(c=u.one(c)).ancestor(function(t){var e=t.get("tagName");return e=e&&e.toLowerCase(),t===i||"td"===e||"th"===e},!0))&&(i=n),(s=c.ancestor(this.BLOCK_TAGS.join(", "),!0))&&(s.ancestor(function(t){return t===i},!1)||(s=!1)),s||(r="rtl"===this.coreDirection?'style="text-align: right;"':'style="text-align: left;"',a=u.Node.create('<p dir="'+this.coreDirection+'" '+r+"></p>"),i.get("childNodes").each(function(t){a.append(t.remove())}),i.append(a),s=a),t&&""!==t&&((o=u.Node.create("<"+t+"></"+t+">")).setAttrs(s.getAttrs()),s.get("childNodes").each(function(t){t.remove(),o.append(t)}),s.replace(o),s=o),e&&s.setAttrs(e),l=this.getSelectionFromNode(s),this.setSelection(l),s)}},u.Base.mix(u.M.editor_atto.Editor,[y]),S.ATTRS={filepickeroptions:{value:{}}},S.prototype={canShowFilepicker:function(t){return"undefined"!=typeof this.get("filepickeroptions")[t]},showFilepicker:function(i,n,s){var a=this;u.use("core_filepicker",function(t){var e=t.clone(a.get("filepickeroptions")[i],!0);e.formcallback=n,s&&(e.magicscope=s),M.core_filepicker.show(t,e)})}},u.Base.mix(u.M.editor_atto.Editor,[S])},"@VERSION@",{requires:["node","transition","io","overlay","escape","event","event-simulate","event-custom","node-event-html5","node-event-simulate","yui-throttle","moodle-core-notification-dialogue","moodle-core-notification-confirm","moodle-editor_atto-rangy","handlebars","timers","querystring-stringify"]});