MDL-64506 templates: Move BS2 btns' to BS4 btns'
[moodle.git] / lib / editor / atto / plugins / equation / yui / build / moodle-atto_equation-button / moodle-atto_equation-button-min.js
1 YUI.add("moodle-atto_equation-button",function(e,t){var n="atto_equation",r="atto_equation",i={EQUATION_TEXT:"atto_equation_equation",EQUATION_PREVIEW:"atto_equation_preview",SUBMIT:"atto_equation_submit",LIBRARY:"atto_equation_library",LIBRARY_GROUPS:"atto_equation_groups",LIBRARY_GROUP_PREFIX:"atto_equation_group"},s={LIBRARY:"."+i.LIBRARY,LIBRARY_GROUP:"."+i.LIBRARY_GROUPS+" > div > div",EQUATION_TEXT:"."+i.EQUATION_TEXT,EQUATION_PREVIEW:"."+i.EQUATION_PREVIEW,SUBMIT:"."+i.SUBMIT,LIBRARY_BUTTON:"."+i.LIBRARY+" button"},o={START:"\\(",END:"\\)"},u={FORM:'<form class="atto_form">{{{library}}}<label for="{{elementid}}_{{CSS.EQUATION_TEXT}}">{{{get_string "editequation" component texdocsurl}}}</label><textarea class="fullwidth {{CSS.EQUATION_TEXT}}" id="{{elementid}}_{{CSS.EQUATION_TEXT}}" rows="8"></textarea><br/><label for="{{elementid}}_{{CSS.EQUATION_PREVIEW}}">{{get_string "preview" component}}</label><div describedby="{{elementid}}_cursorinfo" class="well well-small p-1 fullwidth {{CSS.EQUATION_PREVIEW}}" id="{{elementid}}_{{CSS.EQUATION_PREVIEW}}"></div><div id="{{elementid}}_cursorinfo">{{get_string "cursorinfo" component}}</div><div class="mdl-align"><br/><button class="btn btn-secondary {{CSS.SUBMIT}}">{{get_string "saveequation" component}}</button></div></form>',LIBRARY:'<div class="{{CSS.LIBRARY}}"><ul class="root nav nav-tabs m-b-1" role="tablist">{{#each library}}<li  class="nav-item"><a class="nav-link" href="#{{../elementid}}_{{../CSS.LIBRARY_GROUP_PREFIX}}_{{@key}}"  role="tab" data-toggle="tab">{{get_string groupname ../component}}</a></li>{{/each}}</ul><div class="tab-content m-b-1 {{CSS.LIBRARY_GROUPS}}">{{#each library}}<div data-medium-type="{{CSS.LINK}}" class="tab-pane" id="{{../elementid}}_{{../CSS.LIBRARY_GROUP_PREFIX}}_{{@key}}"><div role="toolbar">{{#split "\n" elements}}<button class="btn btn-secondary" tabindex="-1" data-tex="{{this}}"aria-label="{{this}}" title="{{this}}">{{../../DELIMITERS.START}}{{this}}{{../../DELIMITERS.END}}</button>{{/split}}</div></div>{{/each}}</div></div>'};e.namespace("M.atto_equation").Button=e.Base.create("button",e.M.editor_atto.EditorPlugin,[],{_currentSelection:null,_lastCursorPos:0,_content:null,_sourceEquation:null,_groupFocus:null,_equationPatterns:[/\$\$([\S\s]+?)\$\$/,/\\\(([\S\s]+?)\\\)/,/\\\[([\S\s]+?)\\\]/,/\[tex\]([\S\s]+?)\[\/tex\]/],initializer:function(){this._groupFocus={},this.get("texfilteractive")&&(this.addButton({icon:"e/math",callback:this._displayDialogue}),this.get("host").on("atto:selectionchanged",function(){this._resolveEquation()?this.highlightButtons():this.unHighlightButtons()},this),this.editor.all("tex").each(function(t){var n=e.Node.create("<span>"+o.START+" "+t.get("text")+" "+o.END+"</span>");t.replace(n)}))},_displayDialogue:function(){this._currentSelection=this.get("host").getSelection();if(this._currentSelection===!1)return;var e=this._resolveEquation(),t=this.getDialogue({headerContent:M.util.get_string("pluginname",n),focusAfterHide:!0,width:600,focusOnShowSelector:s.EQUATION_TEXT}),r=this._getDialogueContent();t.set("bodyContent",r),r.one(".nav-item:first-child .nav-link").getDOMNode().click(),t.show(),require(["core/event"],function(e){e.notifyFilterContentUpdated(t.get("boundingBox").getDOMNode())}),e&&r.one(s.EQUATION_TEXT).set("text",e),this._updatePreview(!1)},_resolveEquation:function(){var t=this.get("host").getSelectionParentNode(),n=this.get("host").getSelection(),r,i=!1;return this.get("host").isActive()?t?!n||n.length===0?!1:(this.sourceEquation=null,n=n[0],r=e.one(t).get("text"),e.Array.find(this._equationPatterns,function(t){var s=r.match(new RegExp(t.source,"g"));if(s&&s.length)return e.Array.find(s,function(e){var s=0;while(r.indexOf(e,s)!==-1){var o=r.indexOf(e,s),u=o+e.length,a=n.startOffset>=o&&n.startOffset<u,f=n.endOffset<=u&&n.endOffset>o;if(a&&f){var l=e.match(t);if(l&&l.length){var c=r.indexOf(l[1],o),h=c+l[1].length;return i=l[1],this.sourceEquation={startOuterPosition:o,endOuterPosition:u,outerMatch:e,startInnerPosition:c,endInnerPosition:h,innerMatch:l},!0}}s=u}},this)},this),i!==!1&&(i=i.trim()),i):!1:!1},_setEquation:function(t){var n,r,i,s,u,a;u=this.get("host"),t.preventDefault(),this.getDialogue({focusAfterHide:null}).hide(),n=t.currentTarget.ancestor(".atto_form").one("textarea"),s=n.get("value"),s!==""&&(u.setSelection(this._currentSelection),this.sourceEquation?(r=e.one(u.getSelectionParentNode()),i=r.get("text"),s=" "+s+" ",a=i.slice(0,this.sourceEquation.startInnerPosition)+s+i.slice(this.sourceEquation.endInnerPosition),r.set("text",a)):(s=o.START+" "+s+" "+o.END,u.insertContentAtFocusPoint(s)),this.markUpdated())},_throttle:function(e,t){var n=null;return function(){var r=this,i=arguments;clearTimeout(n),n=setTimeout(function(){e.apply(r,i)},t)}},_updatePreview:function(t){var n=this._content.one(s.EQUATION_TEXT),r=n.get("value"),i,u=n.get("selectionStart"),a="",f="\\Downarrow ",l,c;t&&t.preventDefault(),u||(u=0);while(r.charAt(u)==="\\"&&u>=0)u-=1;l=/[a-zA-Z\{]/;if(u!==0&&r.charAt(u-1)!="{")while(l.test(r.charAt(u))&&u<r.length&&l.test(r.charAt(u-1)))u+=1;this._lastCursorPos=u,r=a+r.substring(0,u)+f+r.substring(u),r=o.START+" "+r+" "+o.END,i=M.cfg.wwwroot+"/lib/editor/atto/plugins/equation/ajax.php",c={sesskey:M.cfg.sesskey,contextid:this.get("contextid"),action:"filtertext",text:r},e.io(i,{context:this,data:c,timeout:500,on:{complete:this._loadPreview}})},_loadPreview:function(e,t){var n=this._content.one(s.EQUATION_PREVIEW);t.status===200&&(n.setHTML(t.responseText),require(["core/event"],function(e){e.notifyFilterContentUpdated(n.getDOMNode())}))},_getDialogueContent:function(){var t=this._getLibraryContent(),r=this._throttle(this._updatePreview,500),o=e.Handlebars.compile(u.FORM);return this._content=e.Node.create(o({elementid:this.get("host").get("elementid"),component:n,library:t,texdocsurl:this.get("texdocsurl"),CSS:i})),this._content.all(s.LIBRARY_GROUP).each(function(e){this._setGroupTabFocus(e,e.one("button")),e.all("button a").setAttribute
2 ("tabindex","-1")},this),this._content.delegate("key",this._groupNavigation,"down:37,39",s.LIBRARY_BUTTON,this),this._content.one(s.SUBMIT).on("click",this._setEquation,this),this._content.one(s.EQUATION_TEXT).on("valuechange",r,this),this._content.one(s.EQUATION_TEXT).on("mouseup",r,this),this._content.one(s.EQUATION_TEXT).on("keyup",r,this),this._content.delegate("click",this._selectLibraryItem,s.LIBRARY_BUTTON,this),this._content},_groupNavigation:function(e){e.preventDefault();var t=e.currentTarget,n=t.get("parentNode"),r=n.all("button"),i=e.keyCode!==37?1:-1,s=r.indexOf(t),o;s<0&&(s=0),s+=i,s<0?s=r.size()-1:s>=r.size()&&(s=0),o=r.item(s),this._setGroupTabFocus(n,o),o.focus()},_setGroupTabFocus:function(e,t){var n=e.generateID();typeof this._groupFocus[n]!="undefined"&&this._groupFocus[n].setAttribute("tabindex","-1"),this._groupFocus[n]=t,t.setAttribute("tabindex",0),e.setAttribute("aria-activedescendant",t.generateID())},_selectLibraryItem:function(e){var t=e.currentTarget.getAttribute("data-tex"),n,r,i,s=0;e.preventDefault(),this._setGroupTabFocus(e.currentTarget.get("parentNode"),e.currentTarget),i=e.currentTarget.ancestor(".atto_form").one("textarea"),n=i.get("value"),r=n.substring(0,this._lastCursorPos),r.charAt(r.length-1)!==" "&&(r+=" "),r+=t,s=r.length,n.charAt(this._lastCursorPos)!==" "&&(r+=" "),r+=n.substring(this._lastCursorPos,n.length),i.set("value",r),i.focus();var o=i.getDOMNode();if(typeof o.selectionStart=="number")o.selectionStart=o.selectionEnd=s;else if(typeof o.createTextRange!="undefined"){var u=o.createTextRange();u.moveToPoint(s),u.select()}this._updatePreview(!1)},_getLibraryContent:function(){var t=e.Handlebars.compile(u.LIBRARY),r=this.get("library"),s="";e.Handlebars.registerHelper("split",function(e,t,n){var r,i,s;if(typeof e=="undefined"||typeof t=="undefined")return"";s="",r=t.trim().split(e);while(r.length>0)i=r.shift().trim(),s+=n.fn(i);return s}),s=t({elementid:this.get("host").get("elementid"),component:n,library:r,CSS:i,DELIMITERS:o});var a=M.cfg.wwwroot+"/lib/editor/atto/plugins/equation/ajax.php",f={sesskey:M.cfg.sesskey,contextid:this.get("contextid"),action:"filtertext",text:s},l=e.io(a,{sync:!0,data:f,method:"POST"});return l.status===200&&(s=l.responseText),s}},{ATTRS:{texfilteractive:{value:!1},contextid:{value:null},library:{value:{}},texdocsurl:{value:null}}})},"@VERSION@",{requires:["moodle-editor_atto-plugin","moodle-core-event","io","event-valuechange","tabview","array-extras"]});