diff --git a/Gruntfile.js b/Gruntfile.js
index d7d547c7..52a34ede 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -41,8 +41,11 @@ module.exports = function (grunt) {
}
},
karma: {
- unit: {
- options: testConfig('karma.conf.js')
+ jquery: {
+ options: testConfig('karma-jquery.conf.js')
+ },
+ jqlite: {
+ options: testConfig('karma-jqlite.conf.js')
}
},
jshint: {
diff --git a/dist/textAngular.min.js b/dist/textAngular.min.js
index 6fdd1d1e..81f1846d 100644
--- a/dist/textAngular.min.js
+++ b/dist/textAngular.min.js
@@ -1,2 +1,2 @@
-!function(a,b){b["true"]=a;var c={translationStrings:{toggleHTML:"Toggle HTML",insertImage:"Please enter a image URL to insert",insertLink:"Please enter a URL to insert",insertVideo:"Please enter a youtube URL to embed"},selectableElements:["a","img"],customDisplayRenderers:[{selector:"img",customAttribute:"ta-insert-video",renderLogic:function(a){var b=angular.element(""),c=a.prop("attributes");angular.forEach(c,function(a){b.attr(a.name,a.value)}),b.attr("src",b.attr("ta-insert-video")),a.replaceWith(b)}}],options:{toolbar:[["h1","h2","h3","h4","h5","h6","p","pre","quote"],["bold","italics","underline","ul","ol","redo","undo","clear"],["justifyLeft","justifyCenter","justifyRight"],["html","insertImage","insertLink","insertVideo"]],classes:{focussed:"focussed",toolbar:"btn-toolbar",toolbarGroup:"btn-group",toolbarButton:"btn btn-default",toolbarButtonActive:"active",disabled:"disabled",textEditor:"form-control",htmlEditor:"form-control"},setup:{textEditorSetup:function(){},htmlEditorSetup:function(){}},defaultFileDropHandler:function(a,b){var c=new FileReader;return"image"===a.type.substring(0,5)?(c.onload=function(){""!==c.result&&b("insertImage",c.result,!0)},c.readAsDataURL(a),!0):!1}},registerToolsFunction:function(a,b,c){a("html",{buttontext:c.toggleHTML,action:function(){this.$editor().switchView()},activeState:function(){return this.$editor().showHtml}});var d=function(a){return function(){return this.$editor().queryFormatBlockState(a)}},e=function(){return this.$editor().wrapSelection("formatBlock","<"+this.name.toUpperCase()+">")};angular.forEach(["h1","h2","h3","h4","h5","h6"],function(b){a(b.toLowerCase(),{buttontext:b.toUpperCase(),action:e,activeState:d(b.toLowerCase())})}),a("p",{buttontext:"P",action:function(){return this.$editor().wrapSelection("formatBlock","
")},activeState:function(){return this.$editor().queryFormatBlockState("p")}}),a("pre",{buttontext:"pre",action:function(){return this.$editor().wrapSelection("formatBlock","
")},activeState:function(){return this.$editor().queryFormatBlockState("pre")}}),a("ul",{iconclass:"fa fa-list-ul",action:function(){return this.$editor().wrapSelection("insertUnorderedList",null)},activeState:function(){return document.queryCommandState("insertUnorderedList")}}),a("ol",{iconclass:"fa fa-list-ol",action:function(){return this.$editor().wrapSelection("insertOrderedList",null)},activeState:function(){return document.queryCommandState("insertOrderedList")}}),a("quote",{iconclass:"fa fa-quote-right",action:function(){return this.$editor().wrapSelection("formatBlock","")},activeState:function(){return this.$editor().queryFormatBlockState("blockquote")}}),a("undo",{iconclass:"fa fa-undo",action:function(){return this.$editor().wrapSelection("undo",null)}}),a("redo",{iconclass:"fa fa-repeat",action:function(){return this.$editor().wrapSelection("redo",null)}}),a("bold",{iconclass:"fa fa-bold",action:function(){return this.$editor().wrapSelection("bold",null)},activeState:function(){return document.queryCommandState("bold")},commandKeyCode:98}),a("justifyLeft",{iconclass:"fa fa-align-left",action:function(){return this.$editor().wrapSelection("justifyLeft",null)},activeState:function(a){var b=!1;return a&&(b="left"===a.css("text-align")||"left"===a.attr("align")||"right"!==a.css("text-align")&&"center"!==a.css("text-align")&&!document.queryCommandState("justifyRight")&&!document.queryCommandState("justifyCenter")),b=b||document.queryCommandState("justifyLeft")}}),a("justifyRight",{iconclass:"fa fa-align-right",action:function(){return this.$editor().wrapSelection("justifyRight",null)},activeState:function(a){var b=!1;return a&&(b="right"===a.css("text-align")),b=b||document.queryCommandState("justifyRight")}}),a("justifyCenter",{iconclass:"fa fa-align-center",action:function(){return this.$editor().wrapSelection("justifyCenter",null)},activeState:function(a){var b=!1;return a&&(b="center"===a.css("text-align")),b=b||document.queryCommandState("justifyCenter")}}),a("italics",{iconclass:"fa fa-italic",action:function(){return this.$editor().wrapSelection("italic",null)},activeState:function(){return document.queryCommandState("italic")},commandKeyCode:105}),a("underline",{iconclass:"fa fa-underline",action:function(){return this.$editor().wrapSelection("underline",null)},activeState:function(){return document.queryCommandState("underline")},commandKeyCode:117}),a("clear",{iconclass:"fa fa-ban",action:function(a,b){this.$editor().wrapSelection("removeFormat",null);var c=[];if(this.$window.rangy&&this.$window.rangy.getSelection&&1===(c=this.$window.rangy.getSelection().getAllRanges()).length){var d=angular.element(c[0].commonAncestorContainer),e=function(a){a=angular.element(a);var b=a;angular.forEach(a.children(),function(a){var c=angular.element("
");c.html(angular.element(a).html()),b.after(c),b=c}),a.remove()};angular.forEach(d.find("ul"),e),angular.forEach(d.find("ol"),e);var f=this.$editor(),g=function(a){a=angular.element(a),a[0]!==f.displayElements.text[0]&&a.removeAttr("class"),angular.forEach(a.children(),g)};angular.forEach(d,g),"li"!==d[0].tagName.toLowerCase()&&"ol"!==d[0].tagName.toLowerCase()&&"ul"!==d[0].tagName.toLowerCase()&&this.$editor().wrapSelection("formatBlock","")}else this.$editor().wrapSelection("formatBlock","
");b()}});var f=function(a,b,c){var d=function(){c.updateTaBindtaTextElement(),c.hidePopover()};a.preventDefault(),c.displayElements.popover.css("width","375px");var e=c.displayElements.popoverContainer;e.empty();var f=angular.element('
'),g=angular.element('
100% ');g.on("click",function(a){a.preventDefault(),b.css({width:"100%",height:""}),d()});var h=angular.element('
50% ');h.on("click",function(a){a.preventDefault(),b.css({width:"50%",height:""}),d()});var i=angular.element('
25% ');i.on("click",function(a){a.preventDefault(),b.css({width:"25%",height:""}),d()});var j=angular.element('
Reset ');j.on("click",function(a){a.preventDefault(),b.css({width:"",height:""}),d()}),f.append(g),f.append(h),f.append(i),f.append(j),e.append(f),f=angular.element('
');var k=angular.element('
');k.on("click",function(a){a.preventDefault(),b.css("float","left"),d()});var l=angular.element('
');l.on("click",function(a){a.preventDefault(),b.css("float","right"),d()});var m=angular.element('
');m.on("click",function(a){a.preventDefault(),b.css("float",""),d()}),f.append(k),f.append(m),f.append(l),e.append(f),f=angular.element('
');var n=angular.element('
');n.on("click",function(a){a.preventDefault(),b.remove(),d()}),f.append(n),e.append(f),c.showPopover(b)};a("insertImage",{iconclass:"fa fa-picture-o",action:function(){var a;return a=b.prompt(c.insertImage,"http://"),a&&""!==a&&"http://"!==a?this.$editor().wrapSelection("insertImage",a,!0):void 0},onElementSelect:{element:"img",action:f}}),a("insertVideo",{iconclass:"fa fa-youtube-play",action:function(){var a;if(a=b.prompt(c.insertVideo,"http://"),a&&""!==a&&"http://"!==a){var d=a.match(/(\?|&)v=[^&]*/);if(d.length>0){var e="http://www.youtube.com/embed/"+d[0].substring(3),f='
';return this.$editor().wrapSelection("insertHTML",f,!0)}}},onElementSelect:{element:"img",onlyWithAttrs:["ta-insert-video"],action:f}}),a("insertLink",{iconclass:"fa fa-link",action:function(){var a;return a=b.prompt(c.insertLink,"http://"),a&&""!==a&&"http://"!==a?this.$editor().wrapSelection("createLink",a,!0):void 0},activeState:function(a){return a?"A"===a[0].tagName:!1},onElementSelect:{element:"a",action:function(a,d,e){a.preventDefault(),e.displayElements.popover.css("width","305px");var f=e.displayElements.popoverContainer;f.empty(),f.css("line-height","28px");var g=angular.element('
'+d.attr("href")+" ");g.css({display:"inline-block","max-width":"200px",overflow:"hidden","text-overflow":"ellipsis","white-space":"nowrap","vertical-align":"middle"}),f.append(g);var h=angular.element('
'),i=angular.element('
');i.on("click",function(a){a.preventDefault();var f=b.prompt(c.insertLink,d.attr("href"));""!==f&&(d.attr("href",f),e.updateTaBindtaTextElement()),e.hidePopover()}),h.append(i);var j=angular.element('
');j.on("click",function(a){a.preventDefault(),d.replaceWith(d.contents()),e.updateTaBindtaTextElement(),e.hidePopover()}),h.append(j),f.append(h),e.showPopover(d)}}})}};!function(){"Use Strict";function a(a,b){var c=Math.max(g.rules.length-1,0);return g.insertRule?g.insertRule(a+"{"+b+"}",c):g.addRule(a,b,c),c}function b(a){g.removeRule?g.removeRule(a):g.deleteRule(a)}function d(a,b){var c=[],e=a.children();return e.length&&angular.forEach(e,function(a){c=c.concat(d(angular.element(a),b))}),void 0!==a.attr(b)&&c.push(a),c}function e(a,b){if(!a||""===a||j.hasOwnProperty(a))throw"textAngular Error: A unique name is required for a Tool Definition";if(b.display&&(""===b.display||0===angular.element(b.display).length)||!b.display&&!b.buttontext&&!b.iconclass)throw'textAngular Error: Tool Definition for "'+a+'" does not have a valid display/iconclass/buttontext value';j[a]=b}var f=function(){var a,b=-1,c=window.navigator.userAgent,d=c.indexOf("MSIE "),e=c.indexOf("Trident/");if(d>0)b=parseInt(c.substring(d+5,c.indexOf(".",d)),10);else if(e>0){var f=c.indexOf("rv:");b=parseInt(c.substring(f+3,c.indexOf(".",f)),10)}return b>-1?b:a}(),g=function(){var a=document.createElement("style");return a.appendChild(document.createTextNode("")),document.head.appendChild(a),a.sheet}(),h=!1,i=angular.module("textAngular",["ngSanitize"]);if(void 0===c)throw"textAngular Error: Setup Options are not defined, see textAngularSetup.js for example.";i.value("taOptions",c.options),i.value("taSelectableElements",c.selectableElements),i.value("taCustomRenderers",c.customDisplayRenderers);var j={};i.constant("taTranslations",c.translationStrings),i.constant("taRegisterTool",e),i.value("taTools",j),i.run(["taRegisterTool","$window","taTranslations",function(a,b,d){angular.forEach(j,function(a,b){delete j[b]}),c.registerToolsFunction(a,b,d)}]),i.directive("textAngular",["$compile","$timeout","taOptions","taSanitize","textAngularManager","$window","$animate","$log",function(a,b,c,d,e,f,g,h){return{require:"?ngModel",scope:{},restrict:"EA",link:function(d,i,j,k){var l,m,n,o,p,q,r,s,t=Math.floor(1e16*Math.random()),u=j.name?j.name:"textAngularEditor"+t;angular.extend(d,angular.copy(c),{wrapSelection:function(a,b,c){try{document.execCommand(a,!1,b)}catch(e){}c&&d["reApplyOnSelectorHandlerstaTextElement"+t](),d.displayElements.text[0].focus()},showHtml:!1}),j.taFocussedClass&&(d.classes.focussed=j.taFocussedClass),j.taTextEditorClass&&(d.classes.textEditor=j.taTextEditorClass),j.taHtmlEditorClass&&(d.classes.htmlEditor=j.taHtmlEditorClass),j.taTextEditorSetup&&(d.setup.textEditorSetup=d.$parent.$eval(j.taTextEditorSetup)),j.taHtmlEditorSetup&&(d.setup.htmlEditorSetup=d.$parent.$eval(j.taHtmlEditorSetup)),d.fileDropHandler=j.taFileDrop?d.$parent.$eval(j.taFileDrop):d.defaultFileDropHandler,r=i[0].innerHTML,i[0].innerHTML="",d.displayElements={forminput:angular.element("
"),html:angular.element("
"),text:angular.element("
"),popover:angular.element('
'),popoverContainer:angular.element('
')},d.displayElements.popover.append(d.displayElements.popoverContainer),i.append(d.displayElements.popover),d.displayElements.popover.on("mousedown",function(a){return a.preventDefault(),!1}),d.showPopover=function(a){d.displayElements.popover.css("top",a[0].offsetTop+a[0].offsetHeight+"px"),d.displayElements.popover.css("left",a[0].offsetLeft+a[0].offsetWidth/2-152.5+"px"),d.displayElements.popover.css("display","block"),g.addClass(d.displayElements.popover,"in"),b(function(){d.displayElements.html.parent().one("click",d.hidePopover)},100)},d.hidePopover=function(){g.removeClass(d.displayElements.popover,"in",function(){d.displayElements.popover.css("display",""),d.displayElements.popoverContainer.attr("style",""),d.displayElements.popoverContainer.attr("class","popover-content")})},d.setup.htmlEditorSetup(d.displayElements.html),d.setup.textEditorSetup(d.displayElements.text),d.displayElements.html.attr({id:"taHtmlElement"+t,"ng-show":"showHtml","ta-bind":"ta-bind","ng-model":"html"}),d.displayElements.text.attr({id:"taTextElement"+t,contentEditable:"true","ng-hide":"showHtml","ta-bind":"ta-bind","ng-model":"html"}),j.taDefaultWrap&&d.displayElements.text.attr("ta-default-wrap",j.taDefaultWrap),i.append(d.displayElements.text),i.append(d.displayElements.html),d.displayElements.forminput.attr("name",u),i.append(d.displayElements.forminput),j.tabindex&&(i.removeAttr("tabindex"),d.displayElements.text.attr("tabindex",j.tabindex),d.displayElements.html.attr("tabindex",j.tabindex)),j.placeholder&&(d.displayElements.text.attr("placeholder",j.placeholder),d.displayElements.html.attr("placeholder",j.placeholder)),j.taDisabled&&(d.displayElements.text.attr("ta-readonly","disabled"),d.displayElements.html.attr("ta-readonly","disabled"),d.disabled=d.$parent.$eval(j.taDisabled),d.$parent.$watch(j.taDisabled,function(a){d.disabled=a,d.disabled?i.addClass(d.classes.disabled):i.removeClass(d.classes.disabled)})),a(d.displayElements.text)(d),a(d.displayElements.html)(d),d.updateTaBindtaTextElement=d["updateTaBindtaTextElement"+t],d.updateTaBindtaHtmlElement=d["updateTaBindtaHtmlElement"+t],i.addClass("ta-root"),d.displayElements.text.addClass("ta-text ta-editor "+d.classes.textEditor),d.displayElements.html.addClass("ta-html ta-editor "+d.classes.textEditor),d._actionRunning=!1;var v=!1;if(d.startAction=function(){return d._actionRunning=!0,f.rangy&&f.rangy.saveSelection?(v=f.rangy.saveSelection(),function(){v&&f.rangy.restoreSelection(v)}):void 0},d.endAction=function(){d._actionRunning=!1,v&&f.rangy.removeMarkers(v),v=!1,d.updateSelectedStyles(),d.showHtml||d["updateTaBindtaTextElement"+t]()},p=function(){i.addClass(d.classes.focussed),s.focus()},d.displayElements.html.on("focus",p),d.displayElements.text.on("focus",p),q=function(a){return d._actionRunning||document.activeElement===d.displayElements.html[0]||document.activeElement===d.displayElements.text[0]||(i.removeClass(d.classes.focussed),s.unfocus(),b(function(){i.triggerHandler("blur")},0)),a.preventDefault(),!1},d.displayElements.html.on("blur",q),d.displayElements.text.on("blur",q),d.queryFormatBlockState=function(a){return a.toLowerCase()===document.queryCommandValue("formatBlock").toLowerCase()},d.switchView=function(){d.showHtml=!d.showHtml,d.showHtml?b(function(){return d.displayElements.html[0].focus()},100):b(function(){return d.displayElements.text[0].focus()},100)},j.ngModel){var w=!0;k.$render=function(){if(w){w=!1;var a=d.$parent.$eval(j.ngModel);void 0!==a&&null!==a||!r||""===r||k.$setViewValue(r)}d.displayElements.forminput.val(k.$viewValue),d._elementSelectTriggered||document.activeElement===d.displayElements.html[0]||document.activeElement===d.displayElements.text[0]||(d.html=k.$viewValue||"")}}else d.displayElements.forminput.val(r),d.html=r;if(d.$watch("html",function(a,b){a!==b&&(j.ngModel&&k.$viewValue!==a&&k.$setViewValue(a),d.displayElements.forminput.val(a))}),j.taTargetToolbars)s=e.registerEditor(u,d,j.taTargetToolbars.split(","));else{var x=angular.element('
');j.taToolbar&&x.attr("ta-toolbar",j.taToolbar),j.taToolbarClass&&x.attr("ta-toolbar-class",j.taToolbarClass),j.taToolbarGroupClass&&x.attr("ta-toolbar-group-class",j.taToolbarGroupClass),j.taToolbarButtonClass&&x.attr("ta-toolbar-button-class",j.taToolbarButtonClass),j.taToolbarActiveButtonClass&&x.attr("ta-toolbar-active-button-class",j.taToolbarActiveButtonClass),j.taFocussedClass&&x.attr("ta-focussed-class",j.taFocussedClass),i.prepend(x),a(x)(d.$parent),s=e.registerEditor(u,d,["textAngularToolbar"+t])}d.$on("$destroy",function(){e.unregisterEditor(u)}),d.$on("ta-element-select",function(a,b){s.triggerElementSelect(a,b)}),d.$on("ta-drop-event",function(a,b,c,e){d.displayElements.text[0].focus(),e&&e.files&&e.files.length>0&&(angular.forEach(e.files,function(a){try{return d.fileDropHandler(a,d.wrapSelection)||d.fileDropHandler!==d.defaultFileDropHandler&&d.defaultFileDropHandler(a,d.wrapSelection)}catch(b){h.error(b)}}),c.preventDefault(),c.stopPropagation())}),d._bUpdateSelectedStyles=!1,d.updateSelectedStyles=function(){var a;f.rangy&&f.rangy.getSelection&&1===(a=f.rangy.getSelection().getAllRanges()).length&&a[0].commonAncestorContainer.parentNode!==d.displayElements.text[0]?s.updateSelectedStyles(angular.element(a[0].commonAncestorContainer.parentNode)):s.updateSelectedStyles(),d._bUpdateSelectedStyles&&b(d.updateSelectedStyles,200)},l=function(){d._bUpdateSelectedStyles||(d._bUpdateSelectedStyles=!0,d.$apply(function(){d.updateSelectedStyles()}))},d.displayElements.html.on("keydown",l),d.displayElements.text.on("keydown",l),m=function(){d._bUpdateSelectedStyles=!1},d.displayElements.html.on("keyup",m),d.displayElements.text.on("keyup",m),n=function(a){d.$apply(function(){return s.sendKeyCommand(a)?(d._bUpdateSelectedStyles||d.updateSelectedStyles(),a.preventDefault(),!1):void 0})},d.displayElements.html.on("keypress",n),d.displayElements.text.on("keypress",n),o=function(){d._bUpdateSelectedStyles=!1,d.$apply(function(){d.updateSelectedStyles()})},d.displayElements.html.on("mouseup",o),d.displayElements.text.on("mouseup",o)}}}]).directive("taBind",["taSanitize","$timeout","$window","taFixChrome","taSelectableElements","taApplyCustomRenderers",function(c,d,e,g,i,j){return{require:"ngModel",scope:{},link:function(k,l,m,n){var o,p=void 0!==l.attr("contenteditable")&&l.attr("contenteditable"),q=p||"textarea"===l[0].tagName.toLowerCase()||"input"===l[0].tagName.toLowerCase(),r=!1,s=!1;void 0===m.taDefaultWrap&&(m.taDefaultWrap="p"),o=""===m.taDefaultWrap?"":void 0===f?"<"+m.taDefaultWrap+">
"+m.taDefaultWrap+">":"<"+m.taDefaultWrap+">"+m.taDefaultWrap+">";var t=function(){if(p)return l[0].innerHTML;if(q)return l.val();throw"textAngular Error: attempting to update non-editable taBind"};if(k.$parent["updateTaBind"+(m.id||"")]=function(){r||n.$setViewValue(t())},q)if(p){if(l.on("cut",function(a){r?a.preventDefault():d(function(){n.$setViewValue(t())},0)}),l.on("paste",function(a){var b;if(a.clipboardData||a.originalEvent&&a.originalEvent.clipboardData?b=(a.originalEvent||a).clipboardData.getData("text/plain"):e.clipboardData&&(b=e.clipboardData.getData("Text")),!b&&!r)return!0;if(a.preventDefault(),!r){var c=angular.element("
");c[0].innerHTML=b,b=c.text(),document.execCommand("insertText",!1,b),n.$setViewValue(t())}}),l.on("keyup",function(){r||n.$setViewValue(t())}),l.on("blur",function(){s=!1;var a=t();r||n.$setViewValue(a===o?"":t()),n.$render()}),m.placeholder){var u;if(!m.id)throw"textAngular Error: An unique ID is required for placeholders to work";u=a("#"+m.id+".placeholder-text:before",'content: "'+m.placeholder+'"'),k.$on("$destroy",function(){b(u)})}l.on("focus",function(){s=!0,n.$render()})}else l.on("paste cut",function(){r||d(function(){n.$setViewValue(t())},0)}),l.on("change blur",function(){r||n.$setViewValue(t())});var v=function(a){return n.$oldViewValue=c(g(a),n.$oldViewValue)};n.$parsers.push(v),n.$formatters.push(v);var w=function(a){return k.$emit("ta-element-select",this),a.preventDefault(),!1},x=function(a){if(!h){h=!0;var b;b=a.originalEvent?a.originalEvent.dataTransfer:a.dataTransfer,k.$emit("ta-drop-event",this,a,b),d(function(){h=!1},100)}};k.$parent["reApplyOnSelectorHandlers"+(m.id||"")]=function(){r||angular.forEach(i,function(a){l.find(a).off("click",w).on("click",w)})},n.$render=function(){var a=n.$viewValue||"";document.activeElement!==l[0]?p?(m.placeholder?""===a?(s?l.removeClass("placeholder-text"):l.addClass("placeholder-text"),l[0].innerHTML=o):(l.removeClass("placeholder-text"),l[0].innerHTML=a):l[0].innerHTML=""===a?o:a,r?l.off("drop",x):(angular.forEach(i,function(a){l.find(a).on("click",w)}),l.on("drop",x))):"textarea"!==l[0].tagName.toLowerCase()&&"input"!==l[0].tagName.toLowerCase()?l[0].innerHTML=j(a):l.val(a):p&&l.removeClass("placeholder-text")},m.taReadonly&&(r=k.$parent.$eval(m.taReadonly),r?(("textarea"===l[0].tagName.toLowerCase()||"input"===l[0].tagName.toLowerCase())&&l.attr("disabled","disabled"),void 0!==l.attr("contenteditable")&&l.attr("contenteditable")&&l.removeAttr("contenteditable")):"textarea"===l[0].tagName.toLowerCase()||"input"===l[0].tagName.toLowerCase()?l.removeAttr("disabled"):p&&l.attr("contenteditable","true"),k.$parent.$watch(m.taReadonly,function(a,b){b!==a&&(a?(("textarea"===l[0].tagName.toLowerCase()||"input"===l[0].tagName.toLowerCase())&&l.attr("disabled","disabled"),void 0!==l.attr("contenteditable")&&l.attr("contenteditable")&&l.removeAttr("contenteditable"),angular.forEach(i,function(a){l.find(a).on("click",w)}),l.off("drop",x)):("textarea"===l[0].tagName.toLowerCase()||"input"===l[0].tagName.toLowerCase()?l.removeAttr("disabled"):p&&l.attr("contenteditable","true"),angular.forEach(i,function(a){l.find(a).off("click",w)}),l.on("drop",x)),r=a)})),p&&!r&&(angular.forEach(i,function(a){l.find(a).on("click",w)}),l.on("drop",x))}}}]).factory("taApplyCustomRenderers",["taCustomRenderers",function(a){return function(b){var c=angular.element("
");return c[0].innerHTML=b,angular.forEach(a,function(a){var b=[];a.selector&&""!==a.selector?b=c.find(a.selector):a.customAttribute&&""!==a.customAttribute&&(b=d(c,a.customAttribute)),angular.forEach(b,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)})}),c[0].innerHTML}}]).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)}}}).factory("taFixChrome",function(){var a=function(a){for(var b=angular.element("
"+a+"
"),c=angular.element(b).find("span"),d=0;d
0&&"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){return function(b,c){var e=angular.element(""+b+"
");angular.forEach(d(e,"align"),function(a){a.css("text-align",a.attr("align")),a.removeAttr("align")}),b=e[0].innerHTML;var f;try{f=a(b)}catch(g){f=c||""}return f}}]).directive("textAngularToolbar",["$compile","textAngularManager","taOptions","taTools","taToolExecuteAction","$window",function(a,b,c,d,e,f){return{scope:{name:"@"},restrict:"EA",link:function(g,h,i){if(!g.name||""===g.name)throw"textAngular Error: A toolbar requires a name";angular.extend(g,angular.copy(c)),i.taToolbar&&(g.toolbar=g.$parent.$eval(i.taToolbar)),i.taToolbarClass&&(g.classes.toolbar=i.taToolbarClass),i.taToolbarGroupClass&&(g.classes.toolbarGroup=i.taToolbarGroupClass),i.taToolbarButtonClass&&(g.classes.toolbarButton=i.taToolbarButtonClass),i.taToolbarActiveButtonClass&&(g.classes.toolbarButtonActive=i.taToolbarActiveButtonClass),i.taFocussedClass&&(g.classes.focussed=i.taFocussedClass),g.disabled=!0,g.focussed=!1,g._$element=h,h[0].innerHTML="",h.addClass("ta-toolbar "+g.classes.toolbar),g.$watch("focussed",function(){g.focussed?h.addClass(g.classes.focussed):h.removeClass(g.classes.focussed)});var j=function(b,c){var d;if(d=angular.element(b&&b.display?b.display:""),d.addClass(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)"),d.on("mousedown",function(a){return 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}};var k={$window:f,$editor:function(){return g._parent},isDisabled:function(){return 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)})}}}]).service("taToolExecuteAction",["$q",function(a){return function(b){void 0!==b&&(this.$editor=function(){return b});var c=a.defer(),d=c.promise,e=this.$editor();d["finally"](function(){e.endAction.call(e)});var f;try{f=this.action(c,e.startAction())}catch(g){}(f||void 0===f)&&c.resolve()}}]).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(b){b.activeState&&(b.active=b.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;g
0)for(var k=e[0].tool,l=e[0].name,m=0;m"),c=a.prop("attributes");angular.forEach(c,function(a){b.attr(a.name,a.value)}),b.attr("src",b.attr("ta-insert-video")),a.replaceWith(b)}}],options:{toolbar:[["h1","h2","h3","h4","h5","h6","p","pre","quote"],["bold","italics","underline","ul","ol","redo","undo","clear"],["justifyLeft","justifyCenter","justifyRight"],["html","insertImage","insertLink","insertVideo"]],classes:{focussed:"focussed",toolbar:"btn-toolbar",toolbarGroup:"btn-group",toolbarButton:"btn btn-default",toolbarButtonActive:"active",disabled:"disabled",textEditor:"form-control",htmlEditor:"form-control"},setup:{textEditorSetup:function(){},htmlEditorSetup:function(){}},defaultFileDropHandler:function(a,b){var c=new FileReader;return"image"===a.type.substring(0,5)?(c.onload=function(){""!==c.result&&b("insertImage",c.result,!0)},c.readAsDataURL(a),!0):!1}},registerToolsFunction:function(a,b,c){a("html",{buttontext:c.toggleHTML,action:function(){this.$editor().switchView()},activeState:function(){return this.$editor().showHtml}});var d=function(a){return function(){return this.$editor().queryFormatBlockState(a)}},e=function(){return this.$editor().wrapSelection("formatBlock","<"+this.name.toUpperCase()+">")};angular.forEach(["h1","h2","h3","h4","h5","h6"],function(b){a(b.toLowerCase(),{buttontext:b.toUpperCase(),action:e,activeState:d(b.toLowerCase())})}),a("p",{buttontext:"P",action:function(){return this.$editor().wrapSelection("formatBlock","")},activeState:function(){return this.$editor().queryFormatBlockState("p")}}),a("pre",{buttontext:"pre",action:function(){return this.$editor().wrapSelection("formatBlock","
")},activeState:function(){return this.$editor().queryFormatBlockState("pre")}}),a("ul",{iconclass:"fa fa-list-ul",action:function(){return this.$editor().wrapSelection("insertUnorderedList",null)},activeState:function(){return document.queryCommandState("insertUnorderedList")}}),a("ol",{iconclass:"fa fa-list-ol",action:function(){return this.$editor().wrapSelection("insertOrderedList",null)},activeState:function(){return document.queryCommandState("insertOrderedList")}}),a("quote",{iconclass:"fa fa-quote-right",action:function(){return this.$editor().wrapSelection("formatBlock","")},activeState:function(){return this.$editor().queryFormatBlockState("blockquote")}}),a("undo",{iconclass:"fa fa-undo",action:function(){return this.$editor().wrapSelection("undo",null)}}),a("redo",{iconclass:"fa fa-repeat",action:function(){return this.$editor().wrapSelection("redo",null)}}),a("bold",{iconclass:"fa fa-bold",action:function(){return this.$editor().wrapSelection("bold",null)},activeState:function(){return document.queryCommandState("bold")},commandKeyCode:98}),a("justifyLeft",{iconclass:"fa fa-align-left",action:function(){return this.$editor().wrapSelection("justifyLeft",null)},activeState:function(a){var b=!1;return a&&(b="left"===a.css("text-align")||"left"===a.attr("align")||"right"!==a.css("text-align")&&"center"!==a.css("text-align")&&!document.queryCommandState("justifyRight")&&!document.queryCommandState("justifyCenter")),b=b||document.queryCommandState("justifyLeft")}}),a("justifyRight",{iconclass:"fa fa-align-right",action:function(){return this.$editor().wrapSelection("justifyRight",null)},activeState:function(a){var b=!1;return a&&(b="right"===a.css("text-align")),b=b||document.queryCommandState("justifyRight")}}),a("justifyCenter",{iconclass:"fa fa-align-center",action:function(){return this.$editor().wrapSelection("justifyCenter",null)},activeState:function(a){var b=!1;return a&&(b="center"===a.css("text-align")),b=b||document.queryCommandState("justifyCenter")}}),a("italics",{iconclass:"fa fa-italic",action:function(){return this.$editor().wrapSelection("italic",null)},activeState:function(){return document.queryCommandState("italic")},commandKeyCode:105}),a("underline",{iconclass:"fa fa-underline",action:function(){return this.$editor().wrapSelection("underline",null)},activeState:function(){return document.queryCommandState("underline")},commandKeyCode:117}),a("clear",{iconclass:"fa fa-ban",action:function(a,b){this.$editor().wrapSelection("removeFormat",null);var c=[];if(this.$window.rangy&&this.$window.rangy.getSelection&&1===(c=this.$window.rangy.getSelection().getAllRanges()).length){var d=angular.element(c[0].commonAncestorContainer),e=function(a){a=angular.element(a);var b=a;angular.forEach(a.children(),function(a){var c=angular.element("
");c.html(angular.element(a).html()),b.after(c),b=c}),a.remove()};angular.forEach(d.find("ul"),e),angular.forEach(d.find("ol"),e);var f=this.$editor(),g=function(a){a=angular.element(a),a[0]!==f.displayElements.text[0]&&a.removeAttr("class"),angular.forEach(a.children(),g)};angular.forEach(d,g),"li"!==d[0].tagName.toLowerCase()&&"ol"!==d[0].tagName.toLowerCase()&&"ul"!==d[0].tagName.toLowerCase()&&this.$editor().wrapSelection("formatBlock","")}else this.$editor().wrapSelection("formatBlock","
");b()}});var f=function(a,b,c){var d=function(){c.updateTaBindtaTextElement(),c.hidePopover()};a.preventDefault(),c.displayElements.popover.css("width","375px");var e=c.displayElements.popoverContainer;e.empty();var f=angular.element('
'),g=angular.element('
100% ');g.on("click",function(a){a.preventDefault(),b.css({width:"100%",height:""}),d()});var h=angular.element('
50% ');h.on("click",function(a){a.preventDefault(),b.css({width:"50%",height:""}),d()});var i=angular.element('
25% ');i.on("click",function(a){a.preventDefault(),b.css({width:"25%",height:""}),d()});var j=angular.element('
Reset ');j.on("click",function(a){a.preventDefault(),b.css({width:"",height:""}),d()}),f.append(g),f.append(h),f.append(i),f.append(j),e.append(f),f=angular.element('
');var k=angular.element('
');k.on("click",function(a){a.preventDefault(),b.css("float","left"),d()});var l=angular.element('
');l.on("click",function(a){a.preventDefault(),b.css("float","right"),d()});var m=angular.element('
');m.on("click",function(a){a.preventDefault(),b.css("float",""),d()}),f.append(k),f.append(m),f.append(l),e.append(f),f=angular.element('
');var n=angular.element('
');n.on("click",function(a){a.preventDefault(),b.remove(),d()}),f.append(n),e.append(f),c.showPopover(b)};a("insertImage",{iconclass:"fa fa-picture-o",action:function(){var a;return a=b.prompt(c.insertImage,"http://"),a&&""!==a&&"http://"!==a?this.$editor().wrapSelection("insertImage",a,!0):void 0},onElementSelect:{element:"img",action:f}}),a("insertVideo",{iconclass:"fa fa-youtube-play",action:function(){var a;if(a=b.prompt(c.insertVideo,"http://"),a&&""!==a&&"http://"!==a){var d=a.match(/(\?|&)v=[^&]*/);if(d.length>0){var e="http://www.youtube.com/embed/"+d[0].substring(3),f='
';return this.$editor().wrapSelection("insertHTML",f,!0)}}},onElementSelect:{element:"img",onlyWithAttrs:["ta-insert-video"],action:f}}),a("insertLink",{iconclass:"fa fa-link",action:function(){var a;return a=b.prompt(c.insertLink,"http://"),a&&""!==a&&"http://"!==a?this.$editor().wrapSelection("createLink",a,!0):void 0},activeState:function(a){return a?"A"===a[0].tagName:!1},onElementSelect:{element:"a",action:function(a,d,e){a.preventDefault(),e.displayElements.popover.css("width","305px");var f=e.displayElements.popoverContainer;f.empty(),f.css("line-height","28px");var g=angular.element('
'+d.attr("href")+" ");g.css({display:"inline-block","max-width":"200px",overflow:"hidden","text-overflow":"ellipsis","white-space":"nowrap","vertical-align":"middle"}),f.append(g);var h=angular.element('
'),i=angular.element('
');i.on("click",function(a){a.preventDefault();var f=b.prompt(c.insertLink,d.attr("href"));""!==f&&(d.attr("href",f),e.updateTaBindtaTextElement()),e.hidePopover()}),h.append(i);var j=angular.element('
');j.on("click",function(a){a.preventDefault(),d.replaceWith(d.contents()),e.updateTaBindtaTextElement(),e.hidePopover()}),h.append(j),f.append(h),e.showPopover(d)}}})}};!function(){"Use Strict";function a(a){try{return 0!==angular.element(a).length}catch(b){return!1}}function b(a,b){var c=Math.max(h.rules.length-1,0);return h.insertRule?h.insertRule(a+"{"+b+"}",c):h.addRule(a,b,c),c}function d(a){h.removeRule?h.removeRule(a):h.deleteRule(a)}function e(a,b){var c=[],d=a.children();return d.length&&angular.forEach(d,function(a){c=c.concat(e(angular.element(a),b))}),void 0!==a.attr(b)&&c.push(a),c}function f(b,c){if(!b||""===b||k.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';k[b]=c}var g=function(){var a,b=-1,c=window.navigator.userAgent,d=c.indexOf("MSIE "),e=c.indexOf("Trident/");if(d>0)b=parseInt(c.substring(d+5,c.indexOf(".",d)),10);else if(e>0){var f=c.indexOf("rv:");b=parseInt(c.substring(f+3,c.indexOf(".",f)),10)}return b>-1?b:a}(),h=function(){var a=document.createElement("style");return a.appendChild(document.createTextNode("")),document.head.appendChild(a),a.sheet}(),i=!1,j=angular.module("textAngular",["ngSanitize"]);if(void 0===c)throw"textAngular Error: Setup Options are not defined, see textAngularSetup.js for example.";j.value("taOptions",c.options),j.value("taSelectableElements",c.selectableElements),j.value("taCustomRenderers",c.customDisplayRenderers);var k={};j.constant("taTranslations",c.translationStrings),j.constant("taRegisterTool",f),j.value("taTools",k),j.run(["taRegisterTool","$window","taTranslations",function(a,b,d){angular.forEach(k,function(a,b){delete k[b]}),c.registerToolsFunction(a,b,d)}]),j.directive("textAngular",["$compile","$timeout","taOptions","taSanitize","textAngularManager","$window","$animate","$log",function(a,b,c,d,e,f,g,h){return{require:"?ngModel",scope:{},restrict:"EA",link:function(d,i,j,k){var l,m,n,o,p,q,r,s,t=Math.floor(1e16*Math.random()),u=j.name?j.name:"textAngularEditor"+t;angular.extend(d,angular.copy(c),{wrapSelection:function(a,b,c){try{document.execCommand(a,!1,b)}catch(e){}c&&d["reApplyOnSelectorHandlerstaTextElement"+t](),d.displayElements.text[0].focus()},showHtml:!1}),j.taFocussedClass&&(d.classes.focussed=j.taFocussedClass),j.taTextEditorClass&&(d.classes.textEditor=j.taTextEditorClass),j.taHtmlEditorClass&&(d.classes.htmlEditor=j.taHtmlEditorClass),j.taTextEditorSetup&&(d.setup.textEditorSetup=d.$parent.$eval(j.taTextEditorSetup)),j.taHtmlEditorSetup&&(d.setup.htmlEditorSetup=d.$parent.$eval(j.taHtmlEditorSetup)),d.fileDropHandler=j.taFileDrop?d.$parent.$eval(j.taFileDrop):d.defaultFileDropHandler,r=i[0].innerHTML,i[0].innerHTML="",d.displayElements={forminput:angular.element("
"),html:angular.element("
"),text:angular.element("
"),popover:angular.element('
'),popoverContainer:angular.element('
')},d.displayElements.popover.append(d.displayElements.popoverContainer),i.append(d.displayElements.popover),d.displayElements.popover.on("mousedown",function(a,b){return b&&angular.extend(a,b),a.preventDefault(),!1}),d.showPopover=function(a){d.displayElements.popover.css("top",a[0].offsetTop+a[0].offsetHeight+"px"),d.displayElements.popover.css("left",a[0].offsetLeft+a[0].offsetWidth/2-152.5+"px"),d.displayElements.popover.css("display","block"),g.addClass(d.displayElements.popover,"in"),b(function(){var a=function(){i.off("click",a),d.hidePopover()};i.on("click",a)},100)},d.hidePopover=function(){g.removeClass(d.displayElements.popover,"in",function(){d.displayElements.popover.css("display",""),d.displayElements.popoverContainer.attr("style",""),d.displayElements.popoverContainer.attr("class","popover-content")})},d.setup.htmlEditorSetup(d.displayElements.html),d.setup.textEditorSetup(d.displayElements.text),d.displayElements.html.attr({id:"taHtmlElement"+t,"ng-show":"showHtml","ta-bind":"ta-bind","ng-model":"html"}),d.displayElements.text.attr({id:"taTextElement"+t,contentEditable:"true","ng-hide":"showHtml","ta-bind":"ta-bind","ng-model":"html"}),j.taDefaultWrap&&d.displayElements.text.attr("ta-default-wrap",j.taDefaultWrap),i.append(d.displayElements.text),i.append(d.displayElements.html),d.displayElements.forminput.attr("name",u),i.append(d.displayElements.forminput),j.tabindex&&(i.removeAttr("tabindex"),d.displayElements.text.attr("tabindex",j.tabindex),d.displayElements.html.attr("tabindex",j.tabindex)),j.placeholder&&(d.displayElements.text.attr("placeholder",j.placeholder),d.displayElements.html.attr("placeholder",j.placeholder)),j.taDisabled&&(d.displayElements.text.attr("ta-readonly","disabled"),d.displayElements.html.attr("ta-readonly","disabled"),d.disabled=d.$parent.$eval(j.taDisabled),d.$parent.$watch(j.taDisabled,function(a){d.disabled=a,d.disabled?i.addClass(d.classes.disabled):i.removeClass(d.classes.disabled)})),a(d.displayElements.text)(d),a(d.displayElements.html)(d),d.updateTaBindtaTextElement=d["updateTaBindtaTextElement"+t],d.updateTaBindtaHtmlElement=d["updateTaBindtaHtmlElement"+t],i.addClass("ta-root"),d.displayElements.text.addClass("ta-text ta-editor "+d.classes.textEditor),d.displayElements.html.addClass("ta-html ta-editor "+d.classes.textEditor),d._actionRunning=!1;var v=!1;if(d.startAction=function(){return d._actionRunning=!0,f.rangy&&f.rangy.saveSelection?(v=f.rangy.saveSelection(),function(){v&&f.rangy.restoreSelection(v)}):void 0},d.endAction=function(){d._actionRunning=!1,v&&f.rangy.removeMarkers(v),v=!1,d.updateSelectedStyles(),d.showHtml||d["updateTaBindtaTextElement"+t]()},p=function(){i.addClass(d.classes.focussed),s.focus()},d.displayElements.html.on("focus",p),d.displayElements.text.on("focus",p),q=function(a){return d._actionRunning||document.activeElement===d.displayElements.html[0]||document.activeElement===d.displayElements.text[0]||(i.removeClass(d.classes.focussed),s.unfocus(),b(function(){i.triggerHandler("blur")},0)),a.preventDefault(),!1},d.displayElements.html.on("blur",q),d.displayElements.text.on("blur",q),d.queryFormatBlockState=function(a){return a.toLowerCase()===document.queryCommandValue("formatBlock").toLowerCase()},d.switchView=function(){d.showHtml=!d.showHtml,d.showHtml?b(function(){return d.displayElements.html[0].focus()},100):b(function(){return d.displayElements.text[0].focus()},100)},j.ngModel){var w=!0;k.$render=function(){if(w){w=!1;var a=d.$parent.$eval(j.ngModel);void 0!==a&&null!==a||!r||""===r||k.$setViewValue(r)}d.displayElements.forminput.val(k.$viewValue),d._elementSelectTriggered||document.activeElement===d.displayElements.html[0]||document.activeElement===d.displayElements.text[0]||(d.html=k.$viewValue||"")}}else d.displayElements.forminput.val(r),d.html=r;if(d.$watch("html",function(a,b){a!==b&&(j.ngModel&&k.$viewValue!==a&&k.$setViewValue(a),d.displayElements.forminput.val(a))}),j.taTargetToolbars)s=e.registerEditor(u,d,j.taTargetToolbars.split(","));else{var x=angular.element('
');j.taToolbar&&x.attr("ta-toolbar",j.taToolbar),j.taToolbarClass&&x.attr("ta-toolbar-class",j.taToolbarClass),j.taToolbarGroupClass&&x.attr("ta-toolbar-group-class",j.taToolbarGroupClass),j.taToolbarButtonClass&&x.attr("ta-toolbar-button-class",j.taToolbarButtonClass),j.taToolbarActiveButtonClass&&x.attr("ta-toolbar-active-button-class",j.taToolbarActiveButtonClass),j.taFocussedClass&&x.attr("ta-focussed-class",j.taFocussedClass),i.prepend(x),a(x)(d.$parent),s=e.registerEditor(u,d,["textAngularToolbar"+t])}d.$on("$destroy",function(){e.unregisterEditor(u)}),d.$on("ta-element-select",function(a,b){s.triggerElementSelect(a,b)}),d.$on("ta-drop-event",function(a,b,c,e){d.displayElements.text[0].focus(),e&&e.files&&e.files.length>0&&(angular.forEach(e.files,function(a){try{return d.fileDropHandler(a,d.wrapSelection)||d.fileDropHandler!==d.defaultFileDropHandler&&d.defaultFileDropHandler(a,d.wrapSelection)}catch(b){h.error(b)}}),c.preventDefault(),c.stopPropagation())}),d._bUpdateSelectedStyles=!1,d.updateSelectedStyles=function(){var a;f.rangy&&f.rangy.getSelection&&1===(a=f.rangy.getSelection().getAllRanges()).length&&a[0].commonAncestorContainer.parentNode!==d.displayElements.text[0]?s.updateSelectedStyles(angular.element(a[0].commonAncestorContainer.parentNode)):s.updateSelectedStyles(),d._bUpdateSelectedStyles&&b(d.updateSelectedStyles,200)},l=function(){d._bUpdateSelectedStyles||(d._bUpdateSelectedStyles=!0,d.$apply(function(){d.updateSelectedStyles()}))},d.displayElements.html.on("keydown",l),d.displayElements.text.on("keydown",l),m=function(){d._bUpdateSelectedStyles=!1},d.displayElements.html.on("keyup",m),d.displayElements.text.on("keyup",m),n=function(a,b){b&&angular.extend(a,b),d.$apply(function(){return s.sendKeyCommand(a)?(d._bUpdateSelectedStyles||d.updateSelectedStyles(),a.preventDefault(),!1):void 0})},d.displayElements.html.on("keypress",n),d.displayElements.text.on("keypress",n),o=function(){d._bUpdateSelectedStyles=!1,d.$apply(function(){d.updateSelectedStyles()})},d.displayElements.html.on("mouseup",o),d.displayElements.text.on("mouseup",o)}}}]).directive("taBind",["taSanitize","$timeout","$window","taFixChrome","taSelectableElements","taApplyCustomRenderers",function(a,c,e,f,h,j){return{require:"ngModel",scope:{},link:function(k,l,m,n){var o,p=void 0!==l.attr("contenteditable")&&l.attr("contenteditable"),q=p||"textarea"===l[0].tagName.toLowerCase()||"input"===l[0].tagName.toLowerCase(),r=!1,s=!1;void 0===m.taDefaultWrap&&(m.taDefaultWrap="p"),o=""===m.taDefaultWrap?"":void 0===g?"<"+m.taDefaultWrap+">
"+m.taDefaultWrap+">":"<"+m.taDefaultWrap+">"+m.taDefaultWrap+">";var t=function(){if(p)return l[0].innerHTML;if(q)return l.val();throw"textAngular Error: attempting to update non-editable taBind"};if(k.$parent["updateTaBind"+(m.id||"")]=function(){r||n.$setViewValue(t())},q)if(p){if(l.on("cut",function(a){r?a.preventDefault():c(function(){n.$setViewValue(t())},0)}),l.on("paste",function(a,b){b&&angular.extend(a,b);var c;if(a.clipboardData||a.originalEvent&&a.originalEvent.clipboardData?c=(a.originalEvent||a).clipboardData.getData("text/plain"):e.clipboardData&&(c=e.clipboardData.getData("Text")),!c&&!r)return!0;if(a.preventDefault(),!r){var d=angular.element("
");d[0].innerHTML=c,c=d.text(),document.execCommand("insertText",!1,c),n.$setViewValue(t())}}),l.on("keyup",function(){r||n.$setViewValue(t())}),l.on("blur",function(){s=!1;var a=t();r||n.$setViewValue(a===o?"":t()),n.$render()}),m.placeholder){var u;if(!m.id)throw"textAngular Error: An unique ID is required for placeholders to work";u=b("#"+m.id+".placeholder-text:before",'content: "'+m.placeholder+'"'),k.$on("$destroy",function(){d(u)})}l.on("focus",function(){s=!0,n.$render()})}else l.on("paste cut",function(){r||c(function(){n.$setViewValue(t())},0)}),l.on("change blur",function(){r||n.$setViewValue(t())});var v=function(b){return n.$oldViewValue=a(f(b),n.$oldViewValue)};n.$parsers.push(v),n.$formatters.push(v);var w=function(a){return k.$emit("ta-element-select",this),a.preventDefault(),!1},x=function(a,b){if(b&&angular.extend(a,b),!i&&!r){i=!0;var d;d=a.originalEvent?a.originalEvent.dataTransfer:a.dataTransfer,k.$emit("ta-drop-event",this,a,d),c(function(){i=!1},100)}};k.$parent["reApplyOnSelectorHandlers"+(m.id||"")]=function(){r||angular.forEach(h,function(a){l.find(a).off("click",w).on("click",w)})},n.$render=function(){var a=n.$viewValue||"";document.activeElement!==l[0]?p?(m.placeholder?""===a?(s?l.removeClass("placeholder-text"):l.addClass("placeholder-text"),l[0].innerHTML=o):(l.removeClass("placeholder-text"),l[0].innerHTML=a):l[0].innerHTML=""===a?o:a,r?l.off("drop",x):(angular.forEach(h,function(a){l.find(a).on("click",w)}),l.on("drop",x))):"textarea"!==l[0].tagName.toLowerCase()&&"input"!==l[0].tagName.toLowerCase()?l[0].innerHTML=j(a):l.val(a):p&&l.removeClass("placeholder-text")},m.taReadonly&&(r=k.$parent.$eval(m.taReadonly),r?(("textarea"===l[0].tagName.toLowerCase()||"input"===l[0].tagName.toLowerCase())&&l.attr("disabled","disabled"),void 0!==l.attr("contenteditable")&&l.attr("contenteditable")&&l.removeAttr("contenteditable")):"textarea"===l[0].tagName.toLowerCase()||"input"===l[0].tagName.toLowerCase()?l.removeAttr("disabled"):p&&l.attr("contenteditable","true"),k.$parent.$watch(m.taReadonly,function(a,b){b!==a&&(a?(("textarea"===l[0].tagName.toLowerCase()||"input"===l[0].tagName.toLowerCase())&&l.attr("disabled","disabled"),void 0!==l.attr("contenteditable")&&l.attr("contenteditable")&&l.removeAttr("contenteditable"),angular.forEach(h,function(a){l.find(a).on("click",w)}),l.off("drop",x)):("textarea"===l[0].tagName.toLowerCase()||"input"===l[0].tagName.toLowerCase()?l.removeAttr("disabled"):p&&l.attr("contenteditable","true"),angular.forEach(h,function(a){l.find(a).off("click",w)}),l.on("drop",x)),r=a)})),p&&!r&&(angular.forEach(h,function(a){l.find(a).on("click",w)}),l.on("drop",x))}}}]).factory("taApplyCustomRenderers",["taCustomRenderers",function(a){return function(b){var c=angular.element("
");return c[0].innerHTML=b,angular.forEach(a,function(a){var b=[];a.selector&&""!==a.selector?b=c.find(a.selector):a.customAttribute&&""!==a.customAttribute&&(b=e(c,a.customAttribute)),angular.forEach(b,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)})}),c[0].innerHTML}}]).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)}}}).factory("taFixChrome",function(){var a=function(a){for(var b=angular.element("
"+a+"
"),c=angular.element(b).find("span"),d=0;d
0&&"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){return function(b,c){var d=angular.element(""+b+"
");angular.forEach(e(d,"align"),function(a){a.css("text-align",a.attr("align")),a.removeAttr("align")}),b=d[0].innerHTML;var f;try{f=a(b)}catch(g){f=c||""}return f}}]).directive("textAngularToolbar",["$compile","textAngularManager","taOptions","taTools","taToolExecuteAction","$window",function(a,b,c,d,e,f){return{scope:{name:"@"},restrict:"EA",link:function(g,h,i){if(!g.name||""===g.name)throw"textAngular Error: A toolbar requires a name";angular.extend(g,angular.copy(c)),i.taToolbar&&(g.toolbar=g.$parent.$eval(i.taToolbar)),i.taToolbarClass&&(g.classes.toolbar=i.taToolbarClass),i.taToolbarGroupClass&&(g.classes.toolbarGroup=i.taToolbarGroupClass),i.taToolbarButtonClass&&(g.classes.toolbarButton=i.taToolbarButtonClass),i.taToolbarActiveButtonClass&&(g.classes.toolbarButtonActive=i.taToolbarActiveButtonClass),i.taFocussedClass&&(g.classes.focussed=i.taFocussedClass),g.disabled=!0,g.focussed=!1,g._$element=h,h[0].innerHTML="",h.addClass("ta-toolbar "+g.classes.toolbar),g.$watch("focussed",function(){g.focussed?h.addClass(g.classes.focussed):h.removeClass(g.classes.focussed)});var j=function(b,c){var d;if(d=angular.element(b&&b.display?b.display:""),d.addClass(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)"),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}};var k={$window:f,$editor:function(){return g._parent},isDisabled:function(){return 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)})}}}]).service("taToolExecuteAction",["$q",function(a){return function(b){void 0!==b&&(this.$editor=function(){return b});var c=a.defer(),d=c.promise,e=this.$editor();d["finally"](function(){e.endAction.call(e)});var f;try{f=this.action(c,e.startAction())}catch(g){}(f||void 0===f)&&c.resolve()}}]).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(b){b.activeState&&(b.active=b.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;g
0)for(var k=e[0].tool,l=e[0].name,m=0;m -1) ? rv : undef);
}());
+ // tests against the current jqLite/jquery implementation if this can be an element
+ function validElementString(string){
+ try{
+ return angular.element(string).length !== 0;
+ }catch(any){
+ return false;
+ }
+ }
+
/*
Custom stylesheet for the placeholders rules.
Credit to: http://davidwalsh.name/add-rules-stylesheets
@@ -169,7 +178,7 @@ See README.md or https://github.com/fraywing/textAngular/wiki for requirements a
function registerTextAngularTool(name, toolDefinition){
if(!name || name === '' || taTools.hasOwnProperty(name)) throw('textAngular Error: A unique name is required for a Tool Definition');
if(
- (toolDefinition.display && (toolDefinition.display === '' || angular.element(toolDefinition.display).length === 0)) ||
+ (toolDefinition.display && (toolDefinition.display === '' || !validElementString(toolDefinition.display))) ||
(!toolDefinition.display && !toolDefinition.buttontext && !toolDefinition.iconclass)
)
throw('textAngular Error: Tool Definition for "' + name + '" does not have a valid display/iconclass/buttontext value');
@@ -250,20 +259,27 @@ See README.md or https://github.com/fraywing/textAngular/wiki for requirements a
scope.displayElements.popover.append(scope.displayElements.popoverContainer);
element.append(scope.displayElements.popover);
- scope.displayElements.popover.on('mousedown', function(e){
+ scope.displayElements.popover.on('mousedown', function(e, eventData){
+ /* istanbul ignore else: this is for catching the jqLite testing*/
+ if(eventData) angular.extend(e, eventData);
// this prevents focusout from firing on the editor when clicking anything in the popover
e.preventDefault();
return false;
});
// define the popover show and hide functions
- scope.showPopover = function(element){
- scope.displayElements.popover.css('top', element[0].offsetTop + element[0].offsetHeight + 'px');
- scope.displayElements.popover.css('left', element[0].offsetLeft + (element[0].offsetWidth / 2.0) - 152.5 + 'px');
+ scope.showPopover = function(_el){
+ scope.displayElements.popover.css('top', _el[0].offsetTop + _el[0].offsetHeight + 'px');
+ scope.displayElements.popover.css('left', _el[0].offsetLeft + (_el[0].offsetWidth / 2.0) - 152.5 + 'px');
scope.displayElements.popover.css('display', 'block');
$animate.addClass(scope.displayElements.popover, 'in');
$timeout(function(){
- scope.displayElements.html.parent().one('click', scope.hidePopover);
+ // shim the .one till fixed
+ var _func = function(){
+ element.off('click', _func);
+ scope.hidePopover();
+ };
+ element.on('click', _func);
}, 100);
};
scope.hidePopover = function(){
@@ -519,7 +535,9 @@ See README.md or https://github.com/fraywing/textAngular/wiki for requirements a
scope.displayElements.html.on('keyup', _keyup);
scope.displayElements.text.on('keyup', _keyup);
// stop updating on key up and update the display/model
- _keypress = function(event){
+ _keypress = function(event, eventData){
+ /* istanbul ignore else: this is for catching the jqLite testing*/
+ if(eventData) angular.extend(event, eventData);
scope.$apply(function(){
if(_toolbars.sendKeyCommand(event)){
/* istanbul ignore else: don't run if already running */
@@ -602,8 +620,9 @@ See README.md or https://github.com/fraywing/textAngular/wiki for requirements a
}, 0);
else e.preventDefault();
});
- element.on('paste', function(e){
- // timeout to next is needed as otherwise the paste/cut event has not finished actually changing the display
+ element.on('paste', function(e, eventData){
+ /* istanbul ignore else: this is for catching the jqLite testing*/
+ if(eventData) angular.extend(e, eventData);
var text;
// for non-ie
if(e.clipboardData || (e.originalEvent && e.originalEvent.clipboardData))
@@ -676,9 +695,11 @@ See README.md or https://github.com/fraywing/textAngular/wiki for requirements a
event.preventDefault();
return false;
};
- var fileDropHandler = function(event){
+ var fileDropHandler = function(event, eventData){
+ /* istanbul ignore else: this is for catching the jqLite testing*/
+ if(eventData) angular.extend(event, eventData);
// emit the drop event, pass the element, preventing should be done elsewhere
- if(!dropFired){
+ if(!dropFired && !_isReadonly){
dropFired = true;
var dataTransfer;
if(event.originalEvent) dataTransfer = event.originalEvent.dataTransfer;
@@ -960,7 +981,9 @@ See README.md or https://github.com/fraywing/textAngular/wiki for requirements a
toolElement.attr('tabindex', '-1');
toolElement.attr('ng-click', 'executeAction()');
toolElement.attr('ng-class', 'displayActiveToolClass(active)');
- toolElement.on('mousedown', function(e){
+ toolElement.on('mousedown', function(e, eventData){
+ /* istanbul ignore else: this is for catching the jqLite testing*/
+ if(eventData) angular.extend(e, eventData);
// this prevents focusout from firing on the editor when clicking toolbar buttons
e.preventDefault();
return false;
diff --git a/test/taBind.spec.js b/test/taBind.spec.js
index f5303c0e..7cfe4c04 100644
--- a/test/taBind.spec.js
+++ b/test/taBind.spec.js
@@ -216,7 +216,7 @@ describe('taBind', function () {
element.find('a').on('click', function(e){
expect(e.isDefaultPrevented());
});
- element.find('a').triggerHandler('click');
+ jQuery(element.find('a')[0]).trigger('click');
});
describe('should respect the ta-default-wrap value', function(){
@@ -224,7 +224,7 @@ describe('taBind', function () {
$rootScope.html = '';
element = $compile('
')($rootScope);
$rootScope.$digest();
- element.trigger('focus');
+ element.triggerHandler('focus');
$rootScope.$digest();
expect(element.html()).toBe('
');
}));
@@ -232,7 +232,7 @@ describe('taBind', function () {
$rootScope.html = '';
element = $compile('
')($rootScope);
$rootScope.$digest();
- element.trigger('focus');
+ element.triggerHandler('focus');
$rootScope.$digest();
expect(element.html()).toBe('
');
}));
@@ -240,7 +240,7 @@ describe('taBind', function () {
$rootScope.html = '';
element = $compile('
')($rootScope);
$rootScope.$digest();
- element.trigger('focus');
+ element.triggerHandler('focus');
$rootScope.$digest();
expect(element.html()).toBe('');
}));
@@ -261,7 +261,7 @@ describe('taBind', function () {
});
it('should update model from change', function () {
element.val('Test 2 Content
');
- element.trigger('blur');
+ element.triggerHandler('blur');
$rootScope.$digest();
expect($rootScope.html).toBe('Test 2 Content
');
});
@@ -292,7 +292,7 @@ describe('taBind', function () {
});
it('should update model from change', function () {
element.val('Test 2 Content
');
- element.trigger('blur');
+ element.triggerHandler('blur');
$rootScope.$digest();
expect($rootScope.html).toBe('Test 2 Content
');
});
@@ -322,7 +322,7 @@ describe('taBind', function () {
it('should update model from paste', function () {
element.val('Test 2 Content
');
- element.trigger('paste');
+ element.triggerHandler('paste');
$rootScope.$digest();
$timeout.flush();
$rootScope.$digest();
@@ -331,7 +331,7 @@ describe('taBind', function () {
it('should update model from cut', function () {
element.val('Test 2 Content
');
- element.trigger('cut');
+ element.triggerHandler('cut');
$timeout.flush();
$rootScope.$digest();
expect($rootScope.html).toBe('Test 2 Content
');
@@ -362,36 +362,26 @@ describe('taBind', function () {
$window.clipboardData = {
getData: function(){ return 'Test 2 Content'; }
};
- element.trigger('paste');
+ element.triggerHandler('paste');
$rootScope.$digest();
expect($rootScope.html).toBe('Test 2 Content
');
$window.clipboardData = undefined;
}));
it('non-ie based w/o jquery', inject(function($window){
- var event = jQuery.Event('paste');
- event.clipboardData = {
- getData: function(){ return 'Test 3 Content'; }
- };
- element.trigger(event);
+ element.triggerHandler('paste', {clipboardData: {getData: function(){ return 'Test 3 Content'; }}});
$rootScope.$digest();
expect($rootScope.html).toBe('Test 3 Content
');
}));
it('non-ie based w/ jquery', inject(function($window){
- var event = jQuery.Event('paste');
- event.originalEvent = {
- clipboardData: {
- getData: function(){ return 'Test 3 Content'; }
- }
- };
- element.trigger(event);
+ element.triggerHandler('paste', {originalEvent: {clipboardData: {getData: function(){ return 'Test 3 Content'; } }}});
$rootScope.$digest();
expect($rootScope.html).toBe('Test 3 Content
');
}));
it('non-ie based w/o paste content', inject(function($window){
- element.trigger('paste');
+ element.triggerHandler('paste');
$rootScope.$digest();
expect($rootScope.html).toBe('Test Contents
');
}));
@@ -399,7 +389,7 @@ describe('taBind', function () {
it('should update model from cut', function () {
element.html('Test 2 Content
');
- element.trigger('cut');
+ element.triggerHandler('cut');
$timeout.flush();
$rootScope.$digest();
expect($rootScope.html).toBe('Test 2 Content
');
@@ -430,18 +420,14 @@ describe('taBind', function () {
$window.clipboardData = {
getData: function(){ return 'Test 2 Content'; }
};
- element.trigger('paste');
+ element.triggerHandler('paste');
$rootScope.$digest();
expect($rootScope.html).toBe('Test Contents
');
$window.clipboardData = undefined;
}));
it('non-ie based', inject(function($window){
- var event = jQuery.Event('paste');
- event.clipboardData = {
- getData: function(){ return 'Test 3 Content'; }
- };
- element.trigger(event);
+ element.triggerHandler('paste', {clipboardData: {getData: function(){ return 'Test 3 Content'; }}});
$rootScope.$digest();
expect($rootScope.html).toBe('Test Contents
');
}));
@@ -789,14 +775,14 @@ describe('taBind', function () {
it('should update model from paste', function () {
element.val('Test 2 Content
');
- element.trigger('paste');
+ element.triggerHandler('paste');
$rootScope.$digest();
expect($rootScope.html).toBe('Test Contents
');
});
it('should update model from cut', function () {
element.val('Test 2 Content
');
- element.trigger('cut');
+ element.triggerHandler('cut');
$rootScope.$digest();
expect($rootScope.html).toBe('Test Contents
');
});
@@ -814,14 +800,14 @@ describe('taBind', function () {
it('should update model from paste', function () {
element.val('Test 2 Content
');
- element.trigger('paste');
+ element.triggerHandler('paste');
$rootScope.$digest();
expect($rootScope.html).toBe('Test Contents
');
});
it('should update model from cut', function () {
element.val('Test 2 Content
');
- element.trigger('cut');
+ element.triggerHandler('cut');
$rootScope.$digest();
expect($rootScope.html).toBe('Test Contents
');
});
@@ -839,14 +825,14 @@ describe('taBind', function () {
it('should update model from paste', function () {
element.html('Test 2 Content
');
- element.trigger('paste');
+ element.triggerHandler('paste');
$rootScope.$digest();
expect($rootScope.html).toBe('Test Contents
');
});
it('should update model from cut', function () {
element.html('Test 2 Content
');
- element.trigger('cut');
+ element.triggerHandler('cut');
$rootScope.$digest();
expect($rootScope.html).toBe('Test Contents
');
});
@@ -922,7 +908,7 @@ describe('taBind', function () {
it('should update model', function () {
element.val('Test 2 Content
');
- element.trigger('blur');
+ element.triggerHandler('blur');
$rootScope.$digest();
expect($rootScope.html).toBe('Test Contents
');
});
@@ -940,7 +926,7 @@ describe('taBind', function () {
it('should update model', function () {
element.val('Test 2 Content
');
- element.trigger('blur');
+ element.triggerHandler('blur');
$rootScope.$digest();
expect($rootScope.html).toBe('Test Contents
');
});
@@ -960,7 +946,7 @@ describe('taBind', function () {
it('should update model', function () {
element.html('Test 2 Content
');
- element.trigger('keyup');
+ element.triggerHandler('keyup');
$rootScope.$digest();
expect($rootScope.html).toBe('Test Contents
');
});
diff --git a/test/taRegisterTool.spec.js b/test/taRegisterTool.spec.js
index be79aafd..01280a0c 100644
--- a/test/taRegisterTool.spec.js
+++ b/test/taRegisterTool.spec.js
@@ -1,4 +1,4 @@
-describe('Adding tools to taTools', function(){
+describe('taRegisterTool Adding tools to taTools', function(){
'use strict';
beforeEach(module('textAngular'));
diff --git a/test/taTools.spec.js b/test/taTools.spec.js
index 01f5919e..a9a6a3bf 100644
--- a/test/taTools.spec.js
+++ b/test/taTools.spec.js
@@ -74,11 +74,20 @@ describe('taToolsExecuteFunction', function(){
});
});
+function buttonByName(element, name){
+ var button;
+ angular.forEach(element.find('button'), function(_b){
+ _b = angular.element(_b);
+ if(_b.attr('name') === name) button = _b;
+ });
+ return button;
+}
+
describe('taTools test tool actions', function(){
'use strict';
var $rootScope, element, button, editorScope, $window;
var findAndTriggerButton = function(name){
- var button = element.find('button[name=' + name + ']');
+ var button = buttonByName(element, name);
button.scope().executeAction(editorScope);
editorScope.endAction();
$rootScope.$digest();
@@ -178,14 +187,14 @@ describe('taTools test tool actions', function(){
button = findAndTriggerButton('html');
$timeout.flush();
expect(button.hasClass('active'));
- expect(!element.find('.ta-text').is(":visible"));
- expect(element.find('.ta-html').is(":visible"));
- expect(element.find('.ta-html').is(":focus"));
+ expect(!jQuery('.ta-text').is(":visible"));
+ expect(jQuery('.ta-html').is(":visible"));
+ expect(jQuery('.ta-html').is(":focus"));
button = findAndTriggerButton('html'); // retrigger to reset to non html view
$timeout.flush();
- expect(!element.find('.ta-html').is(":visible"));
- expect(element.find('.ta-text').is(":visible"));
- expect(element.find('.ta-text').is(":focus"));
+ expect(!jQuery('.ta-html').is(":visible"));
+ expect(jQuery('.ta-text').is(":visible"));
+ expect(jQuery('.ta-text').is(":focus"));
}));
describe('check untestables don\'t error - ', function(){
@@ -225,7 +234,7 @@ describe('taTools test tool actions', function(){
editorScope = textAngularManager.retrieveEditor('test').scope;
var sel = $window.rangy.getSelection();
var range = $window.rangy.createRangyRange();
- range.selectNode(element.find('.ta-text')[0].childNodes[0]);
+ range.selectNode(jQuery('.ta-text')[0].childNodes[0]);
sel.setSingleRange(range);
}));
afterEach(function(){
@@ -247,7 +256,7 @@ describe('taTools test tool actions', function(){
editorScope = textAngularManager.retrieveEditor('test').scope;
var sel = $window.rangy.getSelection();
var range = $window.rangy.createRangyRange();
- range.selectNodeContents(element.find('.ta-text p')[0]);
+ range.selectNodeContents(jQuery('.ta-text p')[0]);
sel.setSingleRange(range);
}));
afterEach(function(){
@@ -270,7 +279,7 @@ describe('taTools test tool actions', function(){
editorScope = textAngularManager.retrieveEditor('testclearbutton').scope;
var sel = $window.rangy.getSelection();
var range = $window.rangy.createRangyRange();
- range.selectNodeContents(element.find('.ta-text')[0]);
+ range.selectNodeContents(jQuery('.ta-text')[0]);
sel.setSingleRange(range);
}));
afterEach(function(){
@@ -293,8 +302,8 @@ describe('taTools test tool actions', function(){
it('doesn\'t remove partially selected list elements, but clears them of formatting', function(){
var sel = $window.rangy.getSelection();
var range = $window.rangy.createRangyRange();
- range.setStartBefore(element.find('.ta-text ul li:first-child b')[0]);
- range.setEndBefore(element.find('.ta-text ul li:last-child')[0]);
+ range.setStartBefore(jQuery('.ta-text ul li:first-child b')[0]);
+ range.setEndBefore(jQuery('.ta-text ul li:last-child')[0]);
sel.setSingleRange(range);
sel.refresh();
findAndTriggerButton('clear');
@@ -304,7 +313,7 @@ describe('taTools test tool actions', function(){
it('doesn\'t clear wholly selected list elements, but clears them of formatting', function(){
var sel = $window.rangy.getSelection();
var range = $window.rangy.createRangyRange();
- range.selectNodeContents(element.find('.ta-text ul')[0]);
+ range.selectNodeContents(jQuery('.ta-text ul')[0]);
sel.setSingleRange(range);
sel.refresh();
findAndTriggerButton('clear');
@@ -314,8 +323,8 @@ describe('taTools test tool actions', function(){
it('doesn\'t clear singly selected list elements, but clears them of formatting', function(){
var sel = $window.rangy.getSelection();
var range = $window.rangy.createRangyRange();
- range.selectNodeContents(element.find('.ta-text ul li:first-child')[0]);
- range.setEndAfter(element.find('.ta-text ul li:first-child')[0]);
+ range.selectNodeContents(jQuery('.ta-text ul li:first-child')[0]);
+ range.setEndAfter(jQuery('.ta-text ul li:first-child')[0]);
sel.setSingleRange(range);
sel.refresh();
findAndTriggerButton('clear');
@@ -325,8 +334,8 @@ describe('taTools test tool actions', function(){
it('doesn\'t clear singly selected list elements, but clears them of formatting', function(){
var sel = $window.rangy.getSelection();
var range = $window.rangy.createRangyRange();
- range.selectNode(element.find('.ta-text ul li:first-child')[0]);
- range.setEndAfter(element.find('.ta-text ul li:first-child')[0]);
+ range.selectNode(jQuery('.ta-text ul li:first-child')[0]);
+ range.setEndAfter(jQuery('.ta-text ul li:first-child')[0]);
sel.setSingleRange(range);
sel.refresh();
findAndTriggerButton('clear');
@@ -334,7 +343,7 @@ describe('taTools test tool actions', function(){
});
it('works without rangy', function(){
- var button = element.find('button[name=clear]');
+ var button = buttonByName(element, 'clear');
var _rangy = button.scope().$window.rangy;
button.scope().$window.rangy = undefined;
button.scope().executeAction(editorScope);
@@ -357,7 +366,7 @@ describe('taTools test tool actions', function(){
editorScope = textAngularManager.retrieveEditor('test').scope;
var sel = $window.rangy.getSelection();
var range = $window.rangy.createRangyRange();
- range.selectNodeContents(element.find('.ta-text p')[0]);
+ range.selectNodeContents(jQuery('.ta-text p')[0]);
sel.setSingleRange(range);
}));
afterEach(function(){
@@ -373,7 +382,7 @@ describe('taTools test tool actions', function(){
it('creates a link', function(){
$window.prompt = function(){ return 'testval'; };
findAndTriggerButton('insertLink');
- expect(element.find('.ta-text p a').attr('href')).toBe('testval');
+ expect(editorScope.displayElements.text.find('p').find('a').attr('href')).toBe('testval');
});
describe('interacts with the popover', function(){
@@ -383,12 +392,12 @@ describe('taTools test tool actions', function(){
});
it('opens on click', function(){
- element.find('.ta-text p a').triggerHandler('click');
+ editorScope.displayElements.text.find('p').find('a').triggerHandler('click');
expect(editorScope.displayElements.popover.hasClass('in')).toBe(true);
});
it('has correct content', function(){
- element.find('.ta-text p a').triggerHandler('click');
+ editorScope.displayElements.text.find('p').find('a').triggerHandler('click');
var contents = editorScope.displayElements.popoverContainer.contents();
expect(contents.eq(0)[0].tagName.toLowerCase()).toBe('a');
expect(contents.eq(0).html()).toBe('testval');
@@ -396,26 +405,26 @@ describe('taTools test tool actions', function(){
});
it('has functioning unlink button', function(){
- element.find('.ta-text p a').triggerHandler('click');
+ editorScope.displayElements.text.find('p').find('a').triggerHandler('click');
editorScope.displayElements.popoverContainer.find('button').eq(1).triggerHandler('click');
$rootScope.$digest();
- expect(element.find('.ta-text p a').length).toBe(0);
+ expect(editorScope.displayElements.text.find('p').find('a').length).toBe(0);
});
it('has functioning edit button', function(){
$window.prompt = function(){ return 'newval'; };
- element.find('.ta-text p a').triggerHandler('click');
+ editorScope.displayElements.text.find('p').find('a').triggerHandler('click');
editorScope.displayElements.popoverContainer.find('button').eq(0).triggerHandler('click');
$rootScope.$digest();
- expect(element.find('.ta-text p a').attr('href')).toBe('newval');
+ expect(editorScope.displayElements.text.find('p').find('a').attr('href')).toBe('newval');
});
it('has functioning edit button when blank passed', function(){
$window.prompt = function(){ return ''; };
- element.find('.ta-text p a').triggerHandler('click');
+ editorScope.displayElements.text.find('p').find('a').triggerHandler('click');
editorScope.displayElements.popoverContainer.find('button').eq(0).triggerHandler('click');
$rootScope.$digest();
- expect(element.find('.ta-text p a').attr('href')).toBe('testval');
+ expect(editorScope.displayElements.text.find('p').find('a').attr('href')).toBe('testval');
});
});
});
@@ -436,73 +445,78 @@ describe('taTools test tool actions', function(){
});
it('opens on click', function(){
- element.find('.ta-text p img').triggerHandler('click');
+ editorScope.displayElements.text.find('p').find('img').triggerHandler('click');
expect(editorScope.displayElements.popover.hasClass('in')).toBe(true);
});
it('has correct content', function(){
- element.find('.ta-text p img').triggerHandler('click');
+ editorScope.displayElements.text.find('p').find('img').triggerHandler('click');
var contents = editorScope.displayElements.popoverContainer.contents();
expect(contents.find('button').length).toBe(8);
});
// Note that this is just some phantomJS oddness that causes us to have to define the px value not %
it('has functioning 100% button', function(){
- element.find('.ta-text p img').triggerHandler('click');
+ editorScope.displayElements.text.find('p').find('img').triggerHandler('click');
editorScope.displayElements.popoverContainer.find('button').eq(0).triggerHandler('click');
$rootScope.$digest();
- expect(element.find('.ta-text p img').css('width')).toBe('384px');
+ if(jQuery === angular.element) expect(editorScope.displayElements.text.find('p').find('img').css('width')).toBe('384px');
+ else expect(editorScope.displayElements.text.find('p').find('img').css('width')).toBe('100%');
});
it('has functioning 50% button', function(){
- element.find('.ta-text p img').triggerHandler('click');
+ editorScope.displayElements.text.find('p').find('img').triggerHandler('click');
editorScope.displayElements.popoverContainer.find('button').eq(1).triggerHandler('click');
$rootScope.$digest();
- expect(element.find('.ta-text p img').css('width')).toBe('192px');
+ if(jQuery === angular.element) expect(editorScope.displayElements.text.find('p').find('img').css('width')).toBe('192px');
+ else expect(editorScope.displayElements.text.find('p').find('img').css('width')).toBe('50%');
});
it('has functioning 25% button', function(){
- element.find('.ta-text p img').triggerHandler('click');
+ editorScope.displayElements.text.find('p').find('img').triggerHandler('click');
editorScope.displayElements.popoverContainer.find('button').eq(2).triggerHandler('click');
$rootScope.$digest();
- expect(element.find('.ta-text p img').css('width')).toBe('96px');
+ if(jQuery === angular.element) expect(editorScope.displayElements.text.find('p').find('img').css('width')).toBe('96px');
+ else expect(editorScope.displayElements.text.find('p').find('img').css('width')).toBe('25%');
});
it('has functioning reset-size button', function(){
- element.find('.ta-text p img').triggerHandler('click');
+ editorScope.displayElements.text.find('p').find('img').triggerHandler('click');
editorScope.displayElements.popoverContainer.find('button').eq(3).triggerHandler('click');
$rootScope.$digest();
- expect(element.find('.ta-text p img').css('width')).toBe('0px');
+ if(jQuery === angular.element) expect(editorScope.displayElements.text.find('p').find('img').css('width')).toBe('0px');
+ else expect(editorScope.displayElements.text.find('p').find('img').css('width')).toBe('');
});
it('has functioning float-left button', function(){
- element.find('.ta-text p img').triggerHandler('click');
+ editorScope.displayElements.text.find('p').find('img').triggerHandler('click');
editorScope.displayElements.popoverContainer.find('button').eq(4).triggerHandler('click');
$rootScope.$digest();
- expect(element.find('.ta-text p img').css('float')).toBe('left');
+ expect(editorScope.displayElements.text.find('p').find('img').css('float')).toBe('left');
});
it('has functioning float-none button', function(){
- element.find('.ta-text p img').triggerHandler('click');
+ editorScope.displayElements.text.find('p').find('img').triggerHandler('click');
editorScope.displayElements.popoverContainer.find('button').eq(4).triggerHandler('click');
$rootScope.$digest();
- element.find('.ta-text p img').triggerHandler('click');
+ editorScope.displayElements.text.find('p').find('img').triggerHandler('click');
editorScope.displayElements.popoverContainer.find('button').eq(5).triggerHandler('click');
$rootScope.$digest();
- expect(element.find('.ta-text p img').css('float')).toBe('none');
+ if(jQuery === angular.element) expect(editorScope.displayElements.text.find('p').find('img').css('float')).toBe('none');
+ else expect(editorScope.displayElements.text.find('p').find('img').css('float')).toBe('');
});
it('has functioning float-right button', function(){
- element.find('.ta-text p img').triggerHandler('click');
+ editorScope.displayElements.text.find('p').find('img').triggerHandler('click');
editorScope.displayElements.popoverContainer.find('button').eq(6).triggerHandler('click');
$rootScope.$digest();
- expect(element.find('.ta-text p img').css('float')).toBe('right');
+ expect(editorScope.displayElements.text.find('p').find('img').css('float')).toBe('right');
});
it('has functioning remove button', function(){
- element.find('.ta-text p img').triggerHandler('click');
+ editorScope.displayElements.text.find('p').find('img').triggerHandler('click');
editorScope.displayElements.popoverContainer.find('button').eq(7).triggerHandler('click');
$rootScope.$digest();
- expect(element.find('.ta-text p img').length).toBe(0);
+ expect(editorScope.displayElements.text.find('p').find('img').length).toBe(0);
});
});
});
\ No newline at end of file
diff --git a/test/textAngular.spec.js b/test/textAngular.spec.js
index b41ff3b5..01c28683 100644
--- a/test/textAngular.spec.js
+++ b/test/textAngular.spec.js
@@ -61,10 +61,11 @@ describe('textAngular', function(){
describe('Add classes via attributes', function(){
'use strict';
- var $rootScope, element;
+ var $rootScope, element, textAngularManager;
beforeEach(module('textAngular'));
- beforeEach(inject(function (_$compile_, _$rootScope_) {
+ beforeEach(inject(function (_$compile_, _$rootScope_, _textAngularManager_) {
$rootScope = _$rootScope_;
+ textAngularManager = _textAngularManager_;
element = _$compile_(' ')($rootScope);
$rootScope.$digest();
}));
@@ -74,7 +75,7 @@ describe('textAngular', function(){
expect(!jQuery(element).hasClass('.test-focus-class'));
});
it('adds focus class when ta-text is focussed', function(){
- jQuery('.ta-text', element).triggerHandler('focus');
+ textAngularManager.retrieveEditor('test').scope.displayElements.text.triggerHandler('focus');
expect(jQuery(element).hasClass('.test-focus-class'));
});
it('adds focus class when ta-html is focussed', function(){
@@ -82,17 +83,17 @@ describe('textAngular', function(){
expect(jQuery(element).hasClass('.test-focus-class'));
});
it('adds text editor class', function(){
- expect(jQuery('.ta-text', element).hasClass('.test-text-class'));
+ expect(textAngularManager.retrieveEditor('test').scope.displayElements.text.hasClass('.test-text-class'));
});
it('adds html editor class', function(){
- expect(jQuery('.ta-html', element).hasClass('.test-html-class'));
+ expect(textAngularManager.retrieveEditor('test').scope.displayElements.html.hasClass('.test-html-class'));
});
});
});
describe('Change classes via decorator', function(){
'use strict';
- var $rootScope, element;
+ var $rootScope, element, textAngularManager;
beforeEach(module('textAngular', function($provide){
// change all the classes at once
$provide.decorator('taOptions', ['$delegate', function(taOptions){
@@ -103,20 +104,21 @@ describe('textAngular', function(){
return taOptions;
}]);
}));
- beforeEach(inject(function (_$compile_, _$rootScope_) {
+ beforeEach(inject(function (_$compile_, _$rootScope_, _textAngularManager_) {
$rootScope = _$rootScope_;
+ textAngularManager = _textAngularManager_;
element = _$compile_(' ')($rootScope);
$rootScope.$digest();
}));
it('should add .test-focus-class instead of default .focussed', function(){
- jQuery('.ta-text', element).triggerHandler('focus');
+ textAngularManager.retrieveEditor('test').scope.displayElements.text.triggerHandler('focus');
expect(jQuery(element).hasClass('.test-focus-class'));
});
it('adds text editor class', function(){
- expect(jQuery('.ta-text', element).hasClass('.test-text-class'));
+ expect(textAngularManager.retrieveEditor('test').scope.displayElements.text.hasClass('.test-text-class'));
});
it('adds html editor class', function(){
- expect(jQuery('.ta-html', element).hasClass('.test-html-class'));
+ expect(textAngularManager.retrieveEditor('test').scope.displayElements.html.hasClass('.test-html-class'));
});
it('adds disabled class', function(){
expect(jQuery(element).hasClass('.disabled-test'));
@@ -125,20 +127,21 @@ describe('textAngular', function(){
describe('Add tabindex attribute', function(){
'use strict';
- var $rootScope, element;
+ var $rootScope, element, textAngularManager;
beforeEach(module('textAngular'));
- beforeEach(inject(function (_$compile_, _$rootScope_) {
+ beforeEach(inject(function (_$compile_, _$rootScope_, _textAngularManager_) {
$rootScope = _$rootScope_;
+ textAngularManager = _textAngularManager_;
element = _$compile_(' ')($rootScope);
$rootScope.$digest();
}));
describe('Check moved across', function () {
it('to textEditor', function(){
- expect(jQuery('.ta-text', element).attr('tabindex')).toBe('42');
+ expect(textAngularManager.retrieveEditor('test').scope.displayElements.text.attr('tabindex')).toBe('42');
});
it('to htmlEditor', function(){
- expect(jQuery('.ta-html', element).attr('tabindex')).toBe('42');
+ expect(textAngularManager.retrieveEditor('test').scope.displayElements.html.attr('tabindex')).toBe('42');
});
it('removed from .ta-root', function(){
expect(element.attr('tabindex')).toBeUndefined();
@@ -180,68 +183,76 @@ describe('textAngular', function(){
'use strict';
var $rootScope, element, editorScope;
beforeEach(module('textAngular'));
- beforeEach(inject(function (_$compile_, _$rootScope_, textAngularManager) {
+ beforeEach(inject(function (_$compile_, _$rootScope_, textAngularManager, $document) {
$rootScope = _$rootScope_;
element = _$compile_(' ')($rootScope);
+ $document.find('body').append(element);
+ editorScope = textAngularManager.retrieveEditor('test').scope;$document.find('body').append(element);
$rootScope.$digest();
- editorScope = textAngularManager.retrieveEditor('test').scope;
}));
+ afterEach(function(){
+ element.remove();
+ });
it('initially should hide .ta-html and show .ta-text', function(){
- expect(jQuery('.ta-text', element).is(':visible:focus'));
- expect(!jQuery('.ta-html', element).is(':visible'));
+ expect(jQuery('.ta-text', element[0]).is(':visible')).toBe(true);
+ expect(jQuery('.ta-html', element[0]).is(':visible')).toBe(false);
});
describe('from WYSIWYG text to RAW HTML view', function () {
it('should hide .ta-text and show .ta-html', function(){
editorScope.switchView();
- expect(!jQuery('.ta-text', element).is(':visible'));
- expect(jQuery('.ta-html', element).is(':visible:focus'));
+ editorScope.$parent.$digest();
+ expect(jQuery('.ta-text', element[0]).is(':visible')).toBe(false);
+ expect(jQuery('.ta-html', element[0]).is(':visible')).toBe(true);
});
});
describe('from RAW HTML to WYSIWYG text view', function () {
it('should hide .ta-html and show .ta-text', function(){
editorScope.switchView();
+ editorScope.$parent.$digest();
editorScope.switchView();
- expect(jQuery('.ta-text', element).is(':visible:focus'));
- expect(!jQuery('.ta-html', element).is(':visible'));
+ editorScope.$parent.$digest();
+ expect(jQuery('.ta-text', element[0]).is(':visible')).toBe(true);
+ expect(jQuery('.ta-html', element[0]).is(':visible')).toBe(false);
});
});
});
describe('Check focussed class adding', function(){
'use strict';
- var $rootScope, element;
+ var $rootScope, element, editorScope;
beforeEach(module('textAngular'));
- beforeEach(inject(function (_$compile_, _$rootScope_) {
+ beforeEach(inject(function (_$compile_, _$rootScope_, textAngularManager) {
$rootScope = _$rootScope_;
element = _$compile_(' ')($rootScope);
$rootScope.$digest();
+ editorScope = textAngularManager.retrieveEditor('test').scope;
}));
describe('should have added .focussed', function(){
it('on trigger focus on ta-text', function(){
- element.find('.ta-text').triggerHandler('focus');
+ editorScope.displayElements.text.triggerHandler('focus');
expect(element.hasClass('focussed'));
});
it('on trigger focus on ta-html', function(){
- element.find('.ta-html').triggerHandler('focus');
+ editorScope.displayElements.html.triggerHandler('focus');
expect(element.hasClass('focussed'));
});
});
describe('should have removed .focussed', function(){
it('on ta-text trigger blur', function(){
- element.find('.ta-text').triggerHandler('focus');
+ editorScope.displayElements.text.triggerHandler('focus');
$rootScope.$digest();
- element.find('.ta-text').triggerHandler('blur');
+ editorScope.displayElements.text.triggerHandler('blur');
expect(!element.hasClass('focussed'));
});
it('on ta-html trigger blur', function(){
- element.find('.ta-html').triggerHandler('focus');
+ editorScope.displayElements.html.triggerHandler('focus');
$rootScope.$digest();
- element.find('.ta-html').triggerHandler('blur');
+ editorScope.displayElements.html.triggerHandler('blur');
expect(!element.hasClass('focussed'));
});
});
@@ -261,12 +272,12 @@ describe('textAngular', function(){
}));
describe('should have added attribute to', function(){
- it('ta-text', function(){
- expect(element.find('.ta-text').attr('testattr')).toBe('trueish');
- });
- it('ta-html', function(){
- expect(element.find('.ta-html').attr('testattr')).toBe('trueish');
- });
+ it('ta-text', inject(function(textAngularManager){
+ expect(textAngularManager.retrieveEditor('test').scope.displayElements.text.attr('testattr')).toBe('trueish');
+ }));
+ it('ta-html', inject(function(textAngularManager){
+ expect(textAngularManager.retrieveEditor('test').scope.displayElements.html.attr('testattr')).toBe('trueish');
+ }));
});
});
@@ -281,12 +292,12 @@ describe('textAngular', function(){
}));
describe('should have added placeholder to', function(){
- it('.ta-text', function(){
- expect(element.find('.ta-text').attr('placeholder')).toBe('Test Placeholder');
- });
- it('.ta-html', function(){
- expect(element.find('.ta-html').attr('placeholder')).toBe('Test Placeholder');
- });
+ it('ta-text', inject(function(textAngularManager){
+ expect(textAngularManager.retrieveEditor('test').scope.displayElements.text.attr('placeholder')).toBe('Test Placeholder');
+ }));
+ it('ta-html', inject(function(textAngularManager){
+ expect(textAngularManager.retrieveEditor('test').scope.displayElements.html.attr('placeholder')).toBe('Test Placeholder');
+ }));
});
});
@@ -368,11 +379,11 @@ describe('textAngular', function(){
});
describe('should change on input update', function () {
- beforeEach(function(){
- element.find('.ta-text').html('Test Change Content
');
- element.find('.ta-text').triggerHandler('keyup');
+ beforeEach(inject(function(textAngularManager){
+ textAngularManager.retrieveEditor('test').scope.displayElements.text.html('Test Change Content
');
+ textAngularManager.retrieveEditor('test').scope.displayElements.text.triggerHandler('keyup');
$rootScope.$digest();
- });
+ }));
it('not pristine', function(){
expect($rootScope.form.$pristine).toBe(false);
});
@@ -394,86 +405,91 @@ describe('textAngular', function(){
describe('Basic Initiation without ng-model', function(){
'use strict';
- var $rootScope, element;
+ var $rootScope, element, displayElements;
beforeEach(module('textAngular'));
- beforeEach(inject(function (_$compile_, _$rootScope_) {
+ beforeEach(inject(function (_$compile_, _$rootScope_, textAngularManager) {
$rootScope = _$rootScope_;
element = _$compile_('Test Content
')($rootScope);
$rootScope.$digest();
+ displayElements = textAngularManager.retrieveEditor('test').scope.displayElements;
}));
describe('Inserts the current information into the fields', function(){
it('populates the WYSIWYG area', function(){
- expect(jQuery('.ta-text p', element).length).toBe(1);
+ expect(displayElements.text.find('p').length).toBe(1);
});
it('populates the textarea', function(){
- expect(jQuery('.ta-html', element).val()).toBe('Test Content
');
+ expect(displayElements.html.val()).toBe('Test Content
');
});
it('populates the hidden input value', function(){
- expect(jQuery('input[type=hidden]', element).val()).toBe('Test Content
');
+ expect(displayElements.forminput.val()).toBe('Test Content
');
});
});
});
describe('Basic Initiation with ng-model', function(){
'use strict';
- var $rootScope, element;
+ var $rootScope, element, displayElements;
beforeEach(module('textAngular'));
- beforeEach(inject(function (_$compile_, _$rootScope_) {
+ beforeEach(inject(function (_$compile_, _$rootScope_, textAngularManager) {
$rootScope = _$rootScope_;
$rootScope.htmlcontent = 'Test Content
';
element = _$compile_(' ')($rootScope);
$rootScope.$digest();
+ displayElements = textAngularManager.retrieveEditor('test').scope.displayElements;
}));
describe('Inserts the current information into the fields', function(){
it('populates the WYSIWYG area', function(){
- expect(jQuery('.ta-text p', element).length).toBe(1);
+ expect(displayElements.text.find('p').length).toBe(1);
});
it('populates the textarea', function(){
- expect(jQuery('.ta-html', element).val()).toBe('Test Content
');
+ expect(displayElements.html.val()).toBe('Test Content
');
});
it('populates the hidden input value', function(){
- expect(jQuery('input[type=hidden]', element).val()).toBe('Test Content
');
+ expect(displayElements.forminput.val()).toBe('Test Content
');
});
});
});
describe('Basic Initiation with ng-model and originalContents', function(){
'use strict';
- var $rootScope, element;
+ var $rootScope, element, displayElements;
beforeEach(module('textAngular'));
- beforeEach(inject(function (_$compile_, _$rootScope_) {
+ beforeEach(inject(function (_$compile_, _$rootScope_, textAngularManager) {
$rootScope = _$rootScope_;
$rootScope.htmlcontent = 'Test Content
';
element = _$compile_('Original Content
')($rootScope);
$rootScope.$digest();
+ displayElements = textAngularManager.retrieveEditor('test').scope.displayElements;
}));
- describe('Inserts the current information into the fields overriding the original content', function(){
+ describe('Inserts the current information into the fields', function(){
it('populates the WYSIWYG area', function(){
- expect(jQuery('.ta-text p', element).length).toBe(1);
+ expect(displayElements.text.find('p').length).toBe(1);
});
it('populates the textarea', function(){
- expect(jQuery('.ta-html', element).val()).toBe('Test Content
');
+ expect(displayElements.html.val()).toBe('Test Content
');
});
it('populates the hidden input value', function(){
- expect(jQuery('input[type=hidden]', element).val()).toBe('Test Content
');
+ expect(displayElements.forminput.val()).toBe('Test Content
');
});
});
});
describe('should respect the ta-default-wrap value', function(){
beforeEach(module('textAngular'));
- it('with ng-model', inject(function($rootScope, $compile){
+ it('with ng-model', inject(function($rootScope, $compile, textAngularManager){
$rootScope.html = '';
- element = $compile(' ')($rootScope).find('.ta-text');
+ $compile(' ')($rootScope);
+ element = textAngularManager.retrieveEditor('test').scope.displayElements.text;
$rootScope.$digest();
- element.trigger('focus');
+ element.triggerHandler('focus');
$rootScope.$digest();
expect(element.html()).toBe('
');
}));
- it('without ng-model', inject(function($rootScope, $compile){
- element = $compile(' ')($rootScope).find('.ta-text');
+ it('without ng-model', inject(function($rootScope, $compile, textAngularManager){
+ $compile(' ')($rootScope);
+ element = textAngularManager.retrieveEditor('test').scope.displayElements.text;
$rootScope.$digest();
- element.trigger('focus');
+ element.triggerHandler('focus');
$rootScope.$digest();
expect(element.html()).toBe('
');
}));
@@ -481,58 +497,60 @@ describe('textAngular', function(){
describe('Updates without ng-model', function(){
'use strict';
- var $rootScope, element;
+ var $rootScope, element, displayElements;
beforeEach(module('textAngular'));
- beforeEach(inject(function (_$compile_, _$rootScope_) {
+ beforeEach(inject(function (_$compile_, _$rootScope_, textAngularManager) {
$rootScope = _$rootScope_;
element = _$compile_('Test Content
')($rootScope);
$rootScope.$digest();
- jQuery('.ta-text', element).html('Test Change Content
');
- jQuery('.ta-text', element).triggerHandler('keyup');
+ displayElements = textAngularManager.retrieveEditor('test').scope.displayElements;
+ displayElements.text.html('Test Change Content
');
+ displayElements.text.triggerHandler('keyup');
$rootScope.$digest();
}));
describe('updates from .ta-text', function(){
it('should update .ta-html', function(){
- expect(jQuery('.ta-html', element).val()).toBe('Test Change Content
');
+ expect(displayElements.html.val()).toBe('Test Change Content
');
});
it('should update input[type=hidden]', function(){
- expect(jQuery('input[type=hidden]', element).val()).toBe('Test Change Content
');
+ expect(displayElements.forminput.val()).toBe('Test Change Content
');
});
});
describe('updates from .ta-html', function(){
it('should update .ta-text', function(){
- expect(jQuery('.ta-text', element).html()).toBe('Test Change Content
');
+ expect(displayElements.text.html()).toBe('Test Change Content
');
});
it('should update input[type=hidden]', function(){
- expect(jQuery('input[type=hidden]', element).val()).toBe('Test Change Content
');
+ expect(displayElements.forminput.val()).toBe('Test Change Content
');
});
});
});
describe('Updates with ng-model', function(){
'use strict';
- var $rootScope, element;
+ var $rootScope, element, displayElements;
beforeEach(module('textAngular'));
- beforeEach(inject(function (_$compile_, _$rootScope_) {
+ beforeEach(inject(function (_$compile_, _$rootScope_, textAngularManager) {
$rootScope = _$rootScope_;
$rootScope.htmlcontent = 'Test Content
';
element = _$compile_(' ')($rootScope);
$rootScope.$digest();
$rootScope.htmlcontent = 'Test Change Content
';
$rootScope.$digest();
+ displayElements = textAngularManager.retrieveEditor('test').scope.displayElements;
}));
describe('updates from model to display', function(){
it('should update .ta-html', function(){
- expect(jQuery('.ta-html', element).val()).toBe('Test Change Content
');
+ expect(displayElements.html.val()).toBe('Test Change Content
');
});
it('should update .ta-text', function(){
- expect(jQuery('.ta-text', element).html()).toBe('Test Change Content
');
+ expect(displayElements.text.html()).toBe('Test Change Content
');
});
it('should update input[type=hidden]', function(){
- expect(jQuery('input[type=hidden]', element).val()).toBe('Test Change Content
');
+ expect(displayElements.forminput.val()).toBe('Test Change Content
');
});
});
});
@@ -540,69 +558,69 @@ describe('textAngular', function(){
describe('ng-model should handle undefined and null', function(){
'use strict';
beforeEach(module('textAngular'));
- it('should handle initial undefined to empty-string', inject(function ($compile, $rootScope) {
+ it('should handle initial undefined to empty-string', inject(function ($compile, $rootScope, textAngularManager) {
$rootScope.htmlcontent = undefined;
var element = $compile(' ')($rootScope);
$rootScope.$digest();
- expect(jQuery('.ta-text', element).html()).toBe('
');
+ expect(textAngularManager.retrieveEditor('test').scope.displayElements.text.html()).toBe('
');
}));
- it('should handle initial null to empty-string', inject(function ($compile, $rootScope) {
+ it('should handle initial null to empty-string', inject(function ($compile, $rootScope, textAngularManager) {
$rootScope.htmlcontent = null;
var element = $compile(' ')($rootScope);
$rootScope.$digest();
- expect(jQuery('.ta-text', element).html()).toBe('
');
+ expect(textAngularManager.retrieveEditor('test').scope.displayElements.text.html()).toBe('
');
}));
- it('should handle initial undefined to originalContents', inject(function ($compile, $rootScope) {
+ it('should handle initial undefined to originalContents', inject(function ($compile, $rootScope, textAngularManager) {
$rootScope.htmlcontent = undefined;
var element = $compile('Test Contents ')($rootScope);
$rootScope.$digest();
- expect(jQuery('.ta-text', element).html()).toBe('Test Contents');
+ expect(textAngularManager.retrieveEditor('test').scope.displayElements.text.html()).toBe('Test Contents');
}));
- it('should handle initial null to originalContents', inject(function ($compile, $rootScope) {
+ it('should handle initial null to originalContents', inject(function ($compile, $rootScope, textAngularManager) {
$rootScope.htmlcontent = null;
var element = $compile('Test Contents ')($rootScope);
$rootScope.$digest();
- expect(jQuery('.ta-text', element).html()).toBe('Test Contents');
+ expect(textAngularManager.retrieveEditor('test').scope.displayElements.text.html()).toBe('Test Contents');
}));
describe('should reset', function(){
- it('from undefined to empty-string', inject(function ($compile, $rootScope) {
+ it('from undefined to empty-string', inject(function ($compile, $rootScope, textAngularManager) {
$rootScope.htmlcontent = 'Test Content';
var element = $compile(' ')($rootScope);
$rootScope.$digest();
$rootScope.htmlcontent = undefined;
$rootScope.$digest();
- expect(jQuery('.ta-text', element).html()).toBe('
');
+ expect(textAngularManager.retrieveEditor('test').scope.displayElements.text.html()).toBe('
');
}));
- it('from null to empty-string', inject(function ($compile, $rootScope) {
+ it('from null to empty-string', inject(function ($compile, $rootScope, textAngularManager) {
$rootScope.htmlcontent = 'Test Content';
var element = $compile(' ')($rootScope);
$rootScope.$digest();
$rootScope.htmlcontent = null;
$rootScope.$digest();
- expect(jQuery('.ta-text', element).html()).toBe('
');
+ expect(textAngularManager.retrieveEditor('test').scope.displayElements.text.html()).toBe('
');
}));
- it('from undefined to blank/emptystring WITH originalContents', inject(function ($compile, $rootScope) {
+ it('from undefined to blank/emptystring WITH originalContents', inject(function ($compile, $rootScope, textAngularManager) {
$rootScope.htmlcontent = 'Test Content1';
var element = $compile('Test Contents2 ')($rootScope);
$rootScope.$digest();
$rootScope.htmlcontent = undefined;
$rootScope.$digest();
- expect(jQuery('.ta-text', element).html()).toBe('
');
+ expect(textAngularManager.retrieveEditor('test').scope.displayElements.text.html()).toBe('
');
}));
- it('from null to blank/emptystring WITH originalContents', inject(function ($compile, $rootScope) {
+ it('from null to blank/emptystring WITH originalContents', inject(function ($compile, $rootScope, textAngularManager) {
$rootScope.htmlcontent = 'Test Content1';
var element = $compile('Test Contents2 ')($rootScope);
$rootScope.$digest();
$rootScope.htmlcontent = null;
$rootScope.$digest();
- expect(jQuery('.ta-text', element).html()).toBe('
');
+ expect(textAngularManager.retrieveEditor('test').scope.displayElements.text.html()).toBe('
');
}));
});
});
@@ -626,7 +644,7 @@ describe('textAngular', function(){
// setup selection
sel = window.rangy.getSelection();
range = window.rangy.createRangyRange();
- range.selectNodeContents(element.find('.ta-text p strong')[0]);
+ range.selectNodeContents(editorScope.displayElements.text.find('p').find('strong')[0]);
sel.setSingleRange(range);
}));
afterEach(function(){
@@ -647,7 +665,7 @@ describe('textAngular', function(){
expect(sel.toHtml()).toBe('sed do eiusmod tempor incididunt');
// change selection
var range = window.rangy.createRangyRange();
- range.selectNodeContents(element.find('.ta-text p i')[0]);
+ range.selectNodeContents(editorScope.displayElements.text.find('p').find('i')[0]);
sel.setSingleRange(range);
sel.refresh();
expect(sel.toHtml()).toBe('consectetur adipisicing');
@@ -669,7 +687,7 @@ describe('textAngular', function(){
var resetFunc = editorScope.startAction();
editorScope.endAction();
var range = window.rangy.createRangyRange();
- range.selectNodeContents(element.find('.ta-text p i')[0]);
+ range.selectNodeContents(editorScope.displayElements.text.find('p').find('i')[0]);
sel.setSingleRange(range);
sel.refresh();
expect(sel.toHtml()).toBe('consectetur adipisicing');
@@ -707,7 +725,7 @@ describe('textAngular', function(){
// setup selection
var sel = _rangy.getSelection();
var range = _rangy.createRangyRange();
- range.selectNodeContents(element.find('.ta-text p strong')[0]);
+ range.selectNodeContents(editorScope.displayElements.text.find('p').find('strong')[0]);
sel.setSingleRange(range);
}));
@@ -762,7 +780,7 @@ describe('textAngular', function(){
// setup selection
sel = window.rangy.getSelection();
range = window.rangy.createRangyRange();
- range.selectNodeContents(element.find('.ta-text p i')[0]);
+ range.selectNodeContents(editorScope.displayElements.text.find('p').find('i')[0]);
sel.setSingleRange(range);
}));
afterEach(inject(function(taSelectableElements){
@@ -771,31 +789,31 @@ describe('textAngular', function(){
}));
it('should not trigger focus out while an action is processing', inject(function($timeout){
- element.find('.ta-text').triggerHandler('focus');
+ editorScope.displayElements.text.triggerHandler('focus');
editorScope.$parent.$digest();
editorScope.startAction();
- element.find('.ta-text').triggerHandler('blur');
+ editorScope.displayElements.text.triggerHandler('blur');
editorScope.$parent.$digest();
$timeout.flush();
- expect(element.find('button:disabled').length).toBe(0);
+ expect(jQuery(element[0]).find('button:disabled').length).toBe(0);
}));
it('keypress should call sendKeyCommand', function(){
- element.find('.ta-text').trigger({type: 'keypress', metaKey: true, which: 21});
+ editorScope.displayElements.text.triggerHandler('keypress', {metaKey: true, which: 21});
editorScope.$parent.$digest();
- expect(element.find('.ta-toolbar button[name=testbutton]').attr('hit-this')).toBe('true');
+ expect(jQuery(element[0]).find('.ta-toolbar button[name=testbutton]').attr('hit-this')).toBe('true');
});
describe('wrapSelection', function(){
it('should wrap the selected text in tags', function(){
editorScope.wrapSelection('bold');
- expect(element.find('.ta-text p b').length).toBe(1);
+ expect(editorScope.displayElements.text.find('p').find('b').length).toBe(1);
});
it('should unwrap the selected text in tags on re-call', function(){
editorScope.wrapSelection('bold');
editorScope.wrapSelection('bold');
- expect(element.find('.ta-text p b').length).toBe(0);
+ expect(editorScope.displayElements.text.find('p').find('b').length).toBe(0);
});
});
@@ -812,21 +830,21 @@ describe('textAngular', function(){
describe('ta-element-select event', function(){
it('fires correctly on element selector', function(){
- var triggerElement = element.find('.ta-text i');
+ var triggerElement = editorScope.displayElements.text.find('i');
triggerElement.triggerHandler('click');
expect(triggerElement.attr('hit-via-select')).toBe('true');
});
it('fires correctly when filter returns true', inject(function(taTools){
taTools.testbutton.onElementSelect.filter = function(){ return true; };
- var triggerElement = element.find('.ta-text i');
+ var triggerElement = editorScope.displayElements.text.find('i');
triggerElement.triggerHandler('click');
expect(triggerElement.attr('hit-via-select')).toBe('true');
}));
it('does not fire when filter returns false', inject(function(taTools){
taTools.testbutton.onElementSelect.filter = function(){ return false; };
- var triggerElement = element.find('.ta-text i');
+ var triggerElement = editorScope.displayElements.text.find('i');
triggerElement.triggerHandler('click');
expect(triggerElement.attr('hit-via-select')).toBeUndefined();
}));
@@ -834,12 +852,13 @@ describe('textAngular', function(){
describe('popover', function(){
it('should show the popover', function(){
- editorScope.showPopover(element.find('.ta-text p i'));
+ editorScope.showPopover(editorScope.displayElements.text.find('p').find('i'));
expect(editorScope.displayElements.popover.hasClass('in')).toBe(true);
});
describe('should hide the popover', function(){
beforeEach(inject(function($timeout){
- editorScope.showPopover(element.find('.ta-text p i'));
+ editorScope.showPopover(editorScope.displayElements.text.find('p').find('i'));
+ editorScope.$parent.$digest();
$timeout.flush();
editorScope.$parent.$digest();
}));
@@ -848,18 +867,24 @@ describe('textAngular', function(){
expect(editorScope.displayElements.popover.hasClass('in')).toBe(false);
});
it('on click in editor', function(){
- editorScope.displayElements.html.parent().triggerHandler('click');
+ element.triggerHandler('click');
editorScope.$parent.$digest();
expect(editorScope.displayElements.popover.hasClass('in')).toBe(false);
});
it('should prevent mousedown from propagating up from popover', function(){
- var test = false;
- editorScope.displayElements.popover.on('mousedown', function(e){
- test = e.isDefaultPrevented();
- });
- editorScope.displayElements.popover.triggerHandler('mousedown');
- editorScope.$parent.$digest();
- expect(test).toBe(true);
+ var event;
+ if(angular.element === jQuery){
+ event = jQuery.Event('mousedown');
+ editorScope.displayElements.popover.triggerHandler(event);
+ editorScope.$parent.$digest();
+ expect(event.isDefaultPrevented()).toBe(true);
+ }else{
+ var _defaultPrevented = false;
+ event = {preventDefault: function(){ _defaultPrevented = true; }};
+ editorScope.displayElements.popover.triggerHandler('mousedown', event);
+ editorScope.$parent.$digest();
+ expect(_defaultPrevented).toBe(true);
+ }
});
});
});
@@ -876,26 +901,26 @@ describe('textAngular', function(){
});
it('should change on keypress', function(){
- range.selectNodeContents(element.find('.ta-text p u')[0]);
+ range.selectNodeContents(editorScope.displayElements.text.find('p').find('u')[0]);
sel.setSingleRange(range);
- element.find('.ta-text').triggerHandler('keypress');
+ editorScope.displayElements.text.triggerHandler('keypress');
expect(!iButton.hasClass('active'));
});
it('should change on keydown and stop on keyup', inject(function($timeout){
- element.find('.ta-text').triggerHandler('keydown');
- range.selectNodeContents(element.find('.ta-text p u')[0]);
+ editorScope.displayElements.text.triggerHandler('keydown');
+ range.selectNodeContents(editorScope.displayElements.text.find('p').find('u')[0]);
sel.setSingleRange(range);
setTimeout(function(){
expect(!iButton.hasClass('active'));
setTimeout(function(){
range = window.rangy.createRangyRange();
- range.selectNodeContents(element.find('.ta-text p i')[0]);
+ range.selectNodeContents(editorScope.displayElements.text.find('p').find('i')[0]);
setTimeout(function(){
expect(iButton.hasClass('active'));
- element.find('.ta-text').triggerHandler('keydown');
+ editorScope.displayElements.text.triggerHandler('keydown');
setTimeout(function(){
- range.selectNodeContents(element.find('.ta-text p u')[0]);
+ range.selectNodeContents(editorScope.displayElements.text.find('p').find('u')[0]);
setTimeout(function(){
expect(iButton.hasClass('active'));
}, 201);
@@ -906,9 +931,9 @@ describe('textAngular', function(){
}));
it('should change on mouseup', function(){
- range.selectNodeContents(element.find('.ta-text p u')[0]);
+ range.selectNodeContents(editorScope.displayElements.text.find('p').find('u')[0]);
sel.setSingleRange(range);
- element.find('.ta-text').triggerHandler('mouseup');
+ editorScope.displayElements.text.triggerHandler('mouseup');
expect(!iButton.hasClass('active'));
});
});
@@ -916,6 +941,10 @@ describe('textAngular', function(){
describe('File Drop Event', function(){
beforeEach(module('textAngular'));
+ var textAngularManager;
+ beforeEach(inject(function(_textAngularManager_){
+ textAngularManager = _textAngularManager_;
+ }));
afterEach(inject(function($timeout){
try{
$timeout.flush();
@@ -929,7 +958,8 @@ describe('textAngular', function(){
testvar = true;
};
element = $compile(' ')($rootScope);
- element.find('.ta-text').triggerHandler({type: 'drop', originalEvent: {dataTransfer: {files: ['test'], types: ['files']}}});
+ if(jQuery === angular.element) textAngularManager.retrieveEditor('test').scope.displayElements.text.triggerHandler({type: 'drop', originalEvent: {dataTransfer: {files: ['test'], types: ['files']}}});
+ else textAngularManager.retrieveEditor('test').scope.displayElements.text.triggerHandler('drop', {originalEvent: {dataTransfer: {files: ['test'], types: ['files']}}});
$rootScope.$digest();
expect(testvar).toBe(true);
}));
@@ -941,7 +971,8 @@ describe('textAngular', function(){
testvar = true;
};
element = $compile(' ')($rootScope);
- element.find('.ta-text').triggerHandler({type: 'drop', originalEvent: {dataTransfer: {files: ['test'], types: ['files']}}});
+ if(jQuery === angular.element) textAngularManager.retrieveEditor('test').scope.displayElements.text.triggerHandler({type: 'drop', originalEvent: {dataTransfer: {files: ['test'], types: ['files']}}});
+ else textAngularManager.retrieveEditor('test').scope.displayElements.text.triggerHandler('drop', {originalEvent: {dataTransfer: {files: ['test'], types: ['files']}}});
$rootScope.$digest();
expect(testvar).toBe(true);
}));
@@ -953,14 +984,17 @@ describe('textAngular', function(){
testvar = true;
};
element = $compile(' ')($rootScope);
- element.find('.ta-text').triggerHandler({type: 'drop', originalEvent: {dataTransfer: {files: [], types: ['url or something']}}});
+ if(jQuery === angular.element) textAngularManager.retrieveEditor('test').scope.displayElements.text.triggerHandler({type: 'drop', originalEvent: {dataTransfer: {files: [], types: ['url or something']}}});
+ else textAngularManager.retrieveEditor('test').scope.displayElements.text.triggerHandler('drop', {originalEvent: {dataTransfer: {files: [], types: ['url or something']}}});
$rootScope.$digest();
expect(testvar).toBe(false);
expect(function(){
- element.find('.ta-text').triggerHandler({type: 'drop', originalEvent: {dataTransfer: {}}});
+ if(jQuery === angular.element) textAngularManager.retrieveEditor('test').scope.displayElements.text.triggerHandler({type: 'drop', originalEvent: {dataTransfer: {}}});
+ else textAngularManager.retrieveEditor('test').scope.displayElements.text.triggerHandler('drop', {originalEvent: {dataTransfer: {}}});
}).not.toThrow();
expect(function(){
- element.find('.ta-text').triggerHandler({type: 'drop', originalEvent: {}});
+ if(jQuery === angular.element) textAngularManager.retrieveEditor('test').scope.displayElements.text.triggerHandler({type: 'drop', originalEvent: {}});
+ else textAngularManager.retrieveEditor('test').scope.displayElements.text.triggerHandler('drop', {originalEvent: {}});
}).not.toThrow();
}));
@@ -974,9 +1008,10 @@ describe('textAngular', function(){
element = $compile(' ')($rootScope);
$document.find('body').append(element);
$rootScope.$digest();
- element.find('.ta-text').triggerHandler({type: 'drop', originalEvent: {dataTransfer: {files: ['test'], types: ['files']}}});
+ if(jQuery === angular.element) textAngularManager.retrieveEditor('test').scope.displayElements.text.triggerHandler({type: 'drop', originalEvent: {dataTransfer: {files: ['test'], types: ['files']}}});
+ else textAngularManager.retrieveEditor('test').scope.displayElements.text.triggerHandler('drop', {originalEvent: {dataTransfer: {files: ['test'], types: ['files']}}});
$rootScope.$digest();
- expect(element.find('.ta-text').html()).toBe('
');
+ expect(textAngularManager.retrieveEditor('test').scope.displayElements.text.html()).toBe('
');
element.remove();
}));
it('attr function inserts returned html', inject(function($compile, $rootScope, taOptions, $document){
@@ -988,9 +1023,10 @@ describe('textAngular', function(){
element = $compile(' ')($rootScope);
$document.find('body').append(element);
$rootScope.$digest();
- element.find('.ta-text').triggerHandler({type: 'drop', originalEvent: {dataTransfer: {files: ['test'], types: ['files']}}});
+ if(jQuery === angular.element) textAngularManager.retrieveEditor('test').scope.displayElements.text.triggerHandler({type: 'drop', originalEvent: {dataTransfer: {files: ['test'], types: ['files']}}});
+ else textAngularManager.retrieveEditor('test').scope.displayElements.text.triggerHandler('drop', {originalEvent: {dataTransfer: {files: ['test'], types: ['files']}}});
$rootScope.$digest();
- expect(element.find('.ta-text').html()).toBe('
');
+ expect(textAngularManager.retrieveEditor('test').scope.displayElements.text.html()).toBe('
');
element.remove();
}));
it('attr function overrides default', inject(function($compile, $rootScope, taOptions, $document){
@@ -1006,9 +1042,10 @@ describe('textAngular', function(){
element = $compile(' ')($rootScope);
$document.find('body').append(element);
$rootScope.$digest();
- element.find('.ta-text').triggerHandler({type: 'drop', originalEvent: {dataTransfer: {files: ['test'], types: ['files']}}});
+ if(jQuery === angular.element) textAngularManager.retrieveEditor('test').scope.displayElements.text.triggerHandler({type: 'drop', originalEvent: {dataTransfer: {files: ['test'], types: ['files']}}});
+ else textAngularManager.retrieveEditor('test').scope.displayElements.text.triggerHandler('drop', {originalEvent: {dataTransfer: {files: ['test'], types: ['files']}}});
$rootScope.$digest();
- expect(element.find('.ta-text').html()).toBe('
');
+ expect(textAngularManager.retrieveEditor('test').scope.displayElements.text.html()).toBe('
');
element.remove();
}));
it('default inserted if attr function returns false', inject(function($compile, $rootScope, taOptions, $document){
@@ -1023,9 +1060,10 @@ describe('textAngular', function(){
element = $compile(' ')($rootScope);
$document.find('body').append(element);
$rootScope.$digest();
- element.find('.ta-text').triggerHandler({type: 'drop', originalEvent: {dataTransfer: {files: ['test'], types: ['files']}}});
+ if(jQuery === angular.element) textAngularManager.retrieveEditor('test').scope.displayElements.text.triggerHandler({type: 'drop', originalEvent: {dataTransfer: {files: ['test'], types: ['files']}}});
+ else textAngularManager.retrieveEditor('test').scope.displayElements.text.triggerHandler('drop', {originalEvent: {dataTransfer: {files: ['test'], types: ['files']}}});
$rootScope.$digest();
- expect(element.find('.ta-text').html()).toBe('
');
+ expect(textAngularManager.retrieveEditor('test').scope.displayElements.text.html()).toBe('
');
element.remove();
}));
});
@@ -1044,15 +1082,15 @@ describe('textAngular', function(){
$rootScope.$digest();
}));
- it('should re-focus on toolbar when swapping directly from editor to editor', inject(function($timeout){
- element1.find('.ta-text').triggerHandler('focus');
+ it('should re-focus on toolbar when swapping directly from editor to editor', inject(function($timeout, textAngularManager){
+ textAngularManager.retrieveEditor('test1').scope.displayElements.text.triggerHandler('focus');
$rootScope.$digest();
- expect(toolbar.find('button:not(:disabled)').length).toBe(25);
- element2.find('.ta-text').triggerHandler('focus');
+ expect(jQuery(toolbar[0]).find('button:not(:disabled)').length).toBe(25);
+ textAngularManager.retrieveEditor('test2').scope.displayElements.text.triggerHandler('focus');
$rootScope.$digest();
$timeout.flush();
// expect none to be disabled
- expect(toolbar.find('button:not(:disabled)').length).toBe(25);
+ expect(jQuery(toolbar[0]).find('button:not(:disabled)').length).toBe(25);
}));
});
});
\ No newline at end of file
diff --git a/test/textAngularManager.spec.js b/test/textAngularManager.spec.js
index a24c0dc1..8491b88d 100644
--- a/test/textAngularManager.spec.js
+++ b/test/textAngularManager.spec.js
@@ -53,8 +53,8 @@ describe('textAngularManager', function(){
}));
beforeEach(inject(function (_$compile_, _$rootScope_) {
$rootScope = _$rootScope_;
- toolbar1 = _$compile_(' ')($rootScope);
- toolbar2 = _$compile_(' ')($rootScope);
+ toolbar1 = jQuery(_$compile_(' ')($rootScope)[0]);
+ toolbar2 = jQuery(_$compile_(' ')($rootScope)[0]);
$rootScope.$digest();
}));
@@ -349,7 +349,7 @@ describe('textAngularManager', function(){
});
taOptions.toolbar = [['noactivestate','activeonrangyrange','inactiveonrangyrange','onselect','onselectattr','onselectattr_specific']];
$rootScope = _$rootScope_;
- element = _$compile_('Test Content
')($rootScope);
+ element = jQuery(_$compile_('Test Content
')($rootScope)[0]);
$rootScope.$digest();
editorScope = textAngularManager.retrieveEditor('test');
}));
@@ -472,7 +472,7 @@ describe('textAngularManager', function(){
expect(function(){textAngularManager.refreshEditor('non-editor');}).toThrow('textAngular Error: No Editor with name "non-editor" exists');
}));
it('should update from text view to model', inject(function(textAngularManager){
- jQuery('.ta-text', element).append('Test 2 Content
');
+ jQuery('.ta-text', element[0]).append('Test 2 Content
');
textAngularManager.refreshEditor('test');
expect($rootScope.htmlcontent).toBe('Test Content
Test 2 Content
');
}));
diff --git a/test/textAngularToolbar.spec.js b/test/textAngularToolbar.spec.js
index baf89c98..78c4415b 100644
--- a/test/textAngularToolbar.spec.js
+++ b/test/textAngularToolbar.spec.js
@@ -29,12 +29,12 @@ describe('textAngularToolbar', function(){
describe('respects the taToolbar attribute compiled string', function(){
it('should output the correct toolbar', inject(function($rootScope, $compile){
var element = $compile(' ')($rootScope);
- expect(jQuery('button', element).length).toBe(6);
+ expect(jQuery('button', element[0]).length).toBe(6);
}));
it('via text-angular should output the correct toolbar', inject(function($rootScope, $compile){
var element = $compile(' ')($rootScope);
- expect(jQuery('button', element).length).toBe(6);
+ expect(jQuery('button', element[0]).length).toBe(6);
}));
});
@@ -42,50 +42,50 @@ describe('textAngularToolbar', function(){
it('should output the correct toolbar', inject(function($rootScope, $compile){
$rootScope.toolbar = [['h1','h2','h3','h4','h5','h6']];
var element = $compile(' ')($rootScope);
- expect(jQuery('button', element).length).toBe(6);
+ expect(jQuery('button', element[0]).length).toBe(6);
}));
it('via text-angular should output the correct toolbar', inject(function($rootScope, $compile){
$rootScope.toolbar = [['h1','h2','h3','h4','h5','h6']];
var element = $compile(' ')($rootScope);
- expect(jQuery('button', element).length).toBe(6);
+ expect(jQuery('button', element[0]).length).toBe(6);
}));
});
describe('respects the Class attribute taToolbarClass', function(){
it('on the toolbar', inject(function($rootScope, $compile){
var element = $compile(' ')($rootScope);
- expect(jQuery('.test-class', element).length).toBe(0);
+ expect(jQuery('.test-class', element[0]).length).toBe(0);
expect(jQuery(element).hasClass('test-class'));
}));
it('via text-angular on the toolbar', inject(function($rootScope, $compile){
var element = $compile(' ')($rootScope);
- expect(jQuery('.test-class', element).length).toBe(1);
+ expect(jQuery('.test-class', element[0]).length).toBe(1);
}));
});
describe('respects the Class attribute taToolbarGroupClass', function(){
it('on the toolbar group', inject(function($rootScope, $compile){
var element = $compile(' ')($rootScope);
- expect(jQuery('.test-class', element).length).toBe(4);
+ expect(jQuery('.test-class', element[0]).length).toBe(4);
}));
it('via text-angular on the toolbar group', inject(function($rootScope, $compile){
var element = $compile(' ')($rootScope);
- expect(jQuery('.test-class', element).length).toBe(4);
+ expect(jQuery('.test-class', element[0]).length).toBe(4);
}));
});
describe('respects the Class attribute taToolbarButtonClass', function(){
it('adds to all buttons', inject(function($rootScope, $compile){
var element = $compile(' ')($rootScope);
- expect(jQuery('button:not(.test-class)', element).length).toBe(0);
+ expect(jQuery('button:not(.test-class)', element[0]).length).toBe(0);
}));
it('via text-angular adds to all buttons', inject(function($rootScope, $compile){
var element = $compile(' ')($rootScope);
- expect(jQuery('button:not(.test-class)', element).length).toBe(0);
+ expect(jQuery('button:not(.test-class)', element[0]).length).toBe(0);
}));
});
@@ -101,7 +101,7 @@ describe('textAngularToolbar', function(){
}
});
$rootScope.$digest();
- expect(jQuery('button.test-class', element).length).toBe(1);
+ expect(jQuery('button.test-class', element[0]).length).toBe(1);
}));
it('via text-angular on an active button', inject(function($rootScope, $compile, textAngularManager){
@@ -115,7 +115,7 @@ describe('textAngularToolbar', function(){
}
});
$rootScope.$digest();
- expect(jQuery('button.test-class', element).length).toBe(1);
+ expect(jQuery('button.test-class', element[0]).length).toBe(1);
}));
});
@@ -150,45 +150,46 @@ describe('textAngularToolbar', function(){
});
describe('enables and disables from editor', function(){
- var $rootScope, element, $timeout;
- beforeEach(inject(function (_$compile_, _$rootScope_, _$timeout_) {
+ var $rootScope, element, $timeout, displayElements;
+ beforeEach(inject(function (_$compile_, _$rootScope_, _$timeout_, textAngularManager) {
$timeout = _$timeout_;
$rootScope = _$rootScope_;
- element = _$compile_(' ')($rootScope);
+ _$compile_(' ')($rootScope);
$rootScope.$digest();
+ displayElements = textAngularManager.retrieveEditor('test').scope.displayElements;
}));
describe('should have activated all buttons', function(){
it('on trigger focus on ta-text', function(){
- element.find('.ta-text').triggerHandler('focus');
+ displayElements.text.triggerHandler('focus');
$rootScope.$digest();
- expect(element.find('button').attr('disabled')).toBeUndefined();
+ expect(jQuery(displayElements.text.parent()).find('button').eq(0).attr('disabled')).toBeUndefined();
});
it('on trigger focus on ta-html', function(){
- element.find('.ta-html').triggerHandler('focus');
+ displayElements.html.triggerHandler('focus');
$rootScope.$digest();
- expect(element.find('button').attr('disabled')).toBeUndefined();
+ expect(jQuery(displayElements.html.parent()).find('button').eq(0).attr('disabled')).toBeUndefined();
});
});
describe('should have disabled all buttons', function(){
it('on ta-text trigger blur', function(){
- element.find('.ta-text').triggerHandler('focus');
+ displayElements.text.triggerHandler('focus');
$rootScope.$digest();
- element.find('.ta-text').triggerHandler('blur');
+ displayElements.text.triggerHandler('blur');
$rootScope.$digest();
$timeout.flush();
$rootScope.$digest();
- expect(element.find('button').attr('disabled')).toBe('disabled');
+ expect(jQuery(displayElements.text.parent()).find('button').eq(0).attr('disabled')).toBe('disabled');
});
it('on ta-html trigger blur', function(){
- element.find('.ta-html').triggerHandler('focus');
+ displayElements.html.triggerHandler('focus');
$rootScope.$digest();
- element.find('.ta-html').triggerHandler('blur');
+ displayElements.html.triggerHandler('blur');
$rootScope.$digest();
$timeout.flush();
$rootScope.$digest();
- expect(element.find('button').attr('disabled')).toBe('disabled');
+ expect(jQuery(displayElements.html.parent()).find('button').eq(0).attr('disabled')).toBe('disabled');
});
});
});
@@ -218,7 +219,7 @@ describe('textAngularToolbar', function(){
toolbarScope.disabled = false;
toolbarScope.focussed = true;
$rootScope.$digest();
- element = $('button', element).eq(0);
+ element = element.find('button').eq(0);
}));
it('should have a name', function(){
@@ -246,10 +247,19 @@ describe('textAngularToolbar', function(){
});
it('should prevent event on mousedown', function(){
- element.on('mousedown', function(e){
- expect(e.isDefaultPrevented());
- });
- element.triggerHandler('mousedown');
+ var event;
+ if(angular.element === jQuery){
+ event = jQuery.Event('mousedown');
+ element.triggerHandler(event);
+ $rootScope.$digest();
+ expect(event.isDefaultPrevented()).toBe(true);
+ }else{
+ var _defaultPrevented = false;
+ event = {preventDefault: function(){ _defaultPrevented = true; }};
+ element.triggerHandler('mousedown', event);
+ $rootScope.$digest();
+ expect(_defaultPrevented).toBe(true);
+ }
});
});
@@ -271,19 +281,19 @@ describe('textAngularToolbar', function(){
describe('displaying the button', function(){
it('should override everything with the html in the display attribute', function(){
- expect($('div[name=display]', element).html()).toBe('THIS IS A TEST DIV');
+ expect($('div[name=display]', element[0]).html()).toBe('THIS IS A TEST DIV');
});
it('should display only buttontext in the button', function(){
- expect($('button[name=buttontext]', element).html()).toBe('Only Text');
+ expect($('button[name=buttontext]', element[0]).html()).toBe('Only Text');
});
it('should display only icon in the button', function(){
- expect($('button[name=iconclass]', element).html()).toBe(' ');
+ expect($('button[name=iconclass]', element[0]).html()).toBe(' ');
});
it('should display both icon and buttontext in the button', function(){
- expect($('button[name=iconandtext]', element).html()).toBe(' good text');
+ expect($('button[name=iconandtext]', element[0]).html()).toBe(' good text');
});
});
@@ -308,19 +318,19 @@ describe('textAngularToolbar', function(){
}));
it('should override the old display with the html in the new display attribute', function(){
- expect($('div[name=display]', element).html()).toBe('Replaced Text');
+ expect($('div[name=display]', element[0]).html()).toBe('Replaced Text');
});
it('should display only new buttontext in the button', function(){
- expect($('button[name=buttontext]', element).html()).toBe('otherstuff');
+ expect($('button[name=buttontext]', element[0]).html()).toBe('otherstuff');
});
it('should display only new icon in the button', function(){
- expect($('button[name=iconclass]', element).html()).toBe(' ');
+ expect($('button[name=iconclass]', element[0]).html()).toBe(' ');
});
it('should display both new icon and new buttontext in the button', function(){
- expect($('button[name=iconandtext]', element).html()).toBe(' otherstuff');
+ expect($('button[name=iconandtext]', element[0]).html()).toBe(' otherstuff');
});
});
@@ -345,19 +355,19 @@ describe('textAngularToolbar', function(){
}));
it('should override the old display with the html in the new display attribute', function(){
- expect($('div[name=display]', element).html()).toBe('Replaced Text');
+ expect($('div[name=display]', element[0]).html()).toBe('Replaced Text');
});
it('should display only new buttontext in the button', function(){
- expect($('button[name=buttontext]', element).html()).toBe('otherstuff');
+ expect($('button[name=buttontext]', element[0]).html()).toBe('otherstuff');
});
it('should display only new icon in the button', function(){
- expect($('button[name=iconclass]', element).html()).toBe(' ');
+ expect($('button[name=iconclass]', element[0]).html()).toBe(' ');
});
it('should display both new icon and new buttontext in the button', function(){
- expect($('button[name=iconandtext]', element).html()).toBe(' otherstuff');
+ expect($('button[name=iconandtext]', element[0]).html()).toBe(' otherstuff');
});
});
@@ -394,15 +404,15 @@ describe('textAngularToolbar', function(){
it('should remove the display attribute and follow the other rules', function(){
// note as it is reset this is now a button not a div
- expect($('button[name=display]', element).html()).toBe(' This isnt a test');
+ expect($('button[name=display]', element[0]).html()).toBe(' This isnt a test');
});
it('should remove the button text', function(){
- expect($('button[name=buttontext]', element).html()).toBe(' ');
+ expect($('button[name=buttontext]', element[0]).html()).toBe(' ');
});
it('should remove the icon tag', function(){
- expect($('button[name=iconclass]', element).html()).toBe('More text to insert');
+ expect($('button[name=iconclass]', element[0]).html()).toBe('More text to insert');
});
it('should error on attempting to set all 3 to null', inject(function(textAngularManager){
@@ -423,7 +433,7 @@ describe('textAngularToolbar', function(){
manager = textAngularManager;
taOptions.toolbar = [['h1','h2','h3','h4']];
$rootScope = _$rootScope_;
- element = $compile(' ')($rootScope);
+ element = jQuery($compile(' ')($rootScope)[0]);
toolbarScope = textAngularManager.retrieveToolbar('test1');
toolbarScope.disabled = false;
toolbarScope.focussed = true;
@@ -535,7 +545,7 @@ describe('textAngularToolbar', function(){
taRegisterTool('disabled2', {buttontext: 'allways-disabled', disabled: function(){ return true;}});
taOptions.toolbar = [['disabled1','disabled2']];
$rootScope = _$rootScope_;
- element = $compile(' ')($rootScope);
+ element = jQuery($compile(' ')($rootScope)[0]);
toolbarScope = textAngularManager.retrieveToolbar('test');
toolbarScope.disabled = false;
toolbarScope.focussed = true;