!function(e){"function"==typeof define&&define.amd?define(["jquery"],e):"object"==typeof module&&module.exports?module.exports=function(t,n){return void 0===n&&(n="undefined"!=typeof window?require("jquery"):require("jquery")(t)),e(n),n}:e(jQuery)}(function(e){var t=function(){if(e&&e.fn&&e.fn.ppma_select2&&e.fn.ppma_select2.amd)var t,n,n=e.fn.ppma_select2.amd;return!function(){if(!n||!n.requirejs){var e,t,i;n?t=n:n={},function(n){var r,s,o,a,l={},c={},u={},p={},d=Object.prototype.hasOwnProperty,h=[].slice,f=/\.js$/;function m(e,t){return d.call(e,t)}function g(e,t){var n,i,r,s,o,a,l,c,p,d,h,m,g=t&&t.split("/"),v=u.map,y=v&&v["*"]||{};if(e){for(o=(e=e.split("/")).length-1,u.nodeIdCompat&&f.test(e[o])&&(e[o]=e[o].replace(f,"")),"."===e[0].charAt(0)&&g&&(e=(m=g.slice(0,g.length-1)).concat(e)),p=0;p0&&(e.splice(p-1,2),p-=2)}e=e.join("/")}if((g||y)&&v){for(p=(n=e.split("/")).length;p>0;p-=1){if(i=n.slice(0,p).join("/"),g){for(d=g.length;d>0;d-=1)if((r=v[g.slice(0,d).join("/")])&&(r=r[i])){s=r,a=p;break}}if(s)break;!l&&y&&y[i]&&(l=y[i],c=p)}!s&&l&&(s=l,a=c),s&&(n.splice(0,a,s),e=n.join("/"))}return e}function v(e,t){return function(){var i=h.call(arguments,0);return"string"!=typeof i[0]&&1===i.length&&i.push(null),s.apply(n,i.concat([e,t]))}}function y(e){return function(t){l[e]=t}}function b(e){if(m(c,e)){var t=c[e];delete c[e],p[e]=!0,r.apply(n,t)}if(!m(l,e)&&!m(p,e))throw Error("No "+e);return l[e]}function w(e){var t,n=e?e.indexOf("!"):-1;return n>-1&&(t=e.substring(0,n),e=e.substring(n+1,e.length)),[t,e]}function A(e){return e?w(e):[]}o=function(e,t){var n,i,r=w(e),s=r[0],o=t[1];return(e=r[1],s&&(i=b(s=g(s,o))),s)?e=i&&i.normalize?i.normalize(e,(n=o,function(e){return g(e,n)})):g(e,o):(e=g(e,o),s=(r=w(e))[0],e=r[1],s&&(i=b(s))),{f:s?s+"!"+e:e,n:e,pr:s,p:i}},a={require:function(e){return v(e)},exports:function(e){var t=l[e];return void 0!==t?t:l[e]={}},module:function(e){var t;return{id:e,uri:"",exports:l[e],config:(t=e,function(){return u&&u.config&&u.config[t]||{}})}}},r=function(e,t,i,r){var s,u,d,h,f,g,w,D=[],x=typeof i;if(g=A(r=r||e),"undefined"===x||"function"===x){for(f=0,t=!t.length&&i.length?["require","exports","module"]:t;f0&&(n.call(arguments,e.prototype.constructor),r=t.prototype.constructor),r.apply(this,arguments)}t.displayName=e.displayName,s.prototype=new function e(){this.constructor=s};for(var o=0;o":">",'"':""","'":"'","/":"/"};return"string"!=typeof e?e:String(e).replace(/[&<>"'\/\\]/g,function(e){return t[e]})},t.appendMany=function(t,n){if("1.7"===e.fn.jquery.substr(0,3)){var i=e();e.map(n,function(e){i=i.add(e)}),n=i}t.append(n)},t.__cache={};var r=0;return t.GetUniqueElementId=function(e){var t=e.getAttribute("data-ppma_select2-id");return null==t&&(e.id?(t=e.id,e.setAttribute("data-ppma_select2-id",t)):(e.setAttribute("data-ppma_select2-id",++r),t=r.toString())),t},t.StoreData=function(e,n,i){var r=t.GetUniqueElementId(e);t.__cache[r]||(t.__cache[r]={}),t.__cache[r][n]=i},t.GetData=function(n,i){var r=t.GetUniqueElementId(n);return i?t.__cache[r]&&null!=t.__cache[r][i]?t.__cache[r][i]:e(n).data(i):t.__cache[r]},t.RemoveData=function(e){var n=t.GetUniqueElementId(e);null!=t.__cache[n]&&delete t.__cache[n],e.removeAttribute("data-ppma_select2-id")},t}),n.define("ppma_select2/results",["jquery","./utils"],function(e,t){function n(e,t,i){this.$element=e,this.data=i,this.options=t,n.__super__.constructor.call(this)}return t.Extend(n,t.Observable),n.prototype.render=function(){var t=e('
    ');return this.options.get("multiple")&&t.attr("aria-multiselectable","true"),this.$results=t,t},n.prototype.clear=function(){this.$results.empty()},n.prototype.displayMessage=function(t){var n=this.options.get("escapeMarkup");this.clear(),this.hideLoading();var i=e(''),r=this.options.get("translations").get(t.message);i.append(n(r(t.args))),i[0].className+=" ppma_select2-results__message",this.$results.append(i)},n.prototype.hideMessages=function(){this.$results.find(".ppma_select2-results__message").remove()},n.prototype.append=function(e){this.hideLoading();var t=[];if(null==e.results||0===e.results.length){0===this.$results.children().length&&this.trigger("results:message",{message:"noResults"});return}e.results=this.sort(e.results);for(var n=0;n0?t.first().trigger("mouseenter"):e.first().trigger("mouseenter"),this.ensureHighlightVisible()},n.prototype.setClasses=function(){var n=this;this.data.current(function(i){var r=e.map(i,function(e){return e.id.toString()});n.$results.find(".ppma_select2-results__option[aria-selected]").each(function(){var n=e(this),i=t.GetData(this,"data"),s=""+i.id;null!=i.element&&i.element.selected||null==i.element&&e.inArray(s,r)>-1?n.attr("aria-selected","true"):n.attr("aria-selected","false")})})},n.prototype.showLoading=function(e){this.hideLoading();var t={disabled:!0,loading:!0,text:this.options.get("translations").get("searching")(e)},n=this.option(t);n.className+=" loading-results",this.$results.prepend(n)},n.prototype.hideLoading=function(){this.$results.find(".loading-results").remove()},n.prototype.option=function(n){var i=document.createElement("li");i.className="ppma_select2-results__option";var r={role:"option","aria-selected":"false"},s=window.Element.prototype.matches||window.Element.prototype.msMatchesSelector||window.Element.prototype.webkitMatchesSelector;for(var o in(null!=n.element&&s.call(n.element,":disabled")||null==n.element&&n.disabled)&&(delete r["aria-selected"],r["aria-disabled"]="true"),null==n.id&&delete r["aria-selected"],null!=n._resultId&&(i.id=n._resultId),n.title,n.children&&(r.role="group",r["aria-label"]=n.text,delete r["aria-selected"]),r){var a=r[o];i.setAttribute(o,a)}if(n.children){var l=e(i),c=document.createElement("strong");c.className="ppma_select2-results__group",e(c),this.template(n,c);for(var u=[],p=0;p",{class:"ppma_select2-results__options ppma_select2-results__options--nested"});f.append(u),l.append(c),l.append(f)}else this.template(n,i);return t.StoreData(i,"data",n),i},n.prototype.bind=function(n,i){var r=this,s=n.id+"-results";this.$results.attr("id",s),n.on("results:all",function(e){r.clear(),r.append(e.data),n.isOpen()&&(r.setClasses(),r.highlightFirstItem())}),n.on("results:append",function(e){r.append(e.data),n.isOpen()&&r.setClasses()}),n.on("query",function(e){r.hideMessages(),r.showLoading(e)}),n.on("select",function(){n.isOpen()&&(r.setClasses(),r.options.get("scrollAfterSelect")&&r.highlightFirstItem())}),n.on("unselect",function(){n.isOpen()&&(r.setClasses(),r.options.get("scrollAfterSelect")&&r.highlightFirstItem())}),n.on("open",function(){r.$results.attr("aria-expanded","true"),r.$results.attr("aria-hidden","false"),r.setClasses(),r.ensureHighlightVisible()}),n.on("close",function(){r.$results.attr("aria-expanded","false"),r.$results.attr("aria-hidden","true"),r.$results.removeAttr("aria-activedescendant")}),n.on("results:toggle",function(){var e=r.getHighlightedResults();0!==e.length&&e.trigger("mouseup")}),n.on("results:select",function(){var e=r.getHighlightedResults();if(0!==e.length){var n=t.GetData(e[0],"data");"true"==e.attr("aria-selected")?r.trigger("close",{}):r.trigger("select",{data:n})}}),n.on("results:previous",function(){var e=r.getHighlightedResults(),t=r.$results.find("[aria-selected]"),n=t.index(e);if(!(n<=0)){var i=n-1;0===e.length&&(i=0);var s=t.eq(i);s.trigger("mouseenter");var o=r.$results.offset().top,a=s.offset().top,l=r.$results.scrollTop()+(a-o);0===i?r.$results.scrollTop(0):a-o<0&&r.$results.scrollTop(l)}}),n.on("results:next",function(){var e=r.getHighlightedResults(),t=r.$results.find("[aria-selected]"),n=t.index(e)+1;if(!(n>=t.length)){var i=t.eq(n);i.trigger("mouseenter");var s=r.$results.offset().top+r.$results.outerHeight(!1),o=i.offset().top+i.outerHeight(!1),a=r.$results.scrollTop()+o-s;0===n?r.$results.scrollTop(0):o>s&&r.$results.scrollTop(a)}}),n.on("results:focus",function(e){e.element.addClass("ppma_select2-results__option--highlighted")}),n.on("results:message",function(e){r.displayMessage(e)}),e.fn.mousewheel&&this.$results.on("mousewheel",function(e){var t=r.$results.scrollTop(),n=r.$results.get(0).scrollHeight-t+e.deltaY,i=e.deltaY>0&&t-e.deltaY<=0,s=e.deltaY<0&&n<=r.$results.height();i?(r.$results.scrollTop(0),e.preventDefault(),e.stopPropagation()):s&&(r.$results.scrollTop(r.$results.get(0).scrollHeight-r.$results.height()),e.preventDefault(),e.stopPropagation())}),this.$results.on("mouseup",".ppma_select2-results__option[aria-selected]",function(n){var i=e(this),s=t.GetData(this,"data");if("true"===i.attr("aria-selected")){r.options.get("multiple")?r.trigger("unselect",{originalEvent:n,data:s}):r.trigger("close",{});return}r.trigger("select",{originalEvent:n,data:s})}),this.$results.on("mouseenter",".ppma_select2-results__option[aria-selected]",function(n){var i=t.GetData(this,"data");r.getHighlightedResults().removeClass("ppma_select2-results__option--highlighted"),r.trigger("results:focus",{data:i,element:e(this)})})},n.prototype.getHighlightedResults=function(){return this.$results.find(".ppma_select2-results__option--highlighted")},n.prototype.destroy=function(){this.$results.remove()},n.prototype.ensureHighlightVisible=function(){var e=this.getHighlightedResults();if(0!==e.length){var t=this.$results.find("[aria-selected]").index(e),n=this.$results.offset().top,i=e.offset().top,r=this.$results.scrollTop()+(i-n),s=i-n;r-=2*e.outerHeight(!1),t<=2?this.$results.scrollTop(0):(s>this.$results.outerHeight()||s<0)&&this.$results.scrollTop(r)}},n.prototype.template=function(t,n){var i=this.options.get("templateResult"),r=this.options.get("escapeMarkup"),s=i(t,n);null==s?n.style.display="none":"string"==typeof s?n.innerHTML=r(s):e(n).append(s)},n}),n.define("ppma_select2/keys",[],function(){return{BACKSPACE:8,TAB:9,ENTER:13,SHIFT:16,CTRL:17,ALT:18,ESC:27,SPACE:32,PAGE_UP:33,PAGE_DOWN:34,END:35,HOME:36,LEFT:37,UP:38,RIGHT:39,DOWN:40,DELETE:46}}),n.define("ppma_select2/selection/base",["jquery","../utils","../keys"],function(e,t,n){function i(e,t){this.$element=e,this.options=t,i.__super__.constructor.call(this)}return t.Extend(i,t.Observable),i.prototype.render=function(){var n=e('');return this._tabindex=0,null!=t.GetData(this.$element[0],"old-tabindex")?this._tabindex=t.GetData(this.$element[0],"old-tabindex"):null!=this.$element.attr("tabindex")&&(this._tabindex=this.$element.attr("tabindex")),n.attr("tabindex",this._tabindex),n.attr("aria-disabled","false"),this.$selection=n,n},i.prototype.bind=function(e,t){var i=this,r=e.id+"-results";this.container=e,this.$selection.on("focus",function(e){i.trigger("focus",e)}),this.$selection.on("blur",function(e){i._handleBlur(e)}),this.$selection.on("keydown",function(e){i.trigger("keypress",e),e.which===n.SPACE&&e.preventDefault()}),e.on("results:focus",function(e){i.$selection.attr("aria-activedescendant",e.data._resultId)}),e.on("selection:update",function(e){i.update(e.data)}),e.on("open",function(){i.$selection.attr("aria-expanded","true"),i.$selection.attr("aria-owns",r),i._attachCloseHandler(e)}),e.on("close",function(){i.$selection.attr("aria-expanded","false"),i.$selection.removeAttr("aria-activedescendant"),i.$selection.removeAttr("aria-owns"),i.$selection.trigger("focus"),i._detachCloseHandler(e)}),e.on("enable",function(){i.$selection.attr("tabindex",i._tabindex),i.$selection.attr("aria-disabled","false")}),e.on("disable",function(){i.$selection.attr("tabindex","-1"),i.$selection.attr("aria-disabled","true")})},i.prototype._handleBlur=function(t){var n=this;window.setTimeout(function(){!(document.activeElement==n.$selection[0]||e.contains(n.$selection[0],document.activeElement))&&n.trigger("blur",t)},1)},i.prototype._attachCloseHandler=function(n){e(document.body).on("mousedown.ppma_select2."+n.id,function(n){var i=e(n.target).closest(".ppma_select2");e(".ppma_select2.ppma_select2-container--open").each(function(){this!=i[0]&&t.GetData(this,"element").ppma_select2("close")})})},i.prototype._detachCloseHandler=function(t){e(document.body).off("mousedown.ppma_select2."+t.id)},i.prototype.position=function(e,t){t.find(".selection").append(e)},i.prototype.destroy=function(){this._detachCloseHandler(this.container)},i.prototype.update=function(e){throw Error("The `update` method must be defined in child classes.")},i.prototype.isEnabled=function(){return!this.isDisabled()},i.prototype.isDisabled=function(){return this.options.get("disabled")},i}),n.define("ppma_select2/selection/single",["jquery","./base","../utils","../keys"],function(e,t,n,i){function r(){r.__super__.constructor.apply(this,arguments)}return n.Extend(r,t),r.prototype.render=function(){var e=r.__super__.render.call(this);return e.addClass("ppma_select2-selection--single"),e.html(''),e},r.prototype.bind=function(e,t){var n=this;r.__super__.bind.apply(this,arguments);var i=e.id+"-container";this.$selection.find(".ppma_select2-selection__rendered").attr("id",i).attr("role","textbox").attr("aria-readonly","true"),this.$selection.attr("aria-labelledby",i),this.$selection.on("mousedown",function(e){1===e.which&&n.trigger("toggle",{originalEvent:e})}),this.$selection.on("focus",function(e){}),this.$selection.on("blur",function(e){}),e.on("focus",function(t){e.isOpen()||n.$selection.trigger("focus")})},r.prototype.clear=function(){var e=this.$selection.find(".ppma_select2-selection__rendered");e.empty(),e.removeAttr("title")},r.prototype.display=function(e,t){var n=this.options.get("templateSelection");return this.options.get("escapeMarkup")(n(e,t))},r.prototype.selectionContainer=function(){return e("")},r.prototype.update=function(e){if(0===e.length){this.clear();return}var t=e[0],n=this.$selection.find(".ppma_select2-selection__rendered"),i=this.display(t,n);n.empty().append(i),t.title||t.text,n.removeAttr("title")},r}),n.define("ppma_select2/selection/multiple",["jquery","./base","../utils"],function(e,t,n){function i(e,t){i.__super__.constructor.apply(this,arguments)}return n.Extend(i,t),i.prototype.render=function(){var e=i.__super__.render.call(this);return e.addClass("ppma_select2-selection--multiple"),e.html('
      '),e},i.prototype.bind=function(t,r){var s=this;i.__super__.bind.apply(this,arguments),this.$selection.on("click",function(e){s.trigger("toggle",{originalEvent:e})}),this.$selection.on("click",".ppma_select2-selection__choice__remove",function(t){if(!s.isDisabled()){var i=e(this).parent(),r=n.GetData(i[0],"data");s.trigger("unselect",{originalEvent:t,data:r})}})},i.prototype.clear=function(){var e=this.$selection.find(".ppma_select2-selection__rendered");e.empty(),e.removeAttr("title")},i.prototype.display=function(e,t){var n=this.options.get("templateSelection");return this.options.get("escapeMarkup")(n(e,t))},i.prototype.selectionContainer=function(){return e('
    • ×
    • ')},i.prototype.update=function(e){if(this.clear(),0!==e.length){for(var t=[],i=0;i1||n)return e.call(this,t);this.clear();var i=this.createPlaceholder(this.placeholder);this.$selection.find(".ppma_select2-selection__rendered").append(i)},t}),n.define("ppma_select2/selection/allowClear",["jquery","../keys","../utils"],function(e,t,n){function i(){}return i.prototype.bind=function(e,t,n){var i=this;e.call(this,t,n),null==this.placeholder&&this.options.get("debug")&&window.console&&console.error&&console.error("PPMA_Select2: The `allowClear` option should be used in combination with the `placeholder` option."),this.$selection.on("mousedown",".ppma_select2-selection__clear",function(e){i._handleClear(e)}),t.on("keypress",function(e){i._handleKeyboardClear(e,t)})},i.prototype._handleClear=function(e,t){if(!this.isDisabled()){var i=this.$selection.find(".ppma_select2-selection__clear");if(0!==i.length){t.stopPropagation();var r=n.GetData(i[0],"data"),s=this.$element.val();this.$element.val(this.placeholder.id);var o={data:r};if(this.trigger("clear",o),o.prevented){this.$element.val(s);return}for(var a=0;a0)&&0!==i.length){var r=e('×');n.StoreData(r[0],"data",i),this.$selection.find(".ppma_select2-selection__rendered").prepend(r)}},i}),n.define("ppma_select2/selection/search",["jquery","../utils","../keys"],function(e,t,n){function i(e,t,n){e.call(this,t,n)}return i.prototype.render=function(t){var n=e('');this.$searchContainer=n,this.$search=n.find("input");var i=t.call(this);return this._transferTabIndex(),i},i.prototype.bind=function(e,i,r){var s=this,o=i.id+"-results";e.call(this,i,r),i.on("open",function(){s.$search.attr("aria-controls",o),s.$search.trigger("focus")}),i.on("close",function(){s.$search.val(""),s.$search.removeAttr("aria-controls"),s.$search.removeAttr("aria-activedescendant"),s.$search.trigger("focus")}),i.on("enable",function(){s.$search.prop("disabled",!1),s._transferTabIndex()}),i.on("disable",function(){s.$search.prop("disabled",!0)}),i.on("focus",function(e){s.$search.trigger("focus")}),i.on("results:focus",function(e){e.data._resultId?s.$search.attr("aria-activedescendant",e.data._resultId):s.$search.removeAttr("aria-activedescendant")}),this.$selection.on("focusin",".ppma_select2-search--inline",function(e){s.trigger("focus",e)}),this.$selection.on("focusout",".ppma_select2-search--inline",function(e){s._handleBlur(e)}),this.$selection.on("keydown",".ppma_select2-search--inline",function(e){if(e.stopPropagation(),s.trigger("keypress",e),s._keyUpPrevented=e.isDefaultPrevented(),e.which===n.BACKSPACE&&""===s.$search.val()){var i=s.$searchContainer.prev(".ppma_select2-selection__choice");if(i.length>0){var r=t.GetData(i[0],"data");s.searchRemoveChoice(r),e.preventDefault()}}}),this.$selection.on("click",".ppma_select2-search--inline",function(e){s.$search.val()&&e.stopPropagation()});var a=document.documentMode,l=a&&a<=11;this.$selection.on("input.searchcheck",".ppma_select2-search--inline",function(e){if(l){s.$selection.off("input.search input.searchcheck");return}s.$selection.off("keyup.search")}),this.$selection.on("keyup.search input.search",".ppma_select2-search--inline",function(e){if(l&&"input"===e.type){s.$selection.off("input.search input.searchcheck");return}var t=e.which;t!=n.SHIFT&&t!=n.CTRL&&t!=n.ALT&&t!=n.TAB&&s.handleSearch(e)})},i.prototype._transferTabIndex=function(e){this.$search.attr("tabindex",this.$selection.attr("tabindex")),this.$selection.attr("tabindex","-1")},i.prototype.createPlaceholder=function(e,t){this.$search.attr("placeholder",t.text)},i.prototype.update=function(e,t){var n=this.$search[0]==document.activeElement;this.$search.attr("placeholder",""),e.call(this,t),this.$selection.find(".ppma_select2-selection__rendered").append(this.$searchContainer),this.resizeSearch(),n&&this.$search.trigger("focus")},i.prototype.handleSearch=function(){if(this.resizeSearch(),!this._keyUpPrevented){var e=this.$search.val();this.trigger("query",{term:e})}this._keyUpPrevented=!1},i.prototype.searchRemoveChoice=function(e,t){this.trigger("unselect",{data:t}),this.$search.val(t.text),this.handleSearch()},i.prototype.resizeSearch=function(){this.$search.css("width","25px");var e="";e=""!==this.$search.attr("placeholder")?this.$selection.find(".ppma_select2-selection__rendered").width():.75*(this.$search.val().length+1)+"em",this.$search.css("width",e)},i}),n.define("ppma_select2/selection/eventRelay",["jquery"],function(e){function t(){}return t.prototype.bind=function(t,n,i){var r=this,s=["open","opening","close","closing","select","selecting","unselect","unselecting","clear","clearing"],o=["opening","closing","selecting","unselecting","clearing"];t.call(this,n,i),n.on("*",function(t,n){if(-1!==e.inArray(t,s)){n=n||{};var i=e.Event("ppma_select2:"+t,{params:n});r.$element.trigger(i),-1!==e.inArray(t,o)&&(n.prevented=i.isDefaultPrevented())}})},t}),n.define("ppma_select2/translation",["jquery","require"],function(e,t){function n(e){this.dict=e||{}}return n.prototype.all=function(){return this.dict},n.prototype.get=function(e){return this.dict[e]},n.prototype.extend=function(t){this.dict=e.extend({},t.all(),this.dict)},n._cache={},n.loadPath=function(e){if(!(e in n._cache)){var i=t(e);n._cache[e]=i}return new n(n._cache[e])},n}),n.define("ppma_select2/diacritics",[],function(){return{"Ⓐ":"A",A:"A",À:"A",Á:"A",Â:"A",Ầ:"A",Ấ:"A",Ẫ:"A",Ẩ:"A",Ã:"A",Ā:"A",Ă:"A",Ằ:"A",Ắ:"A",Ẵ:"A",Ẳ:"A",Ȧ:"A",Ǡ:"A",Ä:"A",Ǟ:"A",Ả:"A",Å:"A",Ǻ:"A",Ǎ:"A",Ȁ:"A",Ȃ:"A",Ạ:"A",Ậ:"A",Ặ:"A",Ḁ:"A",Ą:"A",Ⱥ:"A",Ɐ:"A",Ꜳ:"AA",Æ:"AE",Ǽ:"AE",Ǣ:"AE",Ꜵ:"AO",Ꜷ:"AU",Ꜹ:"AV",Ꜻ:"AV",Ꜽ:"AY","Ⓑ":"B",B:"B",Ḃ:"B",Ḅ:"B",Ḇ:"B",Ƀ:"B",Ƃ:"B",Ɓ:"B","Ⓒ":"C",C:"C",Ć:"C",Ĉ:"C",Ċ:"C",Č:"C",Ç:"C",Ḉ:"C",Ƈ:"C",Ȼ:"C",Ꜿ:"C","Ⓓ":"D",D:"D",Ḋ:"D",Ď:"D",Ḍ:"D",Ḑ:"D",Ḓ:"D",Ḏ:"D",Đ:"D",Ƌ:"D",Ɗ:"D",Ɖ:"D",Ꝺ:"D",DZ:"DZ",DŽ:"DZ",Dz:"Dz",Dž:"Dz","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["../utils"],function(e){function t(e,n){t.__super__.constructor.call(this)}return e.Extend(t,e.Observable),t.prototype.current=function(e){throw Error("The `current` method must be defined in child classes.")},t.prototype.query=function(e,t){throw Error("The `query` method must be defined in child classes.")},t.prototype.bind=function(e,t){},t.prototype.destroy=function(){},t.prototype.generateResultId=function(t,n){var i=t.id+"-result-";return i+=e.generateChars(4),null!=n.id?i+="-"+n.id.toString():i+="-"+e.generateChars(4),i},t}),n.define("ppma_select2/data/select",["./base","../utils","jquery"],function(e,t,n){function i(e,t){this.$element=e,this.options=t,i.__super__.constructor.call(this)}return t.Extend(i,e),i.prototype.current=function(e){var t=[],i=this;this.$element.find(":selected").each(function(){var e=n(this),r=i.item(e);t.push(r)}),e(t)},i.prototype.select=function(e){var t=this;if(e.selected=!0,n(e.element).is("option")){e.element.selected=!0,this.$element.trigger("input").trigger("change");return}if(this.$element.prop("multiple"))this.current(function(i){var r=[];(e=[e]).push.apply(e,i);for(var s=0;s=0){var u=r.filter(a(c)),p=this.item(u),d=n.extend(!0,{},c,p),h=this.option(d);u.replaceWith(h);continue}var f=this.option(c);if(c.children){var m=this.convertToOptions(c.children);t.appendMany(f,m)}o.push(f)}return o},i}),n.define("ppma_select2/data/ajax",["./array","../utils","jquery"],function(e,t,n){function i(e,t){this.ajaxOptions=this._applyDefaults(t.get("ajax")),null!=this.ajaxOptions.processResults&&(this.processResults=this.ajaxOptions.processResults),i.__super__.constructor.call(this,e,t)}return t.Extend(i,e),i.prototype._applyDefaults=function(e){return n.extend({},{data:function(e){return n.extend({},e,{q:e.term})},transport:function(e,t,i){var r=n.ajax(e);return r.then(t),r.fail(i),r}},e,!0)},i.prototype.processResults=function(e){return e},i.prototype.query=function(e,t){var i=this;null!=this._request&&(n.isFunction(this._request.abort)&&this._request.abort(),this._request=null);var r=n.extend({type:"GET"},this.ajaxOptions);function s(){var s=r.transport(r,function(r){var s=i.processResults(r,e);i.options.get("debug")&&window.console&&console.error&&(!s||!s.results||!n.isArray(s.results))&&console.error("PPMA_Select2: The AJAX results did not return an array in the `results` key of the response."),t(s)},function(){(!("status"in s)||0!==s.status&&"0"!==s.status)&&i.trigger("results:message",{message:"errorLoading"})});i._request=s}"function"==typeof r.url&&(r.url=r.url.call(this.$element,e)),"function"==typeof r.data&&(r.data=r.data.call(this.$element,e)),this.ajaxOptions.delay&&null!=e.term?(this._queryTimeout&&window.clearTimeout(this._queryTimeout),this._queryTimeout=window.setTimeout(s,this.ajaxOptions.delay)):s()},i}),n.define("ppma_select2/data/tags",["jquery"],function(e){function t(t,n,i){var r=i.get("tags"),s=i.get("createTag");void 0!==s&&(this.createTag=s);var o=i.get("insertTag");if(void 0!==o&&(this.insertTag=o),t.call(this,n,i),e.isArray(r))for(var a=0;a0&&t.term.length>this.maximumInputLength){this.trigger("results:message",{message:"inputTooLong",args:{maximum:this.maximumInputLength,input:t.term,params:t}});return}e.call(this,t,n)},e}),n.define("ppma_select2/data/maximumSelectionLength",[],function(){function e(e,t,n){this.maximumSelectionLength=n.get("maximumSelectionLength"),e.call(this,t,n)}return e.prototype.bind=function(e,t,n){var i=this;e.call(this,t,n),t.on("select",function(){i._checkIfMaximumSelected()})},e.prototype.query=function(e,t,n){var i=this;this._checkIfMaximumSelected(function(){e.call(i,t,n)})},e.prototype._checkIfMaximumSelected=function(e,t){var n=this;this.current(function(e){var i=null!=e?e.length:0;if(n.maximumSelectionLength>0&&i>=n.maximumSelectionLength){n.trigger("results:message",{message:"maximumSelected",args:{maximum:n.maximumSelectionLength}});return}t&&t()})},e}),n.define("ppma_select2/dropdown",["jquery","./utils"],function(e,t){function n(e,t){this.$element=e,this.options=t,n.__super__.constructor.call(this)}return t.Extend(n,t.Observable),n.prototype.render=function(){var t=e('');return t.attr("dir",this.options.get("dir")),this.$dropdown=t,t},n.prototype.bind=function(){},n.prototype.position=function(e,t){},n.prototype.destroy=function(){this.$dropdown.remove()},n}),n.define("ppma_select2/dropdown/search",["jquery","../utils"],function(e,t){function n(){}return n.prototype.render=function(t){var n=t.call(this),i=e('');return this.$searchContainer=i,this.$search=i.find("input"),n.prepend(i),n},n.prototype.bind=function(t,n,i){var r=this,s=n.id+"-results";t.call(this,n,i),this.$search.on("keydown",function(e){r.trigger("keypress",e),r._keyUpPrevented=e.isDefaultPrevented()}),this.$search.on("input",function(t){e(this).off("keyup")}),this.$search.on("keyup input",function(e){r.handleSearch(e)}),n.on("open",function(){r.$search.attr("tabindex",0),r.$search.attr("aria-controls",s),r.$search.trigger("focus"),window.setTimeout(function(){r.$search.trigger("focus")},0)}),n.on("close",function(){r.$search.attr("tabindex",-1),r.$search.removeAttr("aria-controls"),r.$search.removeAttr("aria-activedescendant"),r.$search.val(""),r.$search.trigger("blur")}),n.on("focus",function(){n.isOpen()||r.$search.trigger("focus")}),n.on("results:all",function(e){(null==e.query.term||""===e.query.term)&&(r.showSearch(e)?r.$searchContainer.removeClass("ppma_select2-search--hide"):r.$searchContainer.addClass("ppma_select2-search--hide"))}),n.on("results:focus",function(e){e.data._resultId?r.$search.attr("aria-activedescendant",e.data._resultId):r.$search.removeAttr("aria-activedescendant")})},n.prototype.handleSearch=function(e){if(!this._keyUpPrevented){var t=this.$search.val();this.trigger("query",{term:t})}this._keyUpPrevented=!1},n.prototype.showSearch=function(e,t){return!0},n}),n.define("ppma_select2/dropdown/hidePlaceholder",[],function(){function e(e,t,n,i){this.placeholder=this.normalizePlaceholder(n.get("placeholder")),e.call(this,t,n,i)}return e.prototype.append=function(e,t){t.results=this.removePlaceholder(t.results),e.call(this,t)},e.prototype.normalizePlaceholder=function(e,t){return"string"==typeof t&&(t={id:"",text:t}),t},e.prototype.removePlaceholder=function(e,t){for(var n=t.slice(0),i=t.length-1;i>=0;i--){var r=t[i];this.placeholder.id===r.id&&n.splice(i,1)}return n},e}),n.define("ppma_select2/dropdown/infiniteScroll",["jquery"],function(e){function t(e,t,n,i){this.lastParams={},e.call(this,t,n,i),this.$loadingMore=this.createLoadingMore(),this.loading=!1}return t.prototype.append=function(e,t){this.$loadingMore.remove(),this.loading=!1,e.call(this,t),this.showLoadingMore(t)&&(this.$results.append(this.$loadingMore),this.loadMoreIfNeeded())},t.prototype.bind=function(e,t,n){var i=this;e.call(this,t,n),t.on("query",function(e){i.lastParams=e,i.loading=!0}),t.on("query:append",function(e){i.lastParams=e,i.loading=!0}),this.$results.on("scroll",this.loadMoreIfNeeded.bind(this))},t.prototype.loadMoreIfNeeded=function(){var t,n=e.contains(document.documentElement,this.$loadingMore[0]);if(!this.loading&&n){this.$results.offset().top+this.$results.outerHeight(!1)+50>=this.$loadingMore.offset().top+this.$loadingMore.outerHeight(!1)&&this.loadMore()}},t.prototype.loadMore=function(){this.loading=!0;var t=e.extend({},{page:1},this.lastParams);t.page++,this.trigger("query:append",t)},t.prototype.showLoadingMore=function(e,t){return t.pagination&&t.pagination.more},t.prototype.createLoadingMore=function(){var t=e('
    • '),n=this.options.get("translations").get("loadingMore");return t.html(n(this.lastParams)),t},t}),n.define("ppma_select2/dropdown/attachBody",["jquery","../utils"],function(e,t){function n(t,n,i){this.$dropdownParent=e(i.get("dropdownParent")||document.body),t.call(this,n,i)}return n.prototype.bind=function(e,t,n){var i=this;e.call(this,t,n),t.on("open",function(){i._showDropdown(),i._attachPositioningHandler(t),i._bindContainerResultHandlers(t)}),t.on("close",function(){i._hideDropdown(),i._detachPositioningHandler(t)}),this.$dropdownContainer.on("mousedown",function(e){e.stopPropagation()})},n.prototype.destroy=function(e){e.call(this),this.$dropdownContainer.remove()},n.prototype.position=function(e,t,n){t.attr("class",n.attr("class")),t.removeClass("ppma_select2"),t.addClass("ppma_select2-container--open"),t.css({position:"absolute",top:-999999}),this.$container=n},n.prototype.render=function(t){var n=e(""),i=t.call(this);return n.append(i),this.$dropdownContainer=n,n},n.prototype._hideDropdown=function(e){this.$dropdownContainer.detach()},n.prototype._bindContainerResultHandlers=function(e,t){if(!this._containerResultsHandlersBound){var n=this;t.on("results:all",function(){n._positionDropdown(),n._resizeDropdown()}),t.on("results:append",function(){n._positionDropdown(),n._resizeDropdown()}),t.on("results:message",function(){n._positionDropdown(),n._resizeDropdown()}),t.on("select",function(){n._positionDropdown(),n._resizeDropdown()}),t.on("unselect",function(){n._positionDropdown(),n._resizeDropdown()}),this._containerResultsHandlersBound=!0}},n.prototype._attachPositioningHandler=function(n,i){var r=this,s="scroll.ppma_select2."+i.id,o="resize.ppma_select2."+i.id,a="orientationchange.ppma_select2."+i.id,l=this.$container.parents().filter(t.hasScroll);l.each(function(){t.StoreData(this,"ppma_select2-scroll-position",{x:e(this).scrollLeft(),y:e(this).scrollTop()})}),l.on(s,function(n){var i=t.GetData(this,"ppma_select2-scroll-position");e(this).scrollTop(i.y)}),e(window).on(s+" "+o+" "+a,function(e){r._positionDropdown(),r._resizeDropdown()})},n.prototype._detachPositioningHandler=function(n,i){var r="scroll.ppma_select2."+i.id,s="resize.ppma_select2."+i.id,o="orientationchange.ppma_select2."+i.id;this.$container.parents().filter(t.hasScroll).off(r),e(window).off(r+" "+s+" "+o)},n.prototype._positionDropdown=function(){var t=e(window),n=this.$dropdown.hasClass("ppma_select2-dropdown--above"),i=this.$dropdown.hasClass("ppma_select2-dropdown--below"),r=null,s=this.$container.offset();s.bottom=s.top+this.$container.outerHeight(!1);var o={height:this.$container.outerHeight(!1)};o.top=s.top,o.bottom=s.top+o.height;var a={height:this.$dropdown.outerHeight(!1)},l={top:t.scrollTop(),bottom:t.scrollTop()+t.height()},c=l.tops.bottom+a.height,p={left:s.left,top:o.bottom},d=this.$dropdownParent;"static"===d.css("position")&&(d=d.offsetParent());var h={top:0,left:0};(e.contains(document.body,d[0])||d[0].isConnected)&&(h=d.offset()),p.top-=h.top,p.left-=h.left,n||i||(r="below"),u||!c||n?!c&&u&&n&&(r="below"):r="above",("above"==r||n&&"below"!==r)&&(p.top=o.top-h.top-a.height),null!=r&&(this.$dropdown.removeClass("ppma_select2-dropdown--below ppma_select2-dropdown--above").addClass("ppma_select2-dropdown--"+r),this.$container.removeClass("ppma_select2-container--below ppma_select2-container--above").addClass("ppma_select2-container--"+r)),this.$dropdownContainer.css(p)},n.prototype._resizeDropdown=function(){var e={width:this.$container.outerWidth(!1)+"px"};this.options.get("dropdownAutoWidth")&&(e.minWidth=e.width,e.position="relative",e.width="auto"),this.$dropdown.css(e)},n.prototype._showDropdown=function(e){this.$dropdownContainer.appendTo(this.$dropdownParent),this._positionDropdown(),this._resizeDropdown()},n}),n.define("ppma_select2/dropdown/minimumResultsForSearch",[],function(){function e(e,t,n,i){this.minimumResultsForSearch=n.get("minimumResultsForSearch"),this.minimumResultsForSearch<0&&(this.minimumResultsForSearch=1/0),e.call(this,t,n,i)}return e.prototype.showSearch=function(e,t){return!(function e(t){for(var n=0,i=0;i0&&(u.dataAdapter=c.Decorate(u.dataAdapter,v)),u.maximumInputLength>0&&(u.dataAdapter=c.Decorate(u.dataAdapter,y)),u.maximumSelectionLength>0&&(u.dataAdapter=c.Decorate(u.dataAdapter,b)),u.tags&&(u.dataAdapter=c.Decorate(u.dataAdapter,m)),(null!=u.tokenSeparators||null!=u.tokenizer)&&(u.dataAdapter=c.Decorate(u.dataAdapter,g)),null!=u.query){var p=t(u.amdBase+"compat/query");u.dataAdapter=c.Decorate(u.dataAdapter,p)}if(null!=u.initSelection){var O=t(u.amdBase+"compat/initSelection");u.dataAdapter=c.Decorate(u.dataAdapter,O)}}if(null==u.resultsAdapter&&(u.resultsAdapter=n,null!=u.ajax&&(u.resultsAdapter=c.Decorate(u.resultsAdapter,x)),null!=u.placeholder&&(u.resultsAdapter=c.Decorate(u.resultsAdapter,D)),u.selectOnClose&&(u.resultsAdapter=c.Decorate(u.resultsAdapter,E))),null==u.dropdownAdapter){if(u.multiple)u.dropdownAdapter=w;else{var P=c.Decorate(w,A);u.dropdownAdapter=P}if(0!==u.minimumResultsForSearch&&(u.dropdownAdapter=c.Decorate(u.dropdownAdapter,S)),u.closeOnSelect&&(u.dropdownAdapter=c.Decorate(u.dropdownAdapter,_)),null!=u.dropdownCssClass||null!=u.dropdownCss||null!=u.adaptDropdownCssClass){var q=t(u.amdBase+"compat/dropdownCss");u.dropdownAdapter=c.Decorate(u.dropdownAdapter,q)}u.dropdownAdapter=c.Decorate(u.dropdownAdapter,C)}if(null==u.selectionAdapter){if(u.multiple?u.selectionAdapter=r:u.selectionAdapter=i,null!=u.placeholder&&(u.selectionAdapter=c.Decorate(u.selectionAdapter,s)),u.allowClear&&(u.selectionAdapter=c.Decorate(u.selectionAdapter,o)),u.multiple&&(u.selectionAdapter=c.Decorate(u.selectionAdapter,a)),null!=u.containerCssClass||null!=u.containerCss||null!=u.adaptContainerCssClass){var T=t(u.amdBase+"compat/containerCss");u.selectionAdapter=c.Decorate(u.selectionAdapter,T)}u.selectionAdapter=c.Decorate(u.selectionAdapter,l)}u.language=this._resolveLanguage(u.language),u.language.push("en");for(var M=[],L=0;L0){for(var s=e.extend(!0,{},r),o=r.children.length-1;o>=0;o--)null==n(i,r.children[o])&&s.children.splice(o,1);return s.children.length>0?s:n(i,s)}var a=t(r.text).toUpperCase(),l=t(i.term).toUpperCase();return a.indexOf(l)>-1?r:null},minimumInputLength:0,maximumInputLength:0,maximumSelectionLength:0,minimumResultsForSearch:0,selectOnClose:!1,scrollAfterSelect:!1,sorter:function(e){return e},templateResult:function(e){return e.text},templateSelection:function(e){return e.text},theme:"default",width:"resolve"}},P.prototype.applyFromElement=function(e,t){var n=e.language,i=this.defaults.language,r=t.prop("lang"),s=t.closest("[lang]").prop("lang"),o=Array.prototype.concat.call(this._resolveLanguage(r),this._resolveLanguage(n),this._resolveLanguage(i),this._resolveLanguage(s));return e.language=o,e},P.prototype._resolveLanguage=function(t){if(!t||e.isEmptyObject(t))return[];if(e.isPlainObject(t))return[t];n=e.isArray(t)?t:[t];for(var n,i=[],r=0;r0){var s=n[r].split("-")[0];i.push(s)}return i},P.prototype._processTranslations=function(t,n){for(var i=new u,r=0;r-1)&&(t.isPlainObject(this.options[d])?t.extend(this.options[d],p[d]):this.options[d]=p[d]);return this},r.prototype.get=function(e){return this.options[e]},r.prototype.set=function(e,t){this.options[e]=t},r}),n.define("ppma_select2/core",["jquery","./options","./utils","./keys"],function(e,t,n,i){var r=function(e,i){null!=n.GetData(e[0],"ppma_select2")&&n.GetData(e[0],"ppma_select2").destroy(),this.$element=e,this.id=this._generateId(e),i=i||{},this.options=new t(i,e),r.__super__.constructor.call(this);var s=e.attr("tabindex")||0;n.StoreData(e[0],"old-tabindex",s),e.attr("tabindex","-1");var o=this.options.get("dataAdapter");this.dataAdapter=new o(e,this.options);var a=this.render();this._placeContainer(a);var l=this.options.get("selectionAdapter");this.selection=new l(e,this.options),this.$selection=this.selection.render(),this.selection.position(this.$selection,a);var c=this.options.get("dropdownAdapter");this.dropdown=new c(e,this.options),this.$dropdown=this.dropdown.render(),this.dropdown.position(this.$dropdown,a);var u=this.options.get("resultsAdapter");this.results=new u(e,this.options,this.dataAdapter),this.$results=this.results.render(),this.results.position(this.$results,this.$dropdown);var p=this;this._bindAdapters(),this._registerDomEvents(),this._registerDataEvents(),this._registerSelectionEvents(),this._registerDropdownEvents(),this._registerResultsEvents(),this._registerEvents(),this.dataAdapter.current(function(e){p.trigger("selection:update",{data:e})}),e.addClass("ppma_select2-hidden-accessible"),e.attr("aria-hidden","true"),this._syncAttributes(),n.StoreData(e[0],"ppma_select2",this),e.data("ppma_select2",this)};return n.Extend(r,n.Observable),r.prototype._generateId=function(e){var t="";return"ppma_select2-"+(t=(t=null!=e.attr("id")?e.attr("id"):null!=e.attr("name")?e.attr("name")+"-"+n.generateChars(2):n.generateChars(4)).replace(/(:|\.|\[|\]|,)/g,""))},r.prototype._placeContainer=function(e){e.insertAfter(this.$element);var t=this._resolveWidth(this.$element,this.options.get("width"));null!=t&&e.css("width",t)},r.prototype._resolveWidth=function(e,t){var n=/^width:(([-+]?([0-9]*\.)?[0-9]+)(px|em|ex|%|in|cm|mm|pt|pc))/i;if("resolve"==t){var i=this._resolveWidth(e,"style");return null!=i?i:this._resolveWidth(e,"element")}if("element"==t){var r=e.outerWidth(!1);return r<=0?"auto":r+"px"}if("style"==t){var s=e.attr("style");if("string"!=typeof s)return null;for(var o=s.split(";"),a=0,l=o.length;a=1)return c[1]}return null}return"computedstyle"==t?window.getComputedStyle(e[0]).width:t},r.prototype._bindAdapters=function(){this.dataAdapter.bind(this,this.$container),this.selection.bind(this,this.$container),this.dropdown.bind(this,this.$container),this.results.bind(this,this.$container)},r.prototype._registerDomEvents=function(){var e=this;this.$element.on("change.ppma_select2",function(){e.dataAdapter.current(function(t){e.trigger("selection:update",{data:t})})}),this.$element.on("focus.ppma_select2",function(t){e.trigger("focus",t)}),this._syncA=n.bind(this._syncAttributes,this),this._syncS=n.bind(this._syncSubtree,this),this.$element[0].attachEvent&&this.$element[0].attachEvent("onpropertychange",this._syncA);var t=window.MutationObserver||window.WebKitMutationObserver||window.MozMutationObserver;null!=t?(this._observer=new t(function(t){e._syncA(),e._syncS(null,t)}),this._observer.observe(this.$element[0],{attributes:!0,childList:!0,subtree:!1})):this.$element[0].addEventListener&&(this.$element[0].addEventListener("DOMAttrModified",e._syncA,!1),this.$element[0].addEventListener("DOMNodeInserted",e._syncS,!1),this.$element[0].addEventListener("DOMNodeRemoved",e._syncS,!1))},r.prototype._registerDataEvents=function(){var e=this;this.dataAdapter.on("*",function(t,n){e.trigger(t,n)})},r.prototype._registerSelectionEvents=function(){var t=this,n=["toggle","focus"];this.selection.on("toggle",function(){t.toggleDropdown()}),this.selection.on("focus",function(e){t.focus(e)}),this.selection.on("*",function(i,r){-1===e.inArray(i,n)&&t.trigger(i,r)})},r.prototype._registerDropdownEvents=function(){var e=this;this.dropdown.on("*",function(t,n){e.trigger(t,n)})},r.prototype._registerResultsEvents=function(){var e=this;this.results.on("*",function(t,n){e.trigger(t,n)})},r.prototype._registerEvents=function(){var e=this;this.on("open",function(){e.$container.addClass("ppma_select2-container--open")}),this.on("close",function(){e.$container.removeClass("ppma_select2-container--open")}),this.on("enable",function(){e.$container.removeClass("ppma_select2-container--disabled")}),this.on("disable",function(){e.$container.addClass("ppma_select2-container--disabled")}),this.on("blur",function(){e.$container.removeClass("ppma_select2-container--focus")}),this.on("query",function(t){e.isOpen()||e.trigger("open",{}),this.dataAdapter.query(t,function(n){e.trigger("results:all",{data:n,query:t})})}),this.on("query:append",function(t){this.dataAdapter.query(t,function(n){e.trigger("results:append",{data:n,query:t})})}),this.on("keypress",function(t){var n=t.which;e.isOpen()?n===i.ESC||n===i.TAB||n===i.UP&&t.altKey?(e.close(t),t.preventDefault()):n===i.ENTER?(e.trigger("results:select",{}),t.preventDefault()):n===i.SPACE&&t.ctrlKey?(e.trigger("results:toggle",{}),t.preventDefault()):n===i.UP?(e.trigger("results:previous",{}),t.preventDefault()):n===i.DOWN&&(e.trigger("results:next",{}),t.preventDefault()):(n===i.ENTER||n===i.SPACE||n===i.DOWN&&t.altKey)&&(e.open(),t.preventDefault())})},r.prototype._syncAttributes=function(){this.options.set("disabled",this.$element.prop("disabled")),this.isDisabled()?(this.isOpen()&&this.close(),this.trigger("disable",{})):this.trigger("enable",{})},r.prototype._isChangeMutation=function(t,n){var i=!1,r=this;if(!t||!t.target||"OPTION"===t.target.nodeName||"OPTGROUP"===t.target.nodeName){if(n){if(n.addedNodes&&n.addedNodes.length>0)for(var s=0;s0?i=!0:e.isArray(n)&&e.each(n,function(e,t){if(r._isChangeMutation(e,t))return i=!0,!1})}else i=!0;return i}},r.prototype._syncSubtree=function(e,t){var n=this._isChangeMutation(e,t),i=this;n&&this.dataAdapter.current(function(e){i.trigger("selection:update",{data:e})})},r.prototype.trigger=function(e,t){var n=r.__super__.trigger,i={open:"opening",close:"closing",select:"selecting",unselect:"unselecting",clear:"clearing"};if(void 0===t&&(t={}),e in i){var s=i[e],o={prevented:!1,name:e,args:t};if(n.call(this,s,o),o.prevented){t.prevented=!0;return}}n.call(this,e,t)},r.prototype.toggleDropdown=function(){!this.isDisabled()&&(this.isOpen()?this.close():this.open())},r.prototype.open=function(){!(this.isOpen()||this.isDisabled())&&this.trigger("query",{})},r.prototype.close=function(e){this.isOpen()&&this.trigger("close",{originalEvent:e})},r.prototype.isEnabled=function(){return!this.isDisabled()},r.prototype.isDisabled=function(){return this.options.get("disabled")},r.prototype.isOpen=function(){return this.$container.hasClass("ppma_select2-container--open")},r.prototype.hasFocus=function(){return this.$container.hasClass("ppma_select2-container--focus")},r.prototype.focus=function(e){!this.hasFocus()&&(this.$container.addClass("ppma_select2-container--focus"),this.trigger("focus",{}))},r.prototype.enable=function(e){this.options.get("debug")&&window.console&&console.warn&&console.warn('PPMA_Select2: The `ppma_select2("enable")` method has been deprecated and will be removed in later PPMA_Select2 versions. Use $element.prop("disabled") instead.'),(null==e||0===e.length)&&(e=[!0]);var t=!e[0];this.$element.prop("disabled",t)},r.prototype.data=function(){this.options.get("debug")&&arguments.length>0&&window.console&&console.warn&&console.warn('PPMA_Select2: Data can no longer be set using `ppma_select2("data")`. You should consider setting the value instead using `$element.val()`.');var e=[];return this.dataAdapter.current(function(t){e=t}),e},r.prototype.val=function(t){if(this.options.get("debug")&&window.console&&console.warn&&console.warn('PPMA_Select2: The `ppma_select2("val")` method has been deprecated and will be removed in later PPMA_Select2 versions. Use $element.val() instead.'),null==t||0===t.length)return this.$element.val();var n=t[0];e.isArray(n)&&(n=e.map(n,function(e){return e.toString()})),this.$element.val(n).trigger("input").trigger("change")},r.prototype.destroy=function(){this.$container.remove(),this.$element[0].detachEvent&&this.$element[0].detachEvent("onpropertychange",this._syncA),null!=this._observer?(this._observer.disconnect(),this._observer=null):this.$element[0].removeEventListener&&(this.$element[0].removeEventListener("DOMAttrModified",this._syncA,!1),this.$element[0].removeEventListener("DOMNodeInserted",this._syncS,!1),this.$element[0].removeEventListener("DOMNodeRemoved",this._syncS,!1)),this._syncA=null,this._syncS=null,this.$element.off(".ppma_select2"),this.$element.attr("tabindex",n.GetData(this.$element[0],"old-tabindex")),this.$element.removeClass("ppma_select2-hidden-accessible"),this.$element.attr("aria-hidden","false"),n.RemoveData(this.$element[0]),this.$element.removeData("ppma_select2"),this.dataAdapter.destroy(),this.selection.destroy(),this.dropdown.destroy(),this.results.destroy(),this.dataAdapter=null,this.selection=null,this.dropdown=null,this.results=null},r.prototype.render=function(){var t=e('');return t.attr("dir",this.options.get("dir")),this.$container=t,this.$container.addClass("ppma_select2-container--"+this.options.get("theme")),n.StoreData(t[0],"element",this.$element),t},r}),n.define("ppma_select2/compat/utils",["jquery"],function(e){return{syncCssClasses:function t(n,i,r){var s,o,a=[];(s=e.trim(n.attr("class")))&&e((s=""+s).split(/\s+/)).each(function(){0===this.indexOf("ppma_select2-")&&a.push(this)}),(s=e.trim(i.attr("class")))&&e((s=""+s).split(/\s+/)).each(function(){0!==this.indexOf("ppma_select2-")&&null!=(o=r(this))&&a.push(o)}),n.attr("class",a.join(" "))}}}),n.define("ppma_select2/compat/containerCss",["jquery","./utils"],function(e,t){function n(e){return null}function i(){}return i.prototype.render=function(i){var r=i.call(this),s=this.options.get("containerCssClass")||"";e.isFunction(s)&&(s=s(this.$element));var o=this.options.get("adaptContainerCssClass");if(o=o||n,-1!==s.indexOf(":all:")){s=s.replace(":all:","");var a=o;o=function(e){var t=a(e);return null!=t?t+" "+e:e}}var l=this.options.get("containerCss")||{};return e.isFunction(l)&&(l=l(this.$element)),t.syncCssClasses(r,this.$element,o),r.css(l),r.addClass(s),r},i}),n.define("ppma_select2/compat/dropdownCss",["jquery","./utils"],function(e,t){function n(e){return null}function i(){}return i.prototype.render=function(i){var r=i.call(this),s=this.options.get("dropdownCssClass")||"";e.isFunction(s)&&(s=s(this.$element));var o=this.options.get("adaptDropdownCssClass");if(o=o||n,-1!==s.indexOf(":all:")){s=s.replace(":all:","");var a=o;o=function(e){var t=a(e);return null!=t?t+" "+e:e}}var l=this.options.get("dropdownCss")||{};return e.isFunction(l)&&(l=l(this.$element)),t.syncCssClasses(r,this.$element,o),r.css(l),r.addClass(s),r},i}),n.define("ppma_select2/compat/initSelection",["jquery"],function(e){function t(e,t,n){n.get("debug")&&window.console&&console.warn&&console.warn("PPMA_Select2: The `initSelection` option has been deprecated in favor of a custom data adapter that overrides the `current` method. This method is now called multiple times instead of a single time when the instance is initialized. Support will be removed for the `initSelection` option in future versions of PPMA_Select2"),this.initSelection=n.get("initSelection"),this._isInitialized=!1,e.call(this,t,n)}return t.prototype.current=function(t,n){var i=this;if(this._isInitialized){t.call(this,n);return}this.initSelection.call(null,this.$element,function(t){i._isInitialized=!0,e.isArray(t)||(t=[t]),n(t)})},t}),n.define("ppma_select2/compat/inputData",["jquery","../utils"],function(e,t){function n(e,t,n){this._currentData=[],this._valueSeparator=n.get("valueSeparator")||",","hidden"===t.prop("type")&&n.get("debug")&&console&&console.warn&&console.warn("PPMA_Select2: Using a hidden input with PPMA_Select2 is no longer supported and may stop working in the future. It is recommended to use a `', list: [ 'blockquote', 'h2', 'h3', 'p', 'code', 'insertOrderedList', 'insertUnorderedList', 'inserthorizontalrule', 'indent', 'outdent', 'bold', 'italic', 'underline', 'createlink', 'insertimage' ], titles: {}, cleanAttrs: ['id', 'class', 'style', 'name'], cleanTags: ['script'], linksInNewWindow: false }; // user-friendly config if (config.nodeType === 1) { defaults.editor = config; } else if (config.match && config.match(/^#[\S]+$/)) { defaults.editor = doc.getElementById(config.slice(1)); } else { defaults = utils.copy(defaults, config); } return defaults; }; function commandOverall(cmd, val) { var message = ' to exec 「' + cmd + '」 command' + (val ? (' with value: ' + val) : ''); try { doc.execCommand(cmd, false, val); } catch(err) { // TODO: there's an error when insert a image to document, but not a bug return utils.log('fail' + message, true); } utils.log('success' + message); } function commandInsert(ctx, name, val) { var node = getNode(ctx); if (!node) return; ctx._range.selectNode(node); ctx._range.collapse(false); // hide menu when a image was inserted if(name === 'insertimage' && ctx._menu) toggleNode(ctx._menu, true); return commandOverall(name, val); } function commandBlock(ctx, name) { var effectNodes = getEffectNodes(ctx), tagsList = effectNodes.map(function(node) { return node.nodeName.toLowerCase(); }); if (tagsList.indexOf(name) !== -1) name = 'p'; return commandOverall('formatblock', name); } function commandWrap(ctx, tag, value) { value = '<' + tag + '>' + (value||selection.toString()) + ''; return commandOverall('insertHTML', value); } function commandLink(ctx, tag, value) { if (ctx.config.linksInNewWindow && 'unlink' !== tag) { value = '' + (selection.toString()) + ''; return commandOverall('insertHTML', value); } else { return commandOverall(tag, value); } } function createTool(ctx, name, type, group) { var title = ctx.config.titles[name] || '', iconElement = document.createElement( 'div' ); iconElement.classList.add('pen-icon'); iconElement.setAttribute('title', title); if ('parent' === type) { iconElement.classList.add('pen-group-icon'); iconElement.setAttribute('data-group-toggle', name); } else { iconElement.setAttribute('data-action', name); } if('child' === type) { iconElement.setAttribute('data-group', group); } var iconDictionary = ctx.config.toolbarIconsDictionary[ name ]; if ( iconDictionary && iconDictionary.text ) { iconElement.textContent = iconDictionary.text; } else { var iconClass; if ( iconDictionary && iconDictionary.className ) { iconClass = iconDictionary.className; } else { iconClass = ctx.config.toolbarIconsPrefix + name; } iconElement.innerHTML += ''; } return iconElement.outerHTML; } function getMenuTools(ctx) { return slice.call(ctx._menu.children); } function activateGroup(ctx, group) { var tools = getMenuTools(ctx); tools.forEach(function(tool) { toggleNode(tool, tool.getAttribute('data-group') !== group); }); toggleMenuClose(ctx, ! group); ctx.refreshMenuPosition(); } function showMainMenu(ctx) { activateGroup(ctx, null); toggleLinkInput(ctx, true); toggleUnlinkTool(ctx, !ctx._urlInput || ctx._urlInput.value === ''); } function showLinkInput(ctx) { var tools = getMenuTools(ctx); tools.forEach(function(tool) { toggleNode(tool, true); }); toggleLinkInput(ctx); toggleMenuClose(ctx); } function toggleLinkInput(ctx, hide) { var linkInput = ctx._menu.querySelector('.pen-input-wrapper'); if (! linkInput) { return; } toggleNode(linkInput, hide); } function toggleUnlinkTool(ctx, hide) { var unlinkTool = ctx._menu.querySelector('[data-action="unlink"]'); if (! unlinkTool) { return; } toggleNode(unlinkTool, hide); ctx.refreshMenuPosition(); } function toggleMenuClose(ctx, hide) { var closeButton = ctx._menu.querySelector('[data-action="close"]'); toggleNode(closeButton, hide); ctx.refreshMenuPosition(); } function createLinkInput(ctx) { var inputWrapper = doc.createElement('div'), urlInput = doc.createElement('input'), newWindowLabel = doc.createElement('label'), newWindowCheckbox = doc.createElement('input'), newWindowIcon = doc.createElement('i'); inputWrapper.className = 'pen-input-wrapper'; urlInput.className = 'pen-url-input'; urlInput.type = 'url'; urlInput.placeholder = 'http://'; newWindowLabel.className = 'pen-icon pen-input-label'; newWindowCheckbox.className = 'pen-external-url-checkbox'; newWindowCheckbox.type = 'checkbox'; newWindowIcon.className = ctx.config.toolbarIconsDictionary.externalLink.className; newWindowLabel.appendChild(newWindowCheckbox); newWindowLabel.appendChild(newWindowIcon); inputWrapper.appendChild(urlInput); inputWrapper.appendChild(newWindowLabel); return inputWrapper; } function menuApply(ctx, action, value) { ctx.execCommand(action, value); ctx._range = ctx.getRange(); ctx.highlight().menu(); } function onToolbarClick(ctx, target) { var toolbar = ctx._toolbar || ctx._menu, action; while (!(action = target.getAttribute('data-action'))) { if (target.parentNode === toolbar) { break; } target = target.parentNode; } var groupToggle = target.getAttribute('data-group-toggle'); if (groupToggle) { activateGroup(ctx, groupToggle); } if (!action) return; if ('close' === action) { showMainMenu(ctx); return; } if (!/(?:createlink)|(?:insertimage)/.test(action)) return menuApply(ctx, action); if (!ctx._urlInput) return; // create link var input = ctx._urlInput; if (toolbar === ctx._menu) showLinkInput(ctx); else { ctx._inputActive = true; ctx.menu(); } if (ctx._menu.style.display === 'none') return; setTimeout(function() { input.focus(); }, 10); var createLink = function() { var inputValue = input.value; if (inputValue) { ctx.config.linksInNewWindow = ctx._externalUrlCheckbox.checked; inputValue = input.value .replace(strReg.whiteSpace, '') .replace(strReg.mailTo, 'mailto:$1') .replace(strReg.http, 'http://$1'); } else { action = 'unlink'; } menuApply(ctx, action, inputValue); }; input.onkeypress = function(e) { if (e.which === 13) { e.preventDefault(); createLink() } }; ctx._externalUrlCheckbox.onchange = createLink; } function initToolbar(ctx) { var icons = '', inputStr = createLinkInput(ctx).outerHTML; ctx._toolbar = ctx.config.toolbar; if (!ctx._toolbar) { var toolList = ctx.config.list; if (! Object.values(toolList).length) { return; } utils.forEach(toolList, function (name, key) { if (Array.isArray(name)) { var children = name; name = key; icons += createTool(ctx, name, 'parent'); utils.forEach(children, function(childName) { icons += createTool(ctx, childName, 'child', name); }, true); } else { icons += createTool(ctx, name); } }); var toolListValues = Object.values(toolList); if (toolListValues.indexOf('createlink') >= 0 || toolListValues.indexOf('insertimage') >= 0) icons += inputStr; icons += createTool(ctx, 'close'); } else if (ctx._toolbar.querySelectorAll('[data-action=createlink]').length || ctx._toolbar.querySelectorAll('[data-action=insertimage]').length) { icons += inputStr; } if (icons) { ctx._menu = doc.createElement('div'); ctx._menu.setAttribute('class', ctx.config.class + '-menu pen-menu'); ctx._menu.innerHTML = icons; ctx._urlInput = ctx._menu.querySelector('.pen-url-input'); ctx._externalUrlCheckbox = ctx._menu.querySelector('.pen-external-url-checkbox'); toggleNode(ctx._menu, true); doc.body.appendChild(ctx._menu); } } function initEvents(ctx) { var toolbar = ctx._toolbar || ctx._menu, editor = ctx.config.editor; var toggleMenu = utils.delayExec(function() { if (toolbar) { ctx.highlight().menu(); } }); var outsideClick = function() {}; function updateStatus(delay) { ctx._range = ctx.getRange(); toggleMenu(delay); } if (ctx._menu) { var setpos = function() { if (ctx._menu.style.display === 'flex') ctx.menu(); }; // change menu offset when window resize / scroll addListener(ctx, root, 'resize', setpos); addListener(ctx, root, 'scroll', setpos); // toggle toolbar on mouse select var selecting = false; addListener(ctx, editor, 'mousedown', function() { selecting = true; }); addListener(ctx, editor, 'mouseleave', function() { if (selecting) updateStatus(800); selecting = false; }); addListener(ctx, editor, 'mouseup', function() { if (selecting) updateStatus(200); selecting = false; }); // Hide menu when focusing outside of editor outsideClick = function(e) { if (ctx._menu && !containsNode(editor, e.target) && !containsNode(ctx._menu, e.target)) { removeListener(ctx, doc, 'click', outsideClick); toggleMenu(100); } }; } else { addListener(ctx, editor, 'click', function() { updateStatus(0); }); } addListener(ctx, editor, 'keyup', function(e) { checkPlaceholder(ctx); if (ctx.isEmpty()) { if (ctx.config.mode === 'advanced') { handleEmptyContent(ctx); } return; } if (isCaretAtEnd(ctx) && !isCaretAtStart(ctx) && ctx.config.mode !== 'advanced') { editor.innerHTML = editor.innerHTML.replace( /\u200b/, '' ); addEmptyCharAtEnd(ctx); } // toggle toolbar on key select if (e.which !== 13 || e.shiftKey) return updateStatus(400); var node = getNode(ctx, true); if (!node || !node.nextSibling || !lineBreakReg.test(node.nodeName)) return; if (node.nodeName !== node.nextSibling.nodeName) return; // hack for webkit, make 'enter' behavior like as firefox. if (node.lastChild.nodeName !== 'BR') node.appendChild(doc.createElement('br')); utils.forEach(node.nextSibling.childNodes, function(child) { if (child) node.appendChild(child); }, true); node.parentNode.removeChild(node.nextSibling); focusNode(ctx, node.lastChild, ctx.getRange()); }); // check line break addListener(ctx, editor, 'keydown', function(e) { editor.classList.remove(ctx.config.placeholderClass); if (e.which !== 13 || e.shiftKey) return; if ( ctx.config.ignoreLineBreak ) { e.preventDefault(); return; } var node = getNode(ctx, true); if(!node || !lineBreakReg.test(node.nodeName)) { if (ctx.config.mode === 'basic') { e.preventDefault(); commandOverall('insertHTML', '
      '); } return; } if (!node) { return; } var lastChild = node.lastChild; if (!lastChild || !lastChild.previousSibling) return; if (lastChild.previousSibling.textContent || lastChild.textContent) return; // quit block mode for 2 'enter' e.preventDefault(); var p = doc.createElement('p'); p.innerHTML = '
      '; node.removeChild(lastChild); if (!node.nextSibling) node.parentNode.appendChild(p); else node.parentNode.insertBefore(p, node.nextSibling); focusNode(ctx, p, ctx.getRange()); }); if (toolbar) { addListener(ctx, toolbar, 'click', function(e) { onToolbarClick(ctx, e.target); }); } addListener(ctx, editor, 'focus', function() { if (ctx.isEmpty() && ctx.config.mode === 'advanced') handleEmptyContent(ctx); addListener(ctx, doc, 'click', outsideClick); }); addListener(ctx, editor, 'blur', function() { checkPlaceholder(ctx); ctx.checkContentChange(); }); // listen for paste and clear style addListener(ctx, editor, 'paste', function() { setTimeout(function() { ctx.cleanContent(); }); }); } function addListener(ctx, target, type, listener) { if (ctx._events.hasOwnProperty(type)) { ctx._events[type].push(listener); } else { ctx._eventTargets = ctx._eventTargets || []; ctx._eventsCache = ctx._eventsCache || []; var index = ctx._eventTargets.indexOf(target); if (index < 0) index = ctx._eventTargets.push(target) - 1; ctx._eventsCache[index] = ctx._eventsCache[index] || {}; ctx._eventsCache[index][type] = ctx._eventsCache[index][type] || []; ctx._eventsCache[index][type].push(listener); target.addEventListener(type, listener, false); } return ctx; } // trigger local events function triggerListener(ctx, type) { if (!ctx._events.hasOwnProperty(type)) return; var args = slice.call(arguments, 2); utils.forEach(ctx._events[type], function (listener) { listener.apply(ctx, args); }); } function removeListener(ctx, target, type, listener) { var events = ctx._events[type]; if (!events) { var _index = ctx._eventTargets.indexOf(target); if (_index >= 0) events = ctx._eventsCache[_index][type]; } if (!events) return ctx; var index = events.indexOf(listener); if (index >= 0) events.splice(index, 1); target.removeEventListener(type, listener, false); return ctx; } function removeAllListeners(ctx) { utils.forEach(this._events, function (events) { events.length = 0; }, false); if (!ctx._eventsCache) return ctx; utils.forEach(ctx._eventsCache, function (events, index) { var target = ctx._eventTargets[index]; utils.forEach(events, function (listeners, type) { utils.forEach(listeners, function (listener) { target.removeEventListener(type, listener, false); }, true); }, false); }, true); ctx._eventTargets = []; ctx._eventsCache = []; return ctx; } function checkPlaceholder(ctx) { ctx.config.editor.classList[ctx.isEmpty() ? 'add' : 'remove'](ctx.config.placeholderClass); } function trim(str) { return (str || '').trim().replace(/\u200b/g, ''); } // node.contains is not implemented in IE10/IE11 function containsNode(parent, child) { if (parent === child) return true; child = child.parentNode; while (child) { if (child === parent) return true; child = child.parentNode; } return false; } function getNode(ctx, byRoot) { var node, root = ctx.config.editor; ctx._range = ctx._range || ctx.getRange(); node = ctx._range.commonAncestorContainer; // Fix selection detection for Firefox if (node.hasChildNodes() && ctx._range.startOffset + 1 === ctx._range.endOffset) { node = node.childNodes[ctx._range.startOffset]; } if (!node || node === root) return null; while (node && (node.nodeType !== 1) && (node.parentNode !== root)) node = node.parentNode; while (node && byRoot && (node.parentNode !== root)) node = node.parentNode; return containsNode(root, node) ? node : null; } function getEffectNodes(ctx) { return getNodeParents(ctx).filter(function(node) { return node.nodeName.match(effectNodeReg); }); } function getNodeParents(ctx) { var nodes = [], el = getNode(ctx); while (el && el !== ctx.config.editor) { if (el.nodeType === Node.ELEMENT_NODE) { nodes.push(el); } el = el.parentNode; } return nodes; } function handleEmptyContent(ctx) { var range = ctx._range = ctx.getRange(); ctx.config.editor.innerHTML = ''; var p = doc.createElement('p'); p.innerHTML = '
      '; range.insertNode(p); focusNode(ctx, p.childNodes[0], range); } function addEmptyCharAtEnd(ctx) { var range = ctx.getRange(), emptyCharNode = doc.createTextNode('\u200b'); range.selectNodeContents(ctx.config.editor); range.collapse(false); range.insertNode(emptyCharNode); focusNode(ctx, emptyCharNode, range); } function isCaretAtEnd(ctx) { var range = ctx.getRange(), clonedRange = range.cloneRange(); clonedRange.selectNodeContents(ctx.config.editor); clonedRange.setStart(range.endContainer, range.endOffset); return clonedRange.toString() === ''; } function isCaretAtStart(ctx) { var range = ctx.getRange(), clonedRange = range.cloneRange(); clonedRange.selectNodeContents(ctx.config.editor); clonedRange.setEnd(range.startContainer, range.startOffset); return clonedRange.toString() === ''; } function focusNode(ctx, node, range) { range.setStartAfter(node); range.setEndBefore(node); range.collapse(false); ctx.setRange(range); } function autoLink(node) { if (node.nodeType === 1) { if (autoLinkReg.notLink.test(node.tagName)) return; utils.forEach(node.childNodes, function (child) { autoLink(child); }, true); } else if (node.nodeType === 3) { var result = urlToLink(node.nodeValue || ''); if (!result.links) return; var frag = doc.createDocumentFragment(), div = doc.createElement('div'); div.innerHTML = result.text; while (div.childNodes.length) frag.appendChild(div.childNodes[0]); node.parentNode.replaceChild(frag, node); } } function urlToLink(str) { var count = 0; str = str.replace(autoLinkReg.url, function(url) { var realUrl = url, displayUrl = url; count++; if (url.length > autoLinkReg.maxLength) displayUrl = url.slice(0, autoLinkReg.maxLength) + '...'; // Add http prefix if necessary if (!autoLinkReg.prefix.test(realUrl)) realUrl = 'http://' + realUrl; return '' + displayUrl + ''; }); return {links: count, text: str}; } function toggleNode(node, hide) { node.style.display = hide ? 'none' : 'flex'; } InlineEditor = function(config) { if (!config) throw new Error('Can\'t find config'); debugMode = config.debug; // merge user config var defaults = utils.merge(config); var editor = defaults.editor; if (!editor || editor.nodeType !== 1) throw new Error('Can\'t find editor'); // set default class editor.classList.add.apply(editor.classList, defaults.class.split(' ')); // set contenteditable editor.setAttribute('contenteditable', 'true'); // assign config this.config = defaults; // set placeholder if (defaults.placeholder) editor.setAttribute(this.config.placeholderAttr, defaults.placeholder); checkPlaceholder(this); // save the selection obj this.selection = selection; // define local events this._events = {change: []}; // enable toolbar initToolbar(this); // init events initEvents(this); // to check content change this._prevContent = this.getContent(); // enable markdown covert if (this.markdown) this.markdown.init(this); // stay on the page if (this.config.stay) this.stay(this.config); if(this.config.input) { this.addOnSubmitListener(this.config.input); } if (this.config.mode === 'advanced') { this.getRange().selectNodeContents(editor); this.setRange(); } else { addEmptyCharAtEnd(this); } }; InlineEditor.prototype.on = function(type, listener) { addListener(this, this.config.editor, type, listener); return this; }; InlineEditor.prototype.addOnSubmitListener = function(inputElement) { var form = inputElement.form; var me = this; form.addEventListener("submit", function() { inputElement.value = me.config.saveAsMarkdown ? me.toMd(me.config.editor.innerHTML) : me.config.editor.innerHTML; }); }; InlineEditor.prototype.isEmpty = function(node) { node = node || this.config.editor; return !(node.querySelector('img')) && !(node.querySelector('blockquote')) && !(node.querySelector('li')) && !trim(node.textContent); }; InlineEditor.prototype.getContent = function() { return this.isEmpty() ? '' : trim(this.config.editor.innerHTML); }; InlineEditor.prototype.setContent = function(html) { this.config.editor.innerHTML = html; this.cleanContent(); return this; }; InlineEditor.prototype.checkContentChange = function () { var prevContent = this._prevContent, currentContent = this.getContent(); if (prevContent === currentContent) return; this._prevContent = currentContent; triggerListener(this, 'change', currentContent, prevContent); }; InlineEditor.prototype.getRange = function() { var editor = this.config.editor, range = selection.rangeCount && selection.getRangeAt(0); if (!range) range = doc.createRange(); if (!containsNode(editor, range.commonAncestorContainer)) { range.selectNodeContents(editor); range.collapse(false); } return range; }; InlineEditor.prototype.setRange = function(range) { range = range || this._range; if (!range) { range = this.getRange(); range.collapse(false); // set to end } try { selection.removeAllRanges(); selection.addRange(range); } catch (e) {/* IE throws error sometimes*/} return this; }; InlineEditor.prototype.focus = function(focusStart) { if (!focusStart) this.setRange(); this.config.editor.focus(); return this; }; InlineEditor.prototype.execCommand = function(name, value) { name = name.toLowerCase(); this.setRange(); if (commandsReg.block.test(name)) { commandBlock(this, name); } else if (commandsReg.inline.test(name)) { commandOverall(name, value); } else if (commandsReg.biu.test(name)) { // Temporarily removing all override style rules // to make sure the command will be executed correctly var styleBackup = styleBackupDict[ name ]; styleBackup.backupValue = this.config.editor.style[ styleBackup.styleKey ]; this.config.editor.style[ styleBackup.styleKey ] = styleBackup.correctValue; commandOverall(name, value); this.config.editor.style[ styleBackup.styleKey ] = styleBackup.backupValue; } else if (commandsReg.source.test(name)) { commandLink(this, name, value); } else if (commandsReg.insert.test(name)) { commandInsert(this, name, value); } else if (commandsReg.wrap.test(name)) { commandWrap(this, name, value); } else { utils.log('can not find command function for name: ' + name + (value ? (', value: ' + value) : ''), true); } if (name === 'indent') this.checkContentChange(); }; // remove attrs and tags // pen.cleanContent({cleanAttrs: ['style'], cleanTags: ['id']}) InlineEditor.prototype.cleanContent = function(options) { var editor = this.config.editor; if (!options) options = this.config; utils.forEach(options.cleanAttrs, function (attr) { utils.forEach(editor.querySelectorAll('[' + attr + ']'), function(item) { item.removeAttribute(attr); }, true); }, true); utils.forEach(options.cleanTags, function (tag) { utils.forEach(editor.querySelectorAll(tag), function(item) { item.parentNode.removeChild(item); }, true); }, true); checkPlaceholder(this); this.checkContentChange(); return this; }; // auto link content, return content InlineEditor.prototype.autoLink = function() { autoLink(this.config.editor); return this.getContent(); }; // highlight menu InlineEditor.prototype.highlight = function() { var toolbar = this._toolbar || this._menu, node = getNode(this); // remove all highlights utils.forEach(toolbar.querySelectorAll('.active'), function(el) { el.classList.remove('active'); }, true); if (!node) return this; var nodeParents = getNodeParents(this), urlInput = this._urlInput, externalUrlCheckbox = this._externalUrlCheckbox, highlight; if (urlInput && toolbar === this._menu) { // reset url inputs urlInput.value = ''; this._externalUrlCheckbox.checked = false; } highlight = function(str) { if (!str) return; var el = toolbar.querySelector('[data-action=' + str + ']'); return el && el.classList.add('active'); }; utils.forEach(nodeParents, function(item) { var tag = item.nodeName.toLowerCase(), align = item.style.textAlign, textDecoration = item.style.textDecoration; if (align) { if ('justify' === align) { align = 'full'; } highlight('justify' + align[0].toUpperCase() + align.slice(1)); } if ('underline' === textDecoration) { highlight('underline'); } if (! tag.match(effectNodeReg)) { return; } switch(tag) { case 'a': urlInput.value = item.getAttribute('href'); externalUrlCheckbox.checked = item.getAttribute('target') === '_blank'; tag = 'createlink'; break; case 'img': urlInput.value = item.getAttribute('src'); tag = 'insertimage'; break; case 'i': case 'em': tag = 'italic'; break; case 'u': tag = 'underline'; break; case 'b': case 'strong': tag = 'bold'; break; case 'strike': tag = 'strikethrough'; break; case 'ul': tag = 'insertUnorderedList'; break; case 'ol': tag = 'insertOrderedList'; break; case 'li': tag = 'indent'; break; } highlight(tag); }, true); return this; }; // show menu InlineEditor.prototype.menu = function() { if (!this._menu) return this; if (selection.isCollapsed) { this._menu.style.display = 'none'; //hide menu this._inputActive = false; return this; } if (this._toolbar) { if (!this._urlInput || !this._inputActive) return this; } showMainMenu(this); }; InlineEditor.prototype.refreshMenuPosition = function() { var offset = this._range.getBoundingClientRect() , menuPadding = 10 , top = offset.top - menuPadding , left = offset.left + (offset.width / 2) , menu = this._menu , menuOffset = {x: 0, y: 0} , stylesheet = this._stylesheet; // fixes some browser double click visual discontinuity // if the offset has no width or height it should not be used if (offset.width === 0 && offset.height === 0) return this; // store the stylesheet used for positioning the menu horizontally if (this._stylesheet === undefined) { var style = document.createElement("style"); document.head.appendChild(style); this._stylesheet = stylesheet = style.sheet; } // display it to caculate its width & height menu.style.display = 'flex'; menuOffset.x = left - (menu.clientWidth / 2); menuOffset.y = top - menu.clientHeight; // check to see if menu has over-extended its bounding box. if it has, // 1) apply a new class if overflowed on top; // 2) apply a new rule if overflowed on the left if (stylesheet.cssRules.length > 0) { stylesheet.deleteRule(0); } if (menuOffset.x < 0) { menuOffset.x = 0; stylesheet.insertRule('.pen-menu:after {left: ' + left + 'px;}', 0); } else { stylesheet.insertRule('.pen-menu:after {left: 50%; }', 0); } if (menuOffset.y < 0) { menu.classList.add('pen-menu-below'); menuOffset.y = offset.top + offset.height + menuPadding; } else { menu.classList.remove('pen-menu-below'); } menu.style.top = menuOffset.y + 'px'; menu.style.left = menuOffset.x + 'px'; return this; }; InlineEditor.prototype.stay = function(config) { var ctx = this; if (!window.onbeforeunload) { window.onbeforeunload = function() { if (!ctx._isDestroyed) return config.stayMsg; }; } }; InlineEditor.prototype.destroy = function() { var config = this.config; removeAllListeners(this); config.editor.classList.remove.apply(config.editor.classList, config.class.split(' ').concat(config.placeholderClass)); config.editor.removeAttribute('contenteditable'); config.editor.removeAttribute(config.placeholderAttr); try { selection.removeAllRanges(); if (this._menu) this._menu.parentNode.removeChild(this._menu); } catch (e) {/* IE throws error sometimes*/} this._isDestroyed = true; return this; }; InlineEditor.prototype.rebuild = function() { initToolbar(this); initEvents(this); return this; }; // a fallback for old browers root.ElementorInlineEditor = function(config) { if (!config) return utils.log('can\'t find config', true); var defaults = utils.merge(config) , klass = defaults.editor.getAttribute('class'); klass = klass ? klass.replace(/\bpen\b/g, '') + ' pen-textarea ' + defaults.class : 'pen pen-textarea'; defaults.editor.setAttribute('class', klass); defaults.editor.innerHTML = defaults.textarea; return defaults.editor; }; // export content as markdown var regs = { a: [/]*href=["']([^"]+|[^']+)\b[^>]*>(.*?)<\/a>/ig, '[$2]($1)'], img: [/]*src=["']([^\"+|[^']+)[^>]*>/ig, '![]($1)'], b: [/]*>(.*?)<\/b>/ig, '**$1**'], i: [/]*>(.*?)<\/i>/ig, '***$1***'], h: [/]*>(.*?)<\/h\1>/ig, function(a, b, c) { return '\n' + ('######'.slice(0, b)) + ' ' + c + '\n'; }], li: [/<(li)\b[^>]*>(.*?)<\/\1>/ig, '* $2\n'], blockquote: [/<(blockquote)\b[^>]*>(.*?)<\/\1>/ig, '\n> $2\n'], pre: [/]*>(.*?)<\/pre>/ig, '\n```\n$1\n```\n'], code: [/]*>(.*?)<\/code>/ig, '\n`\n$1\n`\n'], p: [/]*>(.*?)<\/p>/ig, '\n$1\n'], hr: [/]*>/ig, '\n---\n'] }; InlineEditor.prototype.toMd = function() { var html = this.getContent() .replace(/\n+/g, '') // remove line break .replace(/<([uo])l\b[^>]*>(.*?)<\/\1l>/ig, '$2'); // remove ul/ol for(var p in regs) { if (regs.hasOwnProperty(p)) html = html.replace.apply(html, regs[p]); } return html.replace(/\*{5}/g, '**'); }; // make it accessible if (doc.getSelection) { selection = doc.getSelection(); root.ElementorInlineEditor = InlineEditor; } }(window, document));