AutorÃa | Ultima modificación | Ver Log |
YUI.add("moodle-editor_atto-editor",function(r,u){var s,a,n,i={CONTENT:"editor_atto_content",CONTENTWRAPPER:"editor_atto_content_wrap",TOOLBAR:"editor_atto_toolbar",WRAPPER:"editor_atto",HIGHLIGHT:"highlight"},o=window.rangy;function t(){t.superclass.constructor.apply(this,arguments)}function e(){}function l(){}function h(){}function c(){c.superclass.constructor.apply(this,arguments),this._submitEvents={},this._queue=[],this._throttle=null}function d(){}function g(){}function p(){}function f(){}function m(){}function v(){}function b(){}function _(){}r.extend(t,r.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,enableAppropriateEmptyContent:null,_eventHandles:null,initializer:function(){var t,e;this.textarea=r.one(document.getElementById(this.get("elementid"))),this.textarea&&(e=this.textarea.getAttribute("class"),this._eventHandles=[],t=r.Node.create('<div class="sr-only">'+M.util.get_string("richtexteditor","editor_atto")+"</div>"),this._wrapper=r.Node.create('<div class="'+i.WRAPPER+'" role="application" />'),this._wrapper.appendChild(t),this._wrapper.setAttribute("aria-describedby",t.generateID()),t=r.Handlebars.compile('<div id="{{elementid}}editable" contenteditable="true" role="textbox" spellcheck="true" aria-live="off" class="{{CSS.CONTENT}} '+e+'" />'),this.editor=r.Node.create(t({elementid:this.get("elementid"),CSS:i})),this.textareaLabel=r.one('[for="'+this.get("elementid")+'"]'),this.textareaLabel&&(this.textareaLabel.generateID(),this.editor.setAttribute("aria-labelledby",this.textareaLabel.get("id"))),this.coreDirection=r.one("body").hasClass("dir-rtl")?"rtl":"ltr",this.enablePlaceholderForEmpty
Content(),this.setupToolbar(),(e=r.Node.create('<div class="'+i.CONTENTWRAPPER+'" />')).appendChild(this.editor),this._wrapper.appendChild(e),this.editor.setStyle("minHeight",20*this.textarea.getAttribute("rows")+8+"px"),0===r.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(),r.mix(r.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 r.soon(r.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=r.mix({name:s.name,group:i.group,editor:this.editor,toolbar:this.toolbar,host:this},s),"undefined"!=typeof r.M["atto_"+s.name]&&(this.plugins[s.name]=new r.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=t?"enableButtons":"disableButto
ns";e?this.plugins[e][i]():r.Object.each(this.plugins,function(t){t[i]()},this)},updateEditorState:function(){var t=this.textarea.hasAttribute("readonly"),e=r.one("#"+this.get("elementid")+"editable");this._setPluginState(!t),e&&e.setAttribute("contenteditable",!t)},enablePlaceholderForEmptyContent:function(){this.enableAppropriateEmptyContent=!0},disablePlaceholderForEmptyContent:function(){this.enableAppropriateEmptyContent=!1},_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}}}),r.augment(t,r.EventTarget),r.namespace("M.editor_atto").Editor=t,r.namespace("M.editor_atto.Editor").init=function(t){return new r.M.editor_atto.Editor(t)},s="info",a="warning",e.ATTRS={},e.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},s
howMessage:function(t,e,i){var n="";return null===this.messageOverlay&&(this.messageOverlay=r.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===a?n='<img src="'+M.util.image_url("i/warning","moodle")+'" alt="'+M.util.get_string("warning","moodle")+'"/>':e===s&&(n='<img src="'+M.util.image_url("i/info","moodle")+'" alt="'+M.util.get_string("info","moodle")+'"/>'),(i=parseInt(i,10))<=0&&(i=6e4),e=r.Node.create('<div class="'+(e="atto_"+e)+'" role="alert" aria-live="assertive">'+n+" "+r.Escape.html(t)+"</div>"),this.messageOverlay.empty(),this.messageOverlay.append(e),this.messageOverlay.show(!0),this.hideTimer=r.later(i,this,function(){
this.hideTimer=null,this.messageOverlay.inDoc()&&this.messageOverlay.hide(!0)}),this}},r.Base.mix(r.M.editor_atto.Editor,[e]),l.ATTRS={},l.prototype={_getEmptyContent:function(){if(!this.enableAppropriateEmptyContent)return"";var t="rtl"===this.coreDirection?'style="text-align: right;"':'style="text-align: left;"';return r.UA.ie&&r.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 t!==(e=""===e&&this.isActive()?this._getEmptyContent():e)&&(this.textarea.set("value",e),this.textarea.simulate("change"),this.fire("change")),this}},r.Base.mix(r.M.editor_atto.Editor,[l]),h.ATTRS={autosaveEnabled:{value:!0,writeOnce:!0},autosaveFrequency:{value:60,writeOnce:!0},pageHash:{
value:"",writeOnce:!0}},h.prototype={lastText:"",autosaveInstance:null,autosaveTimer:null,setupAutosave:function(){var t,e=-1,i=null,n=this.get("filepickeroptions");if(this.get("autosaveEnabled")){for(i in this.autosaveInstance=r.stamp(this),n)"undefined"!=typeof n[i].itemid&&(e=n[i].itemid);return t={contextid:this.get("contextid"),action:"resume",draftid:e,elementid:this.get("elementid"),pageinstance:this.autosaveInstance,pagehash:this.get("pageHash")},this.autosaveIo(t,this,{success:function(t){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> </p>","<p><br> </p>",'<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>'].includes(t.result)&&(t.re
sult=""),t.error||"undefined"==typeof t.result?this.showMessage(M.util.get_string("errortextrecovery","editor_atto"),a,6e4):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"),a,6e4)}}),t=1e3*parseInt(this.get("autosaveFrequency"),10),this.autosaveTimer=r.later(t,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"),s,6e4),require(["core_editor/events"],function(t){t.notifyEditorContentRestored(this.editor.getDOMNode())}.bind(this)),this},saveDraft:function(){var t,e,i;if(this.editor.getDOMNode())retu
rn 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},this.autosaveIo(t,this,{failure:i=function(t){var e=1e3*parseInt(this.get("autosaveFrequency"),10);this.showMessage(M.util.get_string("autosavefailed","editor_atto"),a,e)},success:function(t){t&&t.error?r.soon(r.bind(i,this,[t])):(this.lastText=e,this.showMessage(M.util.get_string("autosavesucceeded","editor_atto"),s,5e3))}})),this;this.autosaveTimer.cancel()}},r.Base.mix(r.M.editor_atto.Editor,[h]),n=null,c.NAME="EditorAutosaveIoDispatcher",c.ATTRS={autosaveAjaxScript:{value:"/lib/editor/atto/autosave-ajax.php",readOnly:!0},delay:{value:50,readOnly:!0}},r.extend(c,r.Base,{dispatch:function(t,e,i){this._throttle&&this._throttle.cancel(),this._throttle=r.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||(r.Array.each(t,function(t,e){i[e]=t[0]}),r.io(M.cfg.wwwroot+this.get("autosaveAjaxScript"),{method:"POST",data:r.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(a,e){var o=function(){};return function(){var t=arguments[1],s={};"complete"!=a&&"success"!=a||void 0===t||"undefined"==typeof t.responseText||""===t.responseText||(s=JSON.parse(t.responseText)||{}),r.Array.each(e,function(t,e){var i,n=t[1],t=t[2]&&t[2][a]||o;s&&s.error?i=s:s&&(i=s[e]),t.apply(n,[i])})}},_onSubmit:function(t){var i={},t=t.currentTarget.generateID(),t=this._submitEvents[t];!t||t.ios.length<1||(r.Array.each(t.ios,function(t,e){i[e]=t}),
r.io(M.cfg.wwwroot+this.get("autosaveAjaxScript"),{method:"POST",data:r.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])}}),n=new c,d.prototype={autosaveIo:function(t,e,i){n.dispatch(t,e,i)},autosaveIoOnSubmit:function(t,e){n.whenSubmit(t,e)}},r.Base.mix(r.M.editor_atto.Editor,[d]),g.ATTRS={},g.prototype={getCleanHTML:function(){var t=this.editor.cloneNode(!0);return r.each(t.all('[id^="yui"]'),function(t){t.removeAttribute("id")}),t.all(".atto_control").remove(!0),t=t.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> </p>","<p><br> </p>",'<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>'].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:""}]),t=e?this._cleanHTMLLists(t):t},_filterContentWithRules:function(t,e){for(var i=0,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 r.soon(r.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.rang
y.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 r.soon(r.bind(this.fallbackPasteCleanup,this)),this},_cleanPasteHTML:function(t){var e;return t&&0!==t.length?(t=this._filterContentWithRules(t,[{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:""}]),0!==(t=this._cleanHTML(t)).length&&t.match(/\S/)?((e=document.createElement("div")).innerHTML=t,t=e.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:e.innerHTML=""}],t=this._cleanStyles(t),t=this._filterContentWithRules(t,e),t=this._cleanHTML(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;return t&&0!==t.length?0!==t.length&&t.match(/\S/)?(t=this._filterContentWithRules(t,[{regex:/(<[^>]*?)(?:[\s]*(?:class|style|id)\s*?=\s*?"\s*?")+/gi,replace:"$1"}]),(e=document.createElement("div")).innerHTML=t,i=e.getElementsByTagName("span"),Array.prototype.slice.call(i,0).forEach(function(t){if(!t.hasAttributes()){for(;t.firstChild;)t.parentNode.insertBefore(t.firstChild,t);t.parentNode.removeChild(t)}}),e.innerHTML):t:""},_cleanHTMLLists:function(t){for(var e,i="",n=t,s=null,a=[],o=null,r=null;s=n.match(/<(\/?)(li|ul|ol)\b[^>]*>/i);){if(o={tag:s[2],t
agLowerCase: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.f
ullTag}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)}},r.Base.mix(r.M.editor_atto.Editor,[g]),p.ATTRS={},p.prototype={applyFormat:function(t,e,i,n){var s;if(i=i||this,(s=window.rangy.getSelection()).isCollapsed)return s=this.editor.once("input",function(t,e,i,n,s,a){r.soon(r.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"],s.detach,s);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=r.Node.create("<"+e+" />").setAttrs(i.getAttrs()).removeAttribute("data-iterate"),i.getAttribute("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)}},r.Base.mix(r.M.editor_atto.Editor,[p]),f.ATTRS={},f.prototype={toolbar:null,openMenus:null,setupToolbar:function(){return this.toolbar=r.Node.create('<div class="'+i.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}},r.Base.mix(r.M.editor_atto.Editor,[f]),m.ATTRS={},m.prototype={_tabFocus:null,setupToolbarNavigation:function(){return this._wrapper.delegate("key",this.toolbarKeyboardNavigation,"down:37,39","."+i.TOOLBAR,this),this._wrapper.delegate("focus",function(t){this._setTabFocus(t.currentTarget)},"."+i.TOOLBAR+" button",this),this},toolbarKeyboardNavigation:function(t){t.preventDefault();var e=this.toolbar.all("button"),i=1,n=t.target.ancestor("button",!0),s=t.target.all("button");37===t.keyCode&&(i=-1),(t=this._findFirstF
ocusable(e=!n&&s?s:e,n,i))&&(t.focus(),this._setTabFocus(t))},_findFirstFocusable:function(t,e,i){var n,s,a=0,o=t.indexOf(e);for(o<-1&&(o=0);a<t.size();)if((o+=i)<0?o=t.size()-1:o>=t.size()&&(o=0),a++,!((n=t.item(o)).hasAttribute("hidden")||n.hasAttribute("disabled")||n.ancestor("[hidden]"))){s=n;break}return s},checkTabFocus:function(){var t;return this._tabFocus&&(!(this._tabFocus.hasAttribute("disabled")||this._tabFocus.hasAttribute("hidden")||this._tabFocus.ancestor(".atto_group").hasAttribute("hidden"))||(t=this._findFirstFocusable(this.toolbar.all("button"),this._tabFocus,-1))&&(this._tabFocus.compareTo(document.activeElement)&&t.focus(),this._setTabFocus(t))),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}},r.Base.mix(r.M.editor_atto.Editor,[m]),v.ATTRS={},v.prototype={_selections:null,_lastSelection:null,_foc
usFromClick:!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){r.soon(r.bind(this._hasSelectionChanged,this,t))},this),r.one(document.body).on("gesturemovestart",function(t){this._wrapper.contains(t.target._node)?this._gesturestartededitor=!0:this._gesturestartededitor=!1},null,this),r.one(document.body).on("gesturemoveend",function(t){this._gesturestartededitor&&r.soon(r.bind(this._hasSelectionChanged,this,t))},{standAlone:!0},this),this},isActive:function(){var t=o.createRange(),e=o.getSelection();return!!e.rangeCount&&(!(!document.activeElement||!this.editor.compareTo(document.activeElement)&&!this.editor.contains(document.activeElement))&&(t.selectNode(this.editor.getDOMNode()),t.inte
rsectsRange(e.getRangeAt(0))))},getSelectionFromNode:function(t){var e=o.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 o.getSelection().getAllRanges()},selectionContainsNode:function(t){return o.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=new r.NodeList,s=o.getSelection(),s=s.rangeCount?s.getRangeAt(0):o.createRange();for(s.collapsed&&s.commonAncestorContainer!==this.editor.getDOMNode()&&s.commonAncestorContainer!==r.config.doc&&(s=s.cloneRange()).
selectNode(s.commonAncestorContainer),t=s.getNodes(),i=0;i<t.length;i++)e=r.one(t[i]),this.editor.contains(e)&&n.push(e);return n},_hasSelectionChanged:function(t){var e=o.getSelection(),i=!1,e=e.rangeCount?e.getRangeAt(0):o.createRange();return this._lastSelection&&!this._lastSelection.equals(e)?(i=!0,this._fireSelectionChanged(t)):(this._lastSelection=e,i)},_fireSelectionChanged:function(t){this.fire("atto:selectionchanged",{event:t,selectedNodes:this.getSelectedNodes()})},getSelectionParentNode:function(){var t=o.getSelection();return!!t.rangeCount&&t.getRangeAt(0).commonAncestorContainer},setSelection:function(t){o.getSelection().setRanges(t)},insertContentAtFocusPoint:function(t){var e,i,n,s=o.getSelection(),t=r.Node.create(t);return(e=s.rangeCount?s.getRangeAt(0):e)&&(e.deleteContents(),e.collapse(!1),n=(i=t.getDOMNode()).lastChild||i,e.insertNode(i),e.collapseAfter(
n),s.setSingleRange(e)),t}},r.Base.mix(r.M.editor_atto.Editor,[v]),b.ATTRS={},b.prototype={disableCssStyling:function(){try{document.execCommand("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){t=t.join(" "),t=o.createClassApplier(t,{normalize:!0});t.toggleSelection()},formatSelectionInlineStyle:function(e){var i=this.PLACEHOLDER_CLASS,t=o.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=this.getSelectionParentNode();return!!o&&(i=this.editor,(n=(o=r.one(o)).ancestor(function(t){var e=(e=t.get("tagName"))&&e.toLowerCase();return t===i||"td"===e||"th"===e},!0
))&&(i=n),(n=o.ancestor(this.BLOCK_TAGS.join(", "),!0))&&(n.ancestor(function(t){return t===i},!1)||(n=!1)),n||(o="rtl"===this.coreDirection?'style="text-align: right;"':'style="text-align: left;"',s=r.Node.create('<p dir="'+this.coreDirection+'" '+o+"></p>"),i.get("childNodes").each(function(t){s.append(t.remove())}),i.append(s),n=s),t&&""!==t&&((a=r.Node.create("<"+t+"></"+t+">")).setAttrs(n.getAttrs()),n.get("childNodes").each(function(t){t.remove(),a.append(t)}),n.replace(a),n=a),e&&n.setAttrs(e),o=this.getSelectionFromNode(n),this.setSelection(o),n)}},r.Base.mix(r.M.editor_atto.Editor,[b]),_.ATTRS={filepickeroptions:{value:{}}},_.prototype={canShowFilepicker:function(t){return"undefined"!=typeof this.get("filepickeroptions")[t]},showFilepicker:function(i,n,s){var a=this;r.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)})}},r.Base.mix(r.M.editor_atto.Editor,[_])},"@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-editor_atto-rangy","handlebars","timers","querystring-stringify"]});