a0135cacdb29357fb73250fcd57d1d4e6870f6dd
[moodle.git] / lib / editor / atto / yui / build / moodle-editor_atto-editor / moodle-editor_atto-editor-min.js
1 YUI.add("moodle-editor_atto-editor",function(e,t){M.editor_atto=M.editor_atto||{buttonhandlers:{},menus:{},menuhandlers:{},filepickeroptions:{},widgets:{},showhide_menu_handler:function(e){e.preventDefault();var t=this.getAttribute("disabled"),n=this.getAttribute("data-menu"),r=M.editor_atto.menus[n],i=r.get("bodyContent");r.get("visible")||t?(r.hide(),i.detach("clickoutside")):(i.on("clickoutside",function(e){e.target.ancestor()!==this&&r.get("visible")&&(i.detach("clickoutside"),r.hide())},this),r.show())},buttonclicked_handler:function(e){var t=this.getAttribute("data-editor"),n=this.getAttribute("data-plugin"),r=this.getAttribute("data-handler"),i=M.editor_atto.menus[n+"_"+t];i&&i.hide();if(M.editor_atto.is_enabled(t,n))return r=M.editor_atto.buttonhandlers[r],r(e,t)},is_enabled:function(t,n){var r=e.one("#"+t+"_toolbar .atto_"+n+"_button");return!r.hasAttribute("disabled")},disable_all_widgets:function(t){var n,r;for(n in M.editor_atto.widgets)r=e.one("#"+t+"_toolbar .atto_"+n+"_button"),r&&r.setAttribute("disabled","true")},enable_widget:function(t,n){var r=e.one("#"+t+"_toolbar .atto_"+n+"_button");r&&r.removeAttribute("disabled")},enable_all_widgets:function(t){var n,r;for(n in M.editor_atto.widgets)r=e.one("#"+t+"_toolbar .atto_"+n+"_button"),r&&r.removeAttribute("disabled")},add_toolbar_menu:function(t,n,r,i){var s=e.one("#"+t+"_toolbar"),o=e.Node.create('<button class="atto_'+n+'_button atto_hasmenu" '+'data-editor="'+e.Escape.html(t)+'" '+'data-menu="'+n+"_"+t+'" >'+r+"</button>");s.append(o),M.editor_atto.widgets[n]=n;var u=e.Node.create('<div class="atto_'+n+"_menu"+' atto_menu" data-editor="'+e.Escape.html(t)+'"></div>'),a=0,f={};for(a=0;a<i.length;a++)f=i[a],u.append(e.Node.create('<div class="atto_menuentry"><a href="#" class="atto_'+n+"_action_"+a+'" '+'data-editor="'+e.Escape.html(t)+'" '+'data-plugin="'+e.Escape.html(n)+'" '+'data-handler="'+e.Escape.html(n+"_action_"+a)+'">'+f.text+"</a>"+"</div>")),M.editor_atto.buttonhandlers[n+"_action_"+a]||(e.one("body").delegate("click",M.editor_atto.buttonclicked_handler,".atto_"+n+"_action_"+a),M.editor_atto.buttonhandlers[n+"_action_"+a]=f.handler);M.editor_atto.buttonhandlers[n]||(e.one("body").delegate("click",M.editor_atto.showhide_menu_handler,".atto_"+n+"_button"),M.editor_atto.buttonhandlers[n]=!0);var l=new M.core.dialogue({bodyContent:u,visible:!1,width:"14em",zindex:100,lightbox:!1,closeButton:!1,centered:!1,align:{node:o,points:[e.WidgetPositionAlign.TL,e.WidgetPositionAlign.BL]}});M.editor_atto.menus[n+"_"+t]=l,l.render(),l.hide(),l.headerNode.hide()},add_toolbar_button:function(t,n,r,i){var s=e.one("#"+t+"_toolbar"),o=e.Node.create('<button class="atto_'+n+'_button" '+'data-editor="'+e.Escape.html(t)+'" '+'data-plugin="'+e.Escape.html(n)+'" '+'data-handler="'+e.Escape.html(n)+'">'+r+"</button>");s.append(o),M.editor_atto.buttonhandlers[n]||(e.one("body").delegate("click",M.editor_atto.buttonclicked_handler,".atto_"+n+"_button"),M.editor_atto.buttonhandlers[n]=i),M.editor_atto.widgets[n]=n},is_active:function(t){var n=M.editor_atto.get_selection();n.length&&(n=n.pop());var r=null;return n.parentElement?r=e.one(n.parentElement()):r=e.one(n.startContainer),r&&r.ancestor("#"+t+"editable")!==null},focus:function(t){e.one("#"+t+"editable").focus()},init:function(t){var n=e.one("#"+t.elementid),r=e.Node.create('<div id="'+t.elementid+'editable" '+'contenteditable="true" '+'spellcheck="true" '+'class="editor_atto"/>'),i="",s=e.Node.create('<div class="editor_atto_toolbar" id="'+t.elementid+'_toolbar"/>'),o=e.io(t.content_css,{sync:!0}),u=o.responseText.indexOf("font:");u&&(i=o.responseText.substring(u+"font:".length,o.responseText.length-1),r.setStyle("font",i)),r.setStyle("minHeight",1.2*(n.getAttribute("rows")-1)+"em"),r.append(n.get("value")),n.get("parentNode").insert(s,n),n.get("parentNode").insert(r,n),r.setStyle("color",n.getStyle("color")),r.setStyle("lineHeight",n.getStyle("lineHeight")),r.setStyle("fontSize",n.getStyle("fontSize")),n.hide(),r.on("blur",function(){n.set("value",r.getHTML())}),M.editor_atto.filepickeroptions[t.elementid]=t.filepickeroptions},show_filepicker:function(t,n,r){e.use("core_filepicker",function(e){var i=M.editor_atto.filepickeroptions[t][n];i.formcallback=r,i.editor_target=e.one(t),M.core_filepicker.show(e,i)})},get_selection_from_node:function(e){var t;return window.getSelection?(t=document.createRange(),t.setStartBefore(e.getDOMNode()),t.setEndAfter(e.getDOMNode()),[t]):document.selection?(t=document.body.createTextRange(),t.moveToElementText(e.getDOMNode()),t):!1},get_selection:function(){if(window.getSelection){var e=window.getSelection(),t=[],n=0;for(n=0;n<e.rangeCount;n++)t.push(e.getRangeAt(n));return t}return document.selection&&document.selection.createRange?document.selection.createRange():!1},get_selection_parent_node:function(){var e=M.editor_atto.get_selection();if(e.length>0)return e[0].commonAncestorContainer},get_selection_text:function(){var e=M.editor_atto.get_selection();if(e.length>0&&e[0].cloneContents)return e[0].cloneContents()},set_selection:function(e){var t,n;if(window.getSelection){t=window.getSelection(),t.removeAllRanges();for(n=0;n<e.length;n++)t.addRange(e[n])}else document.selection&&e.select&&e.select()}}},"@VERSION@",{requires:["node","io","overlay","escape","moodle-core-notification"]});