diff --git a/dist/textAngular.min.js b/dist/textAngular.min.js index 0ae1ea89..65360185 100644 --- a/dist/textAngular.min.js +++ b/dist/textAngular.min.js @@ -15,4 +15,4 @@ Version 1.3.0-17 See README.md or https://github.com/fraywing/textAngular/wiki for requirements and use. */ function(){"Use Strict";function a(a){try{return 0!==angular.element(a).length}catch(b){return!1}}function b(a,c){var d=[],e=a.children();return e.length&&angular.forEach(e,function(a){d=d.concat(b(angular.element(a),c))}),void 0!==a.attr(c)&&d.push(a),d}function c(b,c){if(!b||""===b||r.hasOwnProperty(b))throw"textAngular Error: A unique name is required for a Tool Definition";if(c.display&&(""===c.display||!a(c.display))||!c.display&&!c.buttontext&&!c.iconclass)throw'textAngular Error: Tool Definition for "'+b+'" does not have a valid display/iconclass/buttontext value';r[b]=c}var d={ie:function(){for(var a,b=3,c=document.createElement("div"),d=c.getElementsByTagName("i");c.innerHTML="",d[0];);return b>4?b:a}(),webkit:/AppleWebKit\/([\d.]+)/i.test(navigator.userAgent)},e=!1;d.webkit&&(document.addEventListener("mousedown",function(a){var b=a||window.event,c=b.target;if(e&&null!==c){for(var d=!1,f=c;null!==f&&"html"!==f.tagName.toLowerCase()&&!d;)d="true"===f.contentEditable,f=f.parentNode;d||(document.getElementById("textAngular-editableFix-010203040506070809").setSelectionRange(0,0),c.focus(),c.select&&c.select())}e=!1},!1),angular.element(document).ready(function(){angular.element(document.body).append(angular.element(''))}));var f=/^(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)$/gi,g=/^(ul|li|ol)$/gi,h=/^(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|li)$/gi;String.prototype.trim||(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")});var i,j,k,l,m;if(d.ie>8||void 0===d.ie){for(var n=document.styleSheets,o=0;o");return d[0].innerHTML=c,angular.forEach(a,function(a){var c=[];a.selector&&""!==a.selector?c=d.find(a.selector):a.customAttribute&&""!==a.customAttribute&&(c=b(d,a.customAttribute)),angular.forEach(c,function(b){b=angular.element(b),a.selector&&""!==a.selector&&a.customAttribute&&""!==a.customAttribute?void 0!==b.attr(a.customAttribute)&&a.renderLogic(b):a.renderLogic(b)})}),d[0].innerHTML}}]).factory("taFixChrome",function(){var a=function(a){for(var b=angular.element("
"+a+"
"),c=angular.element(b).find("span"),d=0;d0&&"BR"===e.next()[0].tagName&&e.next().remove(),e.replaceWith(e[0].innerHTML)))}var f=b[0].innerHTML.replace(/style="[^"]*?(line-height: 1.428571429;|color: inherit; line-height: 1.1;)[^"]*"/gi,"");return f!==b[0].innerHTML&&(b[0].innerHTML=f),b[0].innerHTML};return a}).factory("taSanitize",["$sanitize",function(a){function c(a){var b=a.children();b.length&&angular.forEach(b,function(a){var b=angular.element(a);d(b),c(b)})}function d(a){var b=a.attr("style");b&&angular.forEach(e,function(c){var d=c.property,e=a.css(d);if(c.values.indexOf(e)>=0&&b.toLowerCase().indexOf(d)>=0){a.css(d,"");var f=a.html(),g=c.tag;f="<"+g+">"+f+"",a.html(f)}})}var e=[{property:"font-weight",values:["bold"],tag:"b"},{property:"font-style",values:["italic"],tag:"i"}];return function(e,f,g){if(!g)try{var h=angular.element("
"+e+"
");d(h),c(h),e=h.html()}catch(i){}var j=angular.element("
"+e+"
");angular.forEach(b(j,"align"),function(a){a.css("text-align",a.attr("align")),a.removeAttr("align")});var k;e=j[0].innerHTML;try{k=a(e),g&&(k=e)}catch(i){k=f||""}return k}}]).factory("taToolExecuteAction",["$q","$log",function(a,b){return function(c){void 0!==c&&(this.$editor=function(){return c});var d=a.defer(),e=d.promise,f=this.$editor();e["finally"](function(){f.endAction.call(f)});var g;try{g=this.action(d,f.startAction())}catch(h){b.error(h)}(g||void 0===g)&&d.resolve()}}]),angular.module("textAngular.DOM",["textAngular.factories"]).factory("taExecCommand",["taSelection","taBrowserTag","$document",function(a,b,c){var d=function(b,c){var d,e,f=b.find("li");for(e=f.length-1;e>=0;e--)d=angular.element("<"+c+">"+f[e].innerHTML+""),b.after(d);b.remove(),a.setSelectionToElementEnd(d[0])},e=function(b){/()$/i.test(b.innerHTML.trim())?a.setSelectionBeforeElement(angular.element(b).find("br")[0]):a.setSelectionToElementEnd(b)},h=function(a,b){var c=angular.element("<"+b+">"+a[0].innerHTML+"");a.after(c),a.remove(),e(c.find("li")[0])},i=function(a,c,d){for(var f="",g=0;g"+a[g].innerHTML+"";var h=angular.element("<"+d+">"+f+"");c.after(h),c.remove(),e(h.find("li")[0])};return function(e,j){return e=b(e),function(k,l,m){var n,o,p,q,r,s,t,u=angular.element("<"+e+">");try{t=a.getSelectionElement()}catch(v){}var w=angular.element(t);if(void 0!==t){var x=t.tagName.toLowerCase();if("insertorderedlist"===k.toLowerCase()||"insertunorderedlist"===k.toLowerCase()){var y=b("insertorderedlist"===k.toLowerCase()?"ol":"ul");if(x===y)return d(w,e);if("li"===x&&w.parent()[0].tagName.toLowerCase()===y&&1===w.parent().children().length)return d(w.parent(),e);if("li"===x&&w.parent()[0].tagName.toLowerCase()!==y&&1===w.parent().children().length)return h(w.parent(),y);if(x.match(f)&&!w.hasClass("ta-bind")){if("ol"===x||"ul"===x)return h(w,y);var z=!1;return angular.forEach(w.children(),function(a){a.tagName.match(f)&&(z=!0)}),z?i(w.children(),w,y):i([angular.element("
"+t.innerHTML+"
")[0]],w,y)}if(x.match(f)){if(q=a.getOnlySelectedElements(),0===q.length)o=angular.element("<"+y+">
  • "+t.innerHTML+"
  • "),w.html(""),w.append(o);else{if(1===q.length&&("ol"===q[0].tagName.toLowerCase()||"ul"===q[0].tagName.toLowerCase()))return q[0].tagName.toLowerCase()===y?d(angular.element(q[0]),e):h(angular.element(q[0]),y);p="";var A=[];for(n=0;n"+B[0].innerHTML+"":B[0].childNodes[0].innerHTML,A.unshift(B)}o=angular.element("<"+y+">"+p+""),A.pop().replaceWith(o),angular.forEach(A,function(a){a.remove()})}return void a.setSelectionToElementEnd(o[0])}}else{if("formatblock"===k.toLowerCase()){for(s=m.toLowerCase().replace(/[<>]/gi,""),"default"===s.trim()&&(s=e,m="<"+e+">"),o="li"===x?w.parent():w;!o[0].tagName||!o[0].tagName.match(f)&&!o.parent().attr("contenteditable");)o=o.parent(),x=(o[0].tagName||"").toLowerCase();if(x===s){q=o.children();var C=!1;for(n=0;n=0;n--)q[n].parentNode&&q[n].parentNode.removeChild(q[n])}else for(n=0;n"),u[0].innerHTML=E[n].outerHTML,E[n]=u[0]),D.parent()[0].insertBefore(E[n],D[0]);D.remove()}return void a.setSelectionToElementEnd(o[0])}if("createlink"===k.toLowerCase()){var F=a.getSelection();if(F.collapsed)return void a.insertHtml(''+m+"",j)}else if("inserthtml"===k.toLowerCase())return void a.insertHtml(m,j)}}try{c[0].execCommand(k,l,m)}catch(v){}}}}]).service("taSelection",["$window","$document",function(a,b){var c=b[0],d=a.rangy,e={getSelection:function(){var a=d.getSelection().getRangeAt(0),b=a.commonAncestorContainer;return b=3===b.nodeType?b.parentNode:b,{start:{element:a.startContainer,offset:a.startOffset},end:{element:a.endContainer,offset:a.endOffset},container:b,collapsed:a.collapsed}},getOnlySelectedElements:function(){var a=d.getSelection().getRangeAt(0),b=a.commonAncestorContainer;return b=3===b.nodeType?b.parentNode:b,a.getNodes([1],function(a){return a.parentNode===b})},getSelectionElement:function(){return e.getSelection().container},setSelection:function(a,b,c){var e=d.createRange();e.setStart(a,b),e.setEnd(a,c),d.getSelection().setSingleRange(e)},setSelectionBeforeElement:function(a){var b=d.createRange();b.selectNode(a),b.collapse(!0),d.getSelection().setSingleRange(b)},setSelectionAfterElement:function(a){var b=d.createRange();b.selectNode(a),b.collapse(!1),d.getSelection().setSingleRange(b)},setSelectionToElementStart:function(a){var b=d.createRange();b.selectNodeContents(a),b.collapse(!0),d.getSelection().setSingleRange(b)},setSelectionToElementEnd:function(a){var b=d.createRange();b.selectNodeContents(a),b.collapse(!1),d.getSelection().setSingleRange(b)},insertHtml:function(a,b){var g,h,i,j,k,l,m,n,o,p=angular.element("
    "+a+"
    "),q=d.getSelection().getRangeAt(0),r=c.createDocumentFragment(),s=p[0].childNodes,t=!0;if(s.length>0){for(j=[],i=0;i)$/i.test(q.startContainer.innerHTML)&&q.selectNode(q.startContainer)}else t=!0,o=r=c.createTextNode(a);if(t)q.deleteContents();else if(q.collapsed&&q.startContainer!==b&&q.startContainer.parentNode!==b){if(3===q.startContainer.nodeType){for(g=q.startContainer.parentNode,j=g.childNodes,l=[],m=[],k=0;k)$/i.test(g.innerHTML.trim())&&(q.setStartBefore(g),q.setEndBefore(g),angular.element(g).remove()),/^(|)$/i.test(h.innerHTML.trim())&&angular.element(h).remove()}else q.deleteContents();q.insertNode(r),o&&e.setSelectionToElementEnd(o)}};return e}]),angular.module("textAngular.validators",[]).directive("taMaxText",function(){return{restrict:"A",require:"ngModel",link:function(a,b,c,d){function e(a){var b=angular.element("
    ");b.html(a);var c=b.text().length;return f>=c?(d.$setValidity("taMaxText",!0),a):void d.$setValidity("taMaxText",!1)}var f=parseInt(a.$eval(c.taMaxText));if(isNaN(f))throw"Max text must be an integer";c.$observe("taMaxText",function(a){if(f=parseInt(a),isNaN(f))throw"Max text must be an integer";d.$dirty&&d.$setViewValue(d.$viewValue)}),d.$parsers.unshift(e)}}}).directive("taMinText",function(){return{restrict:"A",require:"ngModel",link:function(a,b,c,d){function e(a){var b=angular.element("
    ");b.html(a);var c=b.text().length;return!c||c>=f?(d.$setValidity("taMinText",!0),a):void d.$setValidity("taMinText",!1)}var f=parseInt(a.$eval(c.taMinText));if(isNaN(f))throw"Min text must be an integer";c.$observe("taMinText",function(a){if(f=parseInt(a),isNaN(f))throw"Min text must be an integer";d.$dirty&&d.$setViewValue(d.$viewValue)}),d.$parsers.unshift(e)}}}),angular.module("textAngular.taBind",["textAngular.factories","textAngular.DOM"]).directive("taBind",["taSanitize","$timeout","$window","$document","taFixChrome","taBrowserTag","taSelection","taSelectableElements","taApplyCustomRenderers","taOptions",function(a,c,f,g,i,l,m,n,o,q){return{require:"ngModel",link:function(l,r,s,t){var u,v,w,x=void 0!==r.attr("contenteditable")&&r.attr("contenteditable"),y=x||"textarea"===r[0].tagName.toLowerCase()||"input"===r[0].tagName.toLowerCase(),z=!1,A=!1,B=s.taUnsafeSanitizer||q.disableSanitizer,C=/^(9|19|20|27|33|34|35|36|37|38|39|40|45|112|113|114|115|116|117|118|119|120|121|122|123|144|145)$/i,D=/^(8|13|32|46|59|61|107|109|186|187|188|189|190|191|192|219|220|221|222)$/i,E=/<(a|abbr|acronym|bdi|bdo|big|cite|code|del|dfn|img|ins|kbd|label|map|mark|q|ruby|rp|rt|s|samp|time|tt|var)[^>]*>/i;void 0===s.taDefaultWrap&&(s.taDefaultWrap="p"),""===s.taDefaultWrap?(v="",w=void 0===d.ie?"

    ":d.ie>=11?"


    ":d.ie<=8?"

     

    ":"

     

    "):(v=void 0===d.ie||d.ie>=11?"<"+s.taDefaultWrap+">
    ":d.ie<=8?"<"+s.taDefaultWrap.toUpperCase()+">":"<"+s.taDefaultWrap+">",w=void 0===d.ie||d.ie>=11?"<"+s.taDefaultWrap+">
    ":d.ie<=8?"<"+s.taDefaultWrap.toUpperCase()+"> ":"<"+s.taDefaultWrap+"> ");var F=function(a){var b=a.indexOf(">");return-1===b?0===a.trim().length:(a=a.trim().substring(b,b+100),0===a.length||a===w||/^>(\s| )*<\/[^>]+>$/gi.test(a)?!0:/>\s*[^\s<]/i.test(a)||E.test(a)?!1:!0)};r.addClass("ta-bind");var G;l["$undoManager"+(s.id||"")]=t.$undoManager={_stack:[],_index:0,_max:1e3,push:function(a){return"undefined"==typeof a||null===a||"undefined"!=typeof this.current()&&null!==this.current()&&a===this.current()?a:(this._indexthis._max&&this._stack.shift(),this._index=this._stack.length-1,a)},undo:function(){return this.setToIndex(this._index-1)},redo:function(){return this.setToIndex(this._index+1)},setToIndex:function(a){return 0>a||a>this._stack.length-1?void 0:(this._index=a,this.current())},current:function(){return this._stack[this._index]}};var H=l["$undoTaBind"+(s.id||"")]=function(){if(!z&&x){var a=t.$undoManager.undo();"undefined"!=typeof a&&null!==a&&(U(a),K(a,!1),m.setSelectionToElementEnd(r[0].childNodes.length?r[0].childNodes[r[0].childNodes.length-1]:r[0]))}},I=l["$redoTaBind"+(s.id||"")]=function(){if(!z&&x){var a=t.$undoManager.redo();"undefined"!=typeof a&&null!==a&&(U(a),K(a,!1),m.setSelectionToElementEnd(r[0].childNodes.length?r[0].childNodes[r[0].childNodes.length-1]:r[0]))}},J=function(){if(x)return r[0].innerHTML;if(y)return r.val();throw"textAngular Error: attempting to update non-editable taBind"},K=function(a,b){("undefined"==typeof b||null===b)&&(b=!0&&x),("undefined"==typeof a||null===a)&&(a=J()),F(a)?(""!==t.$viewValue&&t.$setViewValue(""),b&&""!==t.$undoManager.current()&&t.$undoManager.push("")):(T(),t.$viewValue!==a&&(t.$setViewValue(a),b&&t.$undoManager.push(a)))};if(l["updateTaBind"+(s.id||"")]=function(){z||K()},y)if(x){var L=function(a,b,c){r[0].childNodes&&r[0].childNodes.length>0?c(a,b):(that={s:a,_:b,cb:c},that.callself=function(){L(that.s,that._,that.cb)},setTimeout(that.callself,5))},M=!1,N=function(d,e){if(text=r[0].innerHTML,r[0].innerHTML=d,f.rangy.restoreSelection(e),text.trim().length){if(text.match(/class=["']*Mso(Normal|List)/i)){var g=text.match(/([\s\S]*?)/i);g=g?g[1]:text,g=g.replace(/[\s\S]*?<\/o:p>/gi,"").replace(/class=(["']|)MsoNormal(["']|)/gi,"");var h=angular.element("
    "+g+"
    "),i=angular.element("
    "),j={element:null,lastIndent:[],lastLi:null,isUl:!1};j.lastIndent.peek=function(){var a=this.length;return a>0?this[a-1]:void 0};for(var k=function(a){j.isUl=a,j.element=angular.element(a?"
      ":"
        "),j.lastIndent=[],j.lastIndent.peek=function(){var a=this.length;return a>0?this[a-1]:void 0},j.lastLevelMatch=null},l=0;l<=h[0].childNodes.length;l++)if(h[0].childNodes[l]&&"#text"!==h[0].childNodes[l].nodeName&&"p"===h[0].childNodes[l].tagName.toLowerCase()){var n=angular.element(h[0].childNodes[l]),o=(n.attr("class")||"").match(/MsoList(Bullet|Number|Paragraph)(CxSp(First|Middle|Last)|)/i);if(o){if(n[0].childNodes.length<2||n[0].childNodes[1].childNodes.length<1)continue;var p="bullet"===o[1].toLowerCase()||"number"!==o[1].toLowerCase()&&!(/^[^0-9a-z<]*[0-9a-z]+[^0-9a-z<>]]":"
          "),j.lastLi.append(j.element);else if(null!=j.lastIndent.peek()&&j.lastIndent.peek()>s){for(;null!=j.lastIndent.peek()&&j.lastIndent.peek()>s;)if("li"!==j.element.parent()[0].tagName.toLowerCase()){if(!/[uo]l/i.test(j.element.parent()[0].tagName.toLowerCase()))break;j.element=j.element.parent(),j.lastIndent.pop()}else j.element=j.element.parent();j.isUl="ul"===j.element[0].tagName.toLowerCase(),p!==j.isUl&&(k(p),i.append(j.element))}j.lastLevelMatch=u,s!==j.lastIndent.peek()&&j.lastIndent.push(s),j.lastLi=angular.element("
        1. "),j.element.append(j.lastLi),j.lastLi.html(n.html().replace(/[\s\S]*?/gi,"")),n.remove()}else k(!1),i.append(n)}var v=function(a){a=angular.element(a);for(var b=a[0].childNodes.length-1;b>=0;b--)a.after(a[0].childNodes[b]);a.remove()};angular.forEach(i.find("span"),function(a){a.removeAttribute("lang"),a.attributes.length<=0&&v(a)}),angular.forEach(i.find("font"),v),text=i.html()}else{if(text=text.replace(/<(|\/)meta[^>]*?>/gi,""),text.match(/<[^>]*?(ta-bind)[^>]*?>/)){if(text.match(/<[^>]*?(text-angular)[^>]*?>/)){var w=angular.element("
          "+text+"
          ");w.find("textarea").remove();for(var x=b(w,"ta-bind"),y=0;y',"")}}else text.match(/^]*?>/gi,""));text=text.replace(/
          ]*?>/gi,"")}text=a(text,"",B),m.insertHtml(text,r[0]),c(function(){t.$setViewValue(J()),M=!1,r.removeClass("processing-paste")},0)}else M=!1,r.removeClass("processing-paste")};if(r.on("paste",function(a,b){if(b&&angular.extend(a,b),z||M)return a.stopPropagation(),a.preventDefault(),!1;var c=f.rangy.saveSelection();M=!0,r.addClass("processing-paste");var d=r[0].innerHTML,e=(a.originalEvent||a).clipboardData;if(e&&e.getData){for(var g="",h=0;h$/i.test(c.innerHTML.trim())&&"blockquote"===c.parentNode.tagName.toLowerCase()&&!c.nextSibling){$selection=angular.element(c);var e=$selection.parent();e.after(d),$selection.remove(),0===e.children().length&&e.remove(),m.setSelectionToElementStart(d[0]),a.preventDefault()}else/^<[^>]+><\/[^>]+>$/i.test(c.innerHTML.trim())&&"blockquote"===c.tagName.toLowerCase()&&($selection=angular.element(c),$selection.after(d),$selection.remove(),m.setSelectionToElementStart(d[0]),a.preventDefault())}}),r.on("keyup",function(a,b){if(b&&angular.extend(a,b),G&&c.cancel(G),!z&&!C.test(a.keyCode)){if(""!==v&&13===a.keyCode&&!a.shiftKey){for(var d=m.getSelectionElement();!d.tagName.match(h)&&d!==r[0];)d=d.parentNode;if(d.tagName.toLowerCase()!==s.taDefaultWrap&&"li"!==d.tagName.toLowerCase()&&(""===d.innerHTML.trim()||"
          "===d.innerHTML.trim())){var e=angular.element(v);angular.element(d).replaceWith(e),m.setSelectionToElementStart(e[0])}}var f=J();""!==v&&""===f.trim()&&(U(v),m.setSelectionToElementStart(r.children()[0]));var g=u!==a.keyCode&&D.test(a.keyCode);K(f,g),g||(G=c(function(){t.$undoManager.push(f)},250)),u=a.keyCode}}),r.on("blur",function(){A=!1,z||K(),t.$render()}),s.placeholder&&(d.ie>8||void 0===d.ie)){var O;if(!s.id)throw"textAngular Error: An unique ID is required for placeholders to work";O=j("#"+s.id+".placeholder-text:before",'content: "'+s.placeholder+'"'),l.$on("$destroy",function(){k(O)})}r.on("focus",function(){A=!0,t.$render()}),r.on("mouseup",function(){var a=m.getSelection();a.start.element===r[0]&&m.setSelectionToElementStart(r.children()[0])}),r.on("mousedown",function(a,b){b&&angular.extend(a,b),a.stopPropagation()})}else r.on("change blur",function(){z||t.$setViewValue(J())});var P=function(b){return t.$oldViewValue=a(i(b),t.$oldViewValue,B)},Q=function(a){return s.required&&t.$setValidity("required",!F(a)),a};t.$parsers.push(P),t.$parsers.push(Q),t.$formatters.push(P),t.$formatters.push(function(a){if(F(a))return a;var b=angular.element("
          "+a+"
          ");return 0===b.children().length&&(a="<"+s.taDefaultWrap+">"+a+""),a}),t.$formatters.push(Q),t.$formatters.push(function(a){return t.$undoManager.push(a||"")});var R=function(a){return l.$emit("ta-element-select",this),a.preventDefault(),!1},S=function(a,b){if(b&&angular.extend(a,b),!p&&!z){p=!0;var d;d=a.originalEvent?a.originalEvent.dataTransfer:a.dataTransfer,l.$emit("ta-drop-event",this,a,d),c(function(){p=!1,K()},100)}},T=l["reApplyOnSelectorHandlers"+(s.id||"")]=function(){z||angular.forEach(n,function(a){r.find(a).off("click",R).on("click",R)})},U=function(a){r[0].innerHTML=a};t.$render=function(){var a=t.$viewValue||"";g[0].activeElement!==r[0]?x?(s.placeholder?""===a?(A?r.removeClass("placeholder-text"):r.addClass("placeholder-text"),U(v)):(r.removeClass("placeholder-text"),U(a)):U(""===a?v:a),z?r.off("drop",S):(T(),r.on("drop",S))):"textarea"!==r[0].tagName.toLowerCase()&&"input"!==r[0].tagName.toLowerCase()?U(o(a)):r.val(a):x&&r.removeClass("placeholder-text")},s.taReadonly&&(z=l.$eval(s.taReadonly),z?(r.addClass("ta-readonly"),("textarea"===r[0].tagName.toLowerCase()||"input"===r[0].tagName.toLowerCase())&&r.attr("disabled","disabled"),void 0!==r.attr("contenteditable")&&r.attr("contenteditable")&&r.removeAttr("contenteditable")):(r.removeClass("ta-readonly"),"textarea"===r[0].tagName.toLowerCase()||"input"===r[0].tagName.toLowerCase()?r.removeAttr("disabled"):x&&r.attr("contenteditable","true")),l.$watch(s.taReadonly,function(a,b){b!==a&&(a?(r.addClass("ta-readonly"),("textarea"===r[0].tagName.toLowerCase()||"input"===r[0].tagName.toLowerCase())&&r.attr("disabled","disabled"),void 0!==r.attr("contenteditable")&&r.attr("contenteditable")&&r.removeAttr("contenteditable"),angular.forEach(n,function(a){r.find(a).on("click",R)}),r.off("drop",S)):(r.removeClass("ta-readonly"),"textarea"===r[0].tagName.toLowerCase()||"input"===r[0].tagName.toLowerCase()?r.removeAttr("disabled"):x&&r.attr("contenteditable","true"),angular.forEach(n,function(a){r.find(a).off("click",R)}),r.on("drop",S)),z=a)})),x&&!z&&(angular.forEach(n,function(a){r.find(a).on("click",R)}),r.on("drop",S),r.on("blur",function(){d.webkit&&(e=!0)}))}}}]);var p=!1,q=angular.module("textAngular",["ngSanitize","textAngularSetup","textAngular.factories","textAngular.DOM","textAngular.validators","textAngular.taBind"]),r={};q.constant("taRegisterTool",c),q.value("taTools",r),q.config([function(){angular.forEach(r,function(a,b){delete r[b]})}]),q.run([function(){if(!window.rangy)throw"rangy-core.js and rangy-selectionsaverestore.js are required for textAngular to work correctly, rangy-core is not yet loaded.";if(window.rangy.init(),!window.rangy.saveSelection)throw"rangy-selectionsaverestore.js is required for textAngular to work correctly."}]),q.directive("textAngular",["$compile","$timeout","taOptions","taSelection","taExecCommand","textAngularManager","$window","$document","$animate","$log","$q",function(a,b,c,d,e,f,g,h,i,j,k){return{require:"?ngModel",scope:{},restrict:"EA",link:function(l,m,n,o){var p,q,r,s,t,u,v,w,x,y=n.serial?n.serial:Math.floor(1e16*Math.random());l._name=n.name?n.name:"textAngularEditor"+y;var z=function(a,c,d){b(function(){var b=function(){a.off(c,b),d.apply(this,arguments)};a.on(c,b)},100)};x=e(n.taDefaultWrap),angular.extend(l,angular.copy(c),{wrapSelection:function(a,b,c){"undo"===a.toLowerCase()?l["$undoTaBindtaTextElement"+y]():"redo"===a.toLowerCase()?l["$redoTaBindtaTextElement"+y]():(x(a,!1,b),c&&l["reApplyOnSelectorHandlerstaTextElement"+y](),l.displayElements.text[0].focus())},showHtml:l.$eval(n.taShowHtml)||!1}),n.taFocussedClass&&(l.classes.focussed=n.taFocussedClass),n.taTextEditorClass&&(l.classes.textEditor=n.taTextEditorClass),n.taHtmlEditorClass&&(l.classes.htmlEditor=n.taHtmlEditorClass),n.taTextEditorSetup&&(l.setup.textEditorSetup=l.$parent.$eval(n.taTextEditorSetup)),n.taHtmlEditorSetup&&(l.setup.htmlEditorSetup=l.$parent.$eval(n.taHtmlEditorSetup)),l.fileDropHandler=n.taFileDrop?l.$parent.$eval(n.taFileDrop):l.defaultFileDropHandler,v=m[0].innerHTML,m[0].innerHTML="",l.displayElements={forminput:angular.element(""),html:angular.element(""),text:angular.element("
          "),scrollWindow:angular.element("
          "),popover:angular.element('
          '),popoverArrow:angular.element('
          '),popoverContainer:angular.element('
          '),resize:{overlay:angular.element('
          '),background:angular.element('
          '),anchors:[angular.element('
          '),angular.element('
          '),angular.element('
          '),angular.element('
          ')],info:angular.element('
          ')}},l.displayElements.popover.append(l.displayElements.popoverArrow),l.displayElements.popover.append(l.displayElements.popoverContainer),l.displayElements.scrollWindow.append(l.displayElements.popover),l.displayElements.popover.on("mousedown",function(a,b){return b&&angular.extend(a,b),a.preventDefault(),!1}),l.showPopover=function(a){l.displayElements.popover.css("display","block"),l.reflowPopover(a),i.addClass(l.displayElements.popover,"in"),z(h.find("body"),"click keyup",function(){l.hidePopover()})},l.reflowPopover=function(a){l.displayElements.text[0].offsetHeight-51>a[0].offsetTop?(l.displayElements.popover.css("top",a[0].offsetTop+a[0].offsetHeight+"px"),l.displayElements.popover.removeClass("top").addClass("bottom")):(l.displayElements.popover.css("top",a[0].offsetTop-54+"px"),l.displayElements.popover.removeClass("bottom").addClass("top"));var b=l.displayElements.text[0].offsetWidth-l.displayElements.popover[0].offsetWidth,c=a[0].offsetLeft+a[0].offsetWidth/2-l.displayElements.popover[0].offsetWidth/2;l.displayElements.popover.css("left",Math.max(0,Math.min(b,c))+"px"),l.displayElements.popoverArrow.css("margin-left",Math.min(c,Math.max(0,c-b))-11+"px")},l.hidePopover=function(){var a=function(){l.displayElements.popover.css("display",""),l.displayElements.popoverContainer.attr("style",""),l.displayElements.popoverContainer.attr("class","popover-content")};k.when(i.removeClass(l.displayElements.popover,"in",a)).then(a)},l.displayElements.resize.overlay.append(l.displayElements.resize.background),angular.forEach(l.displayElements.resize.anchors,function(a){l.displayElements.resize.overlay.append(a)}),l.displayElements.resize.overlay.append(l.displayElements.resize.info),l.displayElements.scrollWindow.append(l.displayElements.resize.overlay),l.reflowResizeOverlay=function(a){a=angular.element(a)[0],l.displayElements.resize.overlay.css({display:"block",left:a.offsetLeft-5+"px",top:a.offsetTop-5+"px",width:a.offsetWidth+10+"px",height:a.offsetHeight+10+"px"}),l.displayElements.resize.info.text(a.offsetWidth+" x "+a.offsetHeight)},l.showResizeOverlay=function(a){var b=function(b){var c={width:parseInt(a.attr("width")),height:parseInt(a.attr("height")),x:b.clientX,y:b.clientY};void 0===c.width&&(c.width=a[0].offsetWidth),void 0===c.height&&(c.height=a[0].offsetHeight),l.hidePopover();var d=c.height/c.width,e=function(b){var e={x:Math.max(0,c.width+(b.clientX-c.x)),y:Math.max(0,c.height+(b.clientY-c.y))};if(b.shiftKey){var f=e.y/e.x;e.x=d>f?e.x:e.y/d,e.y=d>f?e.x*d:e.y}el=angular.element(a),el.attr("height",Math.max(0,e.y)),el.attr("width",Math.max(0,e.x)),l.reflowResizeOverlay(a)};h.find("body").on("mousemove",e),z(h.find("body"),"mouseup",function(b){b.preventDefault(),b.stopPropagation(),h.find("body").off("mousemove",e),l.showPopover(a)}),b.stopPropagation(),b.preventDefault()};l.displayElements.resize.anchors[3].on("mousedown",b),l.reflowResizeOverlay(a),z(h.find("body"),"click",function(){l.hideResizeOverlay()})},l.hideResizeOverlay=function(){l.displayElements.resize.overlay.css("display","")},l.setup.htmlEditorSetup(l.displayElements.html),l.setup.textEditorSetup(l.displayElements.text),l.displayElements.html.attr({id:"taHtmlElement"+y,"ng-show":"showHtml","ta-bind":"ta-bind","ng-model":"html"}),l.displayElements.text.attr({id:"taTextElement"+y,contentEditable:"true","ta-bind":"ta-bind","ng-model":"html"}),l.displayElements.scrollWindow.attr({"ng-hide":"showHtml"}),n.taDefaultWrap&&l.displayElements.text.attr("ta-default-wrap",n.taDefaultWrap),n.taUnsafeSanitizer&&(l.displayElements.text.attr("ta-unsafe-sanitizer",n.taUnsafeSanitizer),l.displayElements.html.attr("ta-unsafe-sanitizer",n.taUnsafeSanitizer)),l.displayElements.scrollWindow.append(l.displayElements.text),m.append(l.displayElements.scrollWindow),m.append(l.displayElements.html),l.displayElements.forminput.attr("name",l._name),m.append(l.displayElements.forminput),n.tabindex&&(m.removeAttr("tabindex"),l.displayElements.text.attr("tabindex",n.tabindex),l.displayElements.html.attr("tabindex",n.tabindex)),n.placeholder&&(l.displayElements.text.attr("placeholder",n.placeholder),l.displayElements.html.attr("placeholder",n.placeholder)),n.taDisabled&&(l.displayElements.text.attr("ta-readonly","disabled"),l.displayElements.html.attr("ta-readonly","disabled"),l.disabled=l.$parent.$eval(n.taDisabled),l.$parent.$watch(n.taDisabled,function(a){l.disabled=a,l.disabled?m.addClass(l.classes.disabled):m.removeClass(l.classes.disabled) -})),a(l.displayElements.scrollWindow)(l),a(l.displayElements.html)(l),l.updateTaBindtaTextElement=l["updateTaBindtaTextElement"+y],l.updateTaBindtaHtmlElement=l["updateTaBindtaHtmlElement"+y],m.addClass("ta-root"),l.displayElements.scrollWindow.addClass("ta-text ta-editor "+l.classes.textEditor),l.displayElements.html.addClass("ta-html ta-editor "+l.classes.htmlEditor),l._actionRunning=!1;var A=!1;if(l.startAction=function(){return l._actionRunning=!0,A=g.rangy.saveSelection(),function(){A&&g.rangy.restoreSelection(A)}},l.endAction=function(){l._actionRunning=!1,A&&g.rangy.removeMarkers(A),A=!1,l.updateSelectedStyles(),l.showHtml||l["updateTaBindtaTextElement"+y]()},t=function(){m.addClass(l.classes.focussed),w.focus()},l.displayElements.html.on("focus",t),l.displayElements.text.on("focus",t),u=function(a){return l._actionRunning||h[0].activeElement===l.displayElements.html[0]||h[0].activeElement===l.displayElements.text[0]||(m.removeClass(l.classes.focussed),w.unfocus(),b(function(){m.triggerHandler("blur")},0)),a.preventDefault(),!1},l.displayElements.html.on("blur",u),l.displayElements.text.on("blur",u),l.queryFormatBlockState=function(a){return!l.showHtml&&a.toLowerCase()===h[0].queryCommandValue("formatBlock").toLowerCase()},l.queryCommandState=function(a){return l.showHtml?"":h[0].queryCommandState(a)},l.switchView=function(){l.showHtml=!l.showHtml,i.enabled(!1,l.displayElements.html),i.enabled(!1,l.displayElements.text),l.showHtml?b(function(){return i.enabled(!0,l.displayElements.html),i.enabled(!0,l.displayElements.text),l.displayElements.html[0].focus()},100):b(function(){return i.enabled(!0,l.displayElements.html),i.enabled(!0,l.displayElements.text),l.displayElements.text[0].focus()},100)},n.ngModel){var B=!0;o.$render=function(){if(B){B=!1;var a=l.$parent.$eval(n.ngModel);void 0!==a&&null!==a||!v||""===v||o.$setViewValue(v)}l.displayElements.forminput.val(o.$viewValue),l._elementSelectTriggered||h[0].activeElement===l.displayElements.html[0]||h[0].activeElement===l.displayElements.text[0]||(l.html=o.$viewValue||"")};var C=function(a){return n.required&&o.$setValidity("required",!(!a||""===a.trim())),a};o.$parsers.push(C),o.$formatters.push(C)}else l.displayElements.forminput.val(v),l.html=v;if(l.$watch("html",function(a,b){a!==b&&(n.ngModel&&o.$viewValue!==a&&o.$setViewValue(a),l.displayElements.forminput.val(a))}),n.taTargetToolbars)w=f.registerEditor(l._name,l,n.taTargetToolbars.split(","));else{var D=angular.element('
          ');n.taToolbar&&D.attr("ta-toolbar",n.taToolbar),n.taToolbarClass&&D.attr("ta-toolbar-class",n.taToolbarClass),n.taToolbarGroupClass&&D.attr("ta-toolbar-group-class",n.taToolbarGroupClass),n.taToolbarButtonClass&&D.attr("ta-toolbar-button-class",n.taToolbarButtonClass),n.taToolbarActiveButtonClass&&D.attr("ta-toolbar-active-button-class",n.taToolbarActiveButtonClass),n.taFocussedClass&&D.attr("ta-focussed-class",n.taFocussedClass),m.prepend(D),a(D)(l.$parent),w=f.registerEditor(l._name,l,["textAngularToolbar"+y])}l.$on("$destroy",function(){f.unregisterEditor(l._name)}),l.$on("ta-element-select",function(a,b){w.triggerElementSelect(a,b)&&l["reApplyOnSelectorHandlerstaTextElement"+y]()}),l.$on("ta-drop-event",function(a,c,d,e){l.displayElements.text[0].focus(),e&&e.files&&e.files.length>0?(angular.forEach(e.files,function(a){try{k.when(l.fileDropHandler(a,l.wrapSelection)||l.fileDropHandler!==l.defaultFileDropHandler&&k.when(l.defaultFileDropHandler(a,l.wrapSelection))).then(function(){l["updateTaBindtaTextElement"+y]()})}catch(b){j.error(b)}}),d.preventDefault(),d.stopPropagation()):b(function(){l["updateTaBindtaTextElement"+y]()},0)}),l._bUpdateSelectedStyles=!1,l.updateSelectedStyles=function(){var a;void 0!==(a=d.getSelectionElement())&&a.parentNode!==l.displayElements.text[0]?w.updateSelectedStyles(angular.element(a)):w.updateSelectedStyles(),l._bUpdateSelectedStyles&&h.hasFocus()?b(l.updateSelectedStyles,200):l._bUpdateSelectedStyles=!1},p=function(){l._bUpdateSelectedStyles||(l._bUpdateSelectedStyles=!0,l.$apply(function(){l.updateSelectedStyles()}))},l.displayElements.html.on("keydown",p),l.displayElements.text.on("keydown",p),q=function(){l._bUpdateSelectedStyles=!1},l.displayElements.html.on("keyup",q),l.displayElements.text.on("keyup",q),r=function(a,b){b&&angular.extend(a,b),l.$apply(function(){return w.sendKeyCommand(a)?(l._bUpdateSelectedStyles||l.updateSelectedStyles(),a.preventDefault(),!1):void 0})},l.displayElements.html.on("keypress",r),l.displayElements.text.on("keypress",r),s=function(){l._bUpdateSelectedStyles=!1,l.$apply(function(){l.updateSelectedStyles()})},l.displayElements.html.on("mouseup",s),l.displayElements.text.on("mouseup",s)}}}]),q.service("textAngularManager",["taToolExecuteAction","taTools","taRegisterTool",function(a,b,c){var d={},e={};return{registerEditor:function(c,f,g){if(!c||""===c)throw"textAngular Error: An editor requires a name";if(!f)throw"textAngular Error: An editor requires a scope";if(e[c])throw'textAngular Error: An Editor with name "'+c+'" already exists';var h=[];return angular.forEach(g,function(a){d[a]&&h.push(d[a])}),e[c]={scope:f,toolbars:g,_registerToolbar:function(a){this.toolbars.indexOf(a.name)>=0&&h.push(a)},editorFunctions:{disable:function(){angular.forEach(h,function(a){a.disabled=!0})},enable:function(){angular.forEach(h,function(a){a.disabled=!1})},focus:function(){angular.forEach(h,function(a){a._parent=f,a.disabled=!1,a.focussed=!0})},unfocus:function(){angular.forEach(h,function(a){a.disabled=!0,a.focussed=!1})},updateSelectedStyles:function(a){angular.forEach(h,function(b){angular.forEach(b.tools,function(c){c.activeState&&(b._parent=f,c.active=c.activeState(a))})})},sendKeyCommand:function(c){var d=!1;return(c.ctrlKey||c.metaKey)&&angular.forEach(b,function(b,e){if(b.commandKeyCode&&b.commandKeyCode===c.which)for(var g=0;g0)for(var k=0;k"),d.addClass(b&&b["class"]?b["class"]:g.classes.toolbarButton),d.attr("name",c.name),d.attr("unselectable","on"),d.attr("ng-disabled","isDisabled()"),d.attr("tabindex","-1"),d.attr("ng-click","executeAction()"),d.attr("ng-class","displayActiveToolClass(active)"),b&&b.tooltiptext&&d.attr("title",b.tooltiptext),d.on("mousedown",function(a,b){return b&&angular.extend(a,b),a.preventDefault(),!1}),b&&!b.display&&!c._display&&(d[0].innerHTML="",b.buttontext&&(d[0].innerHTML=b.buttontext),b.iconclass)){var e=angular.element(""),f=d[0].innerHTML;e.addClass(b.iconclass),d[0].innerHTML="",d.append(e),f&&""!==f&&d.append(" "+f)}return c._lastToolDefinition=angular.copy(b),a(d)(c)};g.tools={},g._parent={disabled:!0,showHtml:!1,queryFormatBlockState:function(){return!1},queryCommandState:function(){return!1}};var k={$window:f,$editor:function(){return g._parent},isDisabled:function(){return"function"!=typeof this.$eval("disabled")&&this.$eval("disabled")||this.$eval("disabled()")||"html"!==this.name&&this.$editor().showHtml||this.$parent.disabled||this.$editor().disabled},displayActiveToolClass:function(a){return a?g.classes.toolbarButtonActive:""},executeAction:e};angular.forEach(g.toolbar,function(a){var b=angular.element("
          ");b.addClass(g.classes.toolbarGroup),angular.forEach(a,function(a){g.tools[a]=angular.extend(g.$new(!0),d[a],k,{name:a}),g.tools[a].$element=j(d[a],g.tools[a]),b.append(g.tools[a].$element)}),h.append(b)}),g.updateToolDisplay=function(a,b,c){var d=g.tools[a];if(d){if(d._lastToolDefinition&&!c&&(b=angular.extend({},d._lastToolDefinition,b)),null===b.buttontext&&null===b.iconclass&&null===b.display)throw'textAngular Error: Tool Definition for updating "'+a+'" does not have a valid display/iconclass/buttontext value';null===b.buttontext&&delete b.buttontext,null===b.iconclass&&delete b.iconclass,null===b.display&&delete b.display;var e=j(b,d);d.$element.replaceWith(e),d.$element=e}},g.addTool=function(a,b,c,e){g.tools[a]=angular.extend(g.$new(!0),d[a],k,{name:a}),g.tools[a].$element=j(d[a],g.tools[a]);var f;void 0===c&&(c=g.toolbar.length-1),f=angular.element(h.children()[c]),void 0===e?(f.append(g.tools[a].$element),g.toolbar[c][g.toolbar[c].length-1]=a):(f.children().eq(e).after(g.tools[a].$element),g.toolbar[c][e]=a)},b.registerToolbar(g),g.$on("$destroy",function(){b.unregisterToolbar(g.name)})}}}])}()}({},function(){return this}()); \ No newline at end of file +})),a(l.displayElements.scrollWindow)(l),a(l.displayElements.html)(l),l.updateTaBindtaTextElement=l["updateTaBindtaTextElement"+y],l.updateTaBindtaHtmlElement=l["updateTaBindtaHtmlElement"+y],m.addClass("ta-root"),l.displayElements.scrollWindow.addClass("ta-text ta-editor "+l.classes.textEditor),l.displayElements.html.addClass("ta-html ta-editor "+l.classes.htmlEditor),l._actionRunning=!1;var A=!1;if(l.startAction=function(){return l._actionRunning=!0,A=g.rangy.saveSelection(),function(){A&&g.rangy.restoreSelection(A)}},l.endAction=function(){l._actionRunning=!1,A&&g.rangy.removeMarkers(A),A=!1,l.updateSelectedStyles(),l.showHtml||l["updateTaBindtaTextElement"+y]()},t=function(){m.addClass(l.classes.focussed),w.focus()},l.displayElements.html.on("focus",t),l.displayElements.text.on("focus",t),u=function(a){return l._actionRunning||h[0].activeElement===l.displayElements.html[0]||h[0].activeElement===l.displayElements.text[0]||(m.removeClass(l.classes.focussed),w.unfocus(),b(function(){m.triggerHandler("blur")},0)),a.preventDefault(),!1},l.displayElements.html.on("blur",u),l.displayElements.text.on("blur",u),l.queryFormatBlockState=function(a){return!l.showHtml&&a.toLowerCase()===h[0].queryCommandValue("formatBlock").toLowerCase()},l.queryCommandState=function(a){return l.showHtml?"":h[0].queryCommandState(a)},l.switchView=function(){l.showHtml=!l.showHtml,i.enabled(!1,l.displayElements.html),i.enabled(!1,l.displayElements.text),l.showHtml?b(function(){return i.enabled(!0,l.displayElements.html),i.enabled(!0,l.displayElements.text),l.displayElements.html[0].focus()},100):b(function(){return i.enabled(!0,l.displayElements.html),i.enabled(!0,l.displayElements.text),l.displayElements.text[0].focus()},100)},n.ngModel){var B=!0;o.$render=function(){if(B){B=!1;var a=l.$parent.$eval(n.ngModel);void 0!==a&&null!==a||!v||""===v||o.$setViewValue(v)}l.displayElements.forminput.val(o.$viewValue),l._elementSelectTriggered||h[0].activeElement===l.displayElements.html[0]||h[0].activeElement===l.displayElements.text[0]||(l.html=o.$viewValue||"")};var C=function(a){return n.required&&o.$setValidity("required",!(!a||""===a.trim())),a};o.$parsers.push(C),o.$formatters.push(C)}else l.displayElements.forminput.val(v),l.html=v;if(l.$watch("html",function(a,b){a!==b&&(n.ngModel&&o.$viewValue!==a&&o.$setViewValue(a),l.displayElements.forminput.val(a))}),n.taTargetToolbars)w=f.registerEditor(l._name,l,n.taTargetToolbars.split(","));else{var D=angular.element('
          ');n.taToolbar&&D.attr("ta-toolbar",n.taToolbar),n.taToolbarClass&&D.attr("ta-toolbar-class",n.taToolbarClass),n.taToolbarGroupClass&&D.attr("ta-toolbar-group-class",n.taToolbarGroupClass),n.taToolbarButtonClass&&D.attr("ta-toolbar-button-class",n.taToolbarButtonClass),n.taToolbarActiveButtonClass&&D.attr("ta-toolbar-active-button-class",n.taToolbarActiveButtonClass),n.taFocussedClass&&D.attr("ta-focussed-class",n.taFocussedClass),m.prepend(D),a(D)(l.$parent),w=f.registerEditor(l._name,l,["textAngularToolbar"+y])}l.$on("$destroy",function(){f.unregisterEditor(l._name)}),l.$on("ta-element-select",function(a,b){w.triggerElementSelect(a,b)&&l["reApplyOnSelectorHandlerstaTextElement"+y]()}),l.$on("ta-drop-event",function(a,c,d,e){l.displayElements.text[0].focus(),e&&e.files&&e.files.length>0?(angular.forEach(e.files,function(a){try{k.when(l.fileDropHandler(a,l.wrapSelection)||l.fileDropHandler!==l.defaultFileDropHandler&&k.when(l.defaultFileDropHandler(a,l.wrapSelection))).then(function(){l["updateTaBindtaTextElement"+y]()})}catch(b){j.error(b)}}),d.preventDefault(),d.stopPropagation()):b(function(){l["updateTaBindtaTextElement"+y]()},0)}),l._bUpdateSelectedStyles=!1,angular.element(window).on("blur",function(){l._bUpdateSelectedStyles=!1}),l.updateSelectedStyles=function(){var a;void 0!==(a=d.getSelectionElement())&&a.parentNode!==l.displayElements.text[0]?w.updateSelectedStyles(angular.element(a)):w.updateSelectedStyles(),l._bUpdateSelectedStyles&&b(l.updateSelectedStyles,200)},p=function(){l._bUpdateSelectedStyles||(l._bUpdateSelectedStyles=!0,l.$apply(function(){l.updateSelectedStyles()}))},l.displayElements.html.on("keydown",p),l.displayElements.text.on("keydown",p),q=function(){l._bUpdateSelectedStyles=!1},l.displayElements.html.on("keyup",q),l.displayElements.text.on("keyup",q),r=function(a,b){b&&angular.extend(a,b),l.$apply(function(){return w.sendKeyCommand(a)?(l._bUpdateSelectedStyles||l.updateSelectedStyles(),a.preventDefault(),!1):void 0})},l.displayElements.html.on("keypress",r),l.displayElements.text.on("keypress",r),s=function(){l._bUpdateSelectedStyles=!1,l.$apply(function(){l.updateSelectedStyles()})},l.displayElements.html.on("mouseup",s),l.displayElements.text.on("mouseup",s)}}}]),q.service("textAngularManager",["taToolExecuteAction","taTools","taRegisterTool",function(a,b,c){var d={},e={};return{registerEditor:function(c,f,g){if(!c||""===c)throw"textAngular Error: An editor requires a name";if(!f)throw"textAngular Error: An editor requires a scope";if(e[c])throw'textAngular Error: An Editor with name "'+c+'" already exists';var h=[];return angular.forEach(g,function(a){d[a]&&h.push(d[a])}),e[c]={scope:f,toolbars:g,_registerToolbar:function(a){this.toolbars.indexOf(a.name)>=0&&h.push(a)},editorFunctions:{disable:function(){angular.forEach(h,function(a){a.disabled=!0})},enable:function(){angular.forEach(h,function(a){a.disabled=!1})},focus:function(){angular.forEach(h,function(a){a._parent=f,a.disabled=!1,a.focussed=!0})},unfocus:function(){angular.forEach(h,function(a){a.disabled=!0,a.focussed=!1})},updateSelectedStyles:function(a){angular.forEach(h,function(b){angular.forEach(b.tools,function(c){c.activeState&&(b._parent=f,c.active=c.activeState(a))})})},sendKeyCommand:function(c){var d=!1;return(c.ctrlKey||c.metaKey)&&angular.forEach(b,function(b,e){if(b.commandKeyCode&&b.commandKeyCode===c.which)for(var g=0;g0)for(var k=0;k"),d.addClass(b&&b["class"]?b["class"]:g.classes.toolbarButton),d.attr("name",c.name),d.attr("unselectable","on"),d.attr("ng-disabled","isDisabled()"),d.attr("tabindex","-1"),d.attr("ng-click","executeAction()"),d.attr("ng-class","displayActiveToolClass(active)"),b&&b.tooltiptext&&d.attr("title",b.tooltiptext),d.on("mousedown",function(a,b){return b&&angular.extend(a,b),a.preventDefault(),!1}),b&&!b.display&&!c._display&&(d[0].innerHTML="",b.buttontext&&(d[0].innerHTML=b.buttontext),b.iconclass)){var e=angular.element(""),f=d[0].innerHTML;e.addClass(b.iconclass),d[0].innerHTML="",d.append(e),f&&""!==f&&d.append(" "+f)}return c._lastToolDefinition=angular.copy(b),a(d)(c)};g.tools={},g._parent={disabled:!0,showHtml:!1,queryFormatBlockState:function(){return!1},queryCommandState:function(){return!1}};var k={$window:f,$editor:function(){return g._parent},isDisabled:function(){return"function"!=typeof this.$eval("disabled")&&this.$eval("disabled")||this.$eval("disabled()")||"html"!==this.name&&this.$editor().showHtml||this.$parent.disabled||this.$editor().disabled},displayActiveToolClass:function(a){return a?g.classes.toolbarButtonActive:""},executeAction:e};angular.forEach(g.toolbar,function(a){var b=angular.element("
          ");b.addClass(g.classes.toolbarGroup),angular.forEach(a,function(a){g.tools[a]=angular.extend(g.$new(!0),d[a],k,{name:a}),g.tools[a].$element=j(d[a],g.tools[a]),b.append(g.tools[a].$element)}),h.append(b)}),g.updateToolDisplay=function(a,b,c){var d=g.tools[a];if(d){if(d._lastToolDefinition&&!c&&(b=angular.extend({},d._lastToolDefinition,b)),null===b.buttontext&&null===b.iconclass&&null===b.display)throw'textAngular Error: Tool Definition for updating "'+a+'" does not have a valid display/iconclass/buttontext value';null===b.buttontext&&delete b.buttontext,null===b.iconclass&&delete b.iconclass,null===b.display&&delete b.display;var e=j(b,d);d.$element.replaceWith(e),d.$element=e}},g.addTool=function(a,b,c,e){g.tools[a]=angular.extend(g.$new(!0),d[a],k,{name:a}),g.tools[a].$element=j(d[a],g.tools[a]);var f;void 0===c&&(c=g.toolbar.length-1),f=angular.element(h.children()[c]),void 0===e?(f.append(g.tools[a].$element),g.toolbar[c][g.toolbar[c].length-1]=a):(f.children().eq(e).after(g.tools[a].$element),g.toolbar[c][e]=a)},b.registerToolbar(g),g.$on("$destroy",function(){b.unregisterToolbar(g.name)})}}}])}()}({},function(){return this}()); \ No newline at end of file diff --git a/lib/main.js b/lib/main.js index 072818ba..370c4de0 100644 --- a/lib/main.js +++ b/lib/main.js @@ -529,6 +529,8 @@ textAngular.directive("textAngular", [ // the following is for applying the active states to the tools that support it scope._bUpdateSelectedStyles = false; + /* istanbul ignore next: browser window/tab leave check */ + angular.element(window).on('blur', function(){ scope._bUpdateSelectedStyles = false; }); // loop through all the tools polling their activeState function if it exists scope.updateSelectedStyles = function(){ var _selection; @@ -538,8 +540,7 @@ textAngular.directive("textAngular", [ }else _toolbars.updateSelectedStyles(); // used to update the active state when a key is held down, ie the left arrow /* istanbul ignore else: browser only check */ - if(scope._bUpdateSelectedStyles && $document.hasFocus()) $timeout(scope.updateSelectedStyles, 200); - else scope._bUpdateSelectedStyles = false; + if(scope._bUpdateSelectedStyles) $timeout(scope.updateSelectedStyles, 200); }; // start updating on keydown _keydown = function(){ diff --git a/src/textAngular.js b/src/textAngular.js index 6fe2b3b3..fe7d6150 100644 --- a/src/textAngular.js +++ b/src/textAngular.js @@ -1977,6 +1977,8 @@ textAngular.directive("textAngular", [ // the following is for applying the active states to the tools that support it scope._bUpdateSelectedStyles = false; + /* istanbul ignore next: browser window/tab leave check */ + angular.element(window).on('blur', function(){ scope._bUpdateSelectedStyles = false; }); // loop through all the tools polling their activeState function if it exists scope.updateSelectedStyles = function(){ var _selection; @@ -1986,8 +1988,7 @@ textAngular.directive("textAngular", [ }else _toolbars.updateSelectedStyles(); // used to update the active state when a key is held down, ie the left arrow /* istanbul ignore else: browser only check */ - if(scope._bUpdateSelectedStyles && $document.hasFocus()) $timeout(scope.updateSelectedStyles, 200); - else scope._bUpdateSelectedStyles = false; + if(scope._bUpdateSelectedStyles) $timeout(scope.updateSelectedStyles, 200); }; // start updating on keydown _keydown = function(){