");b.addClass(g.classes.toolbarGroup),angular.forEach(a,function(a){g.tools[a]=angular.extend(g.$new(!0),d[a],k,{name:a}),g.tools[a].$element=j(d[a],g.tools[a]),b.append(g.tools[a].$element)}),h.append(b)}),g.updateToolDisplay=function(a,b,c){var d=g.tools[a];if(d){if(d._lastToolDefinition&&!c&&(b=angular.extend({},d._lastToolDefinition,b)),null===b.buttontext&&null===b.iconclass&&null===b.display)throw'textAngular Error: Tool Definition for updating "'+a+'" does not have a valid display/iconclass/buttontext value';null===b.buttontext&&delete b.buttontext,null===b.iconclass&&delete b.iconclass,null===b.display&&delete b.display;var e=j(b,d);d.$element.replaceWith(e),d.$element=e}},g.addTool=function(a,b,c,e){g.tools[a]=angular.extend(g.$new(!0),d[a],k,{name:a}),g.tools[a].$element=j(d[a],g.tools[a]);var f;void 0===c&&(c=g.toolbar.length-1),f=angular.element(h.children()[c]),void 0===e?(f.append(g.tools[a].$element),g.toolbar[c][g.toolbar[c].length-1]=a):(f.children().eq(e).after(g.tools[a].$element),g.toolbar[c][e]=a)},b.registerToolbar(g),g.$on("$destroy",function(){b.unregisterToolbar(g.name)})}}}])}()}({},function(){return this}());
\ No newline at end of file
+})),a(l.displayElements.scrollWindow)(l),a(l.displayElements.html)(l),l.updateTaBindtaTextElement=l["updateTaBindtaTextElement"+y],l.updateTaBindtaHtmlElement=l["updateTaBindtaHtmlElement"+y],m.addClass("ta-root"),l.displayElements.scrollWindow.addClass("ta-text ta-editor "+l.classes.textEditor),l.displayElements.html.addClass("ta-html ta-editor "+l.classes.htmlEditor),l._actionRunning=!1;var A=!1;if(l.startAction=function(){return l._actionRunning=!0,A=g.rangy.saveSelection(),function(){A&&g.rangy.restoreSelection(A)}},l.endAction=function(){l._actionRunning=!1,A&&g.rangy.removeMarkers(A),A=!1,l.updateSelectedStyles(),l.showHtml||l["updateTaBindtaTextElement"+y]()},t=function(){m.addClass(l.classes.focussed),w.focus()},l.displayElements.html.on("focus",t),l.displayElements.text.on("focus",t),u=function(a){return l._actionRunning||h[0].activeElement===l.displayElements.html[0]||h[0].activeElement===l.displayElements.text[0]||(m.removeClass(l.classes.focussed),w.unfocus(),b(function(){m.triggerHandler("blur")},0)),a.preventDefault(),!1},l.displayElements.html.on("blur",u),l.displayElements.text.on("blur",u),l.queryFormatBlockState=function(a){return!l.showHtml&&a.toLowerCase()===h[0].queryCommandValue("formatBlock").toLowerCase()},l.queryCommandState=function(a){return l.showHtml?"":h[0].queryCommandState(a)},l.switchView=function(){l.showHtml=!l.showHtml,i.enabled(!1,l.displayElements.html),i.enabled(!1,l.displayElements.text),l.showHtml?b(function(){return i.enabled(!0,l.displayElements.html),i.enabled(!0,l.displayElements.text),l.displayElements.html[0].focus()},100):b(function(){return i.enabled(!0,l.displayElements.html),i.enabled(!0,l.displayElements.text),l.displayElements.text[0].focus()},100)},n.ngModel){var B=!0;o.$render=function(){if(B){B=!1;var a=l.$parent.$eval(n.ngModel);void 0!==a&&null!==a||!v||""===v||o.$setViewValue(v)}l.displayElements.forminput.val(o.$viewValue),l._elementSelectTriggered||h[0].activeElement===l.displayElements.html[0]||h[0].activeElement===l.displayElements.text[0]||(l.html=o.$viewValue||"")};var C=function(a){return n.required&&o.$setValidity("required",!(!a||""===a.trim())),a};o.$parsers.push(C),o.$formatters.push(C)}else l.displayElements.forminput.val(v),l.html=v;if(l.$watch("html",function(a,b){a!==b&&(n.ngModel&&o.$viewValue!==a&&o.$setViewValue(a),l.displayElements.forminput.val(a))}),n.taTargetToolbars)w=f.registerEditor(l._name,l,n.taTargetToolbars.split(","));else{var D=angular.element('
');n.taToolbar&&D.attr("ta-toolbar",n.taToolbar),n.taToolbarClass&&D.attr("ta-toolbar-class",n.taToolbarClass),n.taToolbarGroupClass&&D.attr("ta-toolbar-group-class",n.taToolbarGroupClass),n.taToolbarButtonClass&&D.attr("ta-toolbar-button-class",n.taToolbarButtonClass),n.taToolbarActiveButtonClass&&D.attr("ta-toolbar-active-button-class",n.taToolbarActiveButtonClass),n.taFocussedClass&&D.attr("ta-focussed-class",n.taFocussedClass),m.prepend(D),a(D)(l.$parent),w=f.registerEditor(l._name,l,["textAngularToolbar"+y])}l.$on("$destroy",function(){f.unregisterEditor(l._name)}),l.$on("ta-element-select",function(a,b){w.triggerElementSelect(a,b)&&l["reApplyOnSelectorHandlerstaTextElement"+y]()}),l.$on("ta-drop-event",function(a,c,d,e){l.displayElements.text[0].focus(),e&&e.files&&e.files.length>0?(angular.forEach(e.files,function(a){try{k.when(l.fileDropHandler(a,l.wrapSelection)||l.fileDropHandler!==l.defaultFileDropHandler&&k.when(l.defaultFileDropHandler(a,l.wrapSelection))).then(function(){l["updateTaBindtaTextElement"+y]()})}catch(b){j.error(b)}}),d.preventDefault(),d.stopPropagation()):b(function(){l["updateTaBindtaTextElement"+y]()},0)}),l._bUpdateSelectedStyles=!1,angular.element(window).on("blur",function(){l._bUpdateSelectedStyles=!1}),l.updateSelectedStyles=function(){var a;void 0!==(a=d.getSelectionElement())&&a.parentNode!==l.displayElements.text[0]?w.updateSelectedStyles(angular.element(a)):w.updateSelectedStyles(),l._bUpdateSelectedStyles&&b(l.updateSelectedStyles,200)},p=function(){l._bUpdateSelectedStyles||(l._bUpdateSelectedStyles=!0,l.$apply(function(){l.updateSelectedStyles()}))},l.displayElements.html.on("keydown",p),l.displayElements.text.on("keydown",p),q=function(){l._bUpdateSelectedStyles=!1},l.displayElements.html.on("keyup",q),l.displayElements.text.on("keyup",q),r=function(a,b){b&&angular.extend(a,b),l.$apply(function(){return w.sendKeyCommand(a)?(l._bUpdateSelectedStyles||l.updateSelectedStyles(),a.preventDefault(),!1):void 0})},l.displayElements.html.on("keypress",r),l.displayElements.text.on("keypress",r),s=function(){l._bUpdateSelectedStyles=!1,l.$apply(function(){l.updateSelectedStyles()})},l.displayElements.html.on("mouseup",s),l.displayElements.text.on("mouseup",s)}}}]),q.service("textAngularManager",["taToolExecuteAction","taTools","taRegisterTool",function(a,b,c){var d={},e={};return{registerEditor:function(c,f,g){if(!c||""===c)throw"textAngular Error: An editor requires a name";if(!f)throw"textAngular Error: An editor requires a scope";if(e[c])throw'textAngular Error: An Editor with name "'+c+'" already exists';var h=[];return angular.forEach(g,function(a){d[a]&&h.push(d[a])}),e[c]={scope:f,toolbars:g,_registerToolbar:function(a){this.toolbars.indexOf(a.name)>=0&&h.push(a)},editorFunctions:{disable:function(){angular.forEach(h,function(a){a.disabled=!0})},enable:function(){angular.forEach(h,function(a){a.disabled=!1})},focus:function(){angular.forEach(h,function(a){a._parent=f,a.disabled=!1,a.focussed=!0})},unfocus:function(){angular.forEach(h,function(a){a.disabled=!0,a.focussed=!1})},updateSelectedStyles:function(a){angular.forEach(h,function(b){angular.forEach(b.tools,function(c){c.activeState&&(b._parent=f,c.active=c.activeState(a))})})},sendKeyCommand:function(c){var d=!1;return(c.ctrlKey||c.metaKey)&&angular.forEach(b,function(b,e){if(b.commandKeyCode&&b.commandKeyCode===c.which)for(var g=0;g
0)for(var k=0;k"),d.addClass(b&&b["class"]?b["class"]:g.classes.toolbarButton),d.attr("name",c.name),d.attr("unselectable","on"),d.attr("ng-disabled","isDisabled()"),d.attr("tabindex","-1"),d.attr("ng-click","executeAction()"),d.attr("ng-class","displayActiveToolClass(active)"),b&&b.tooltiptext&&d.attr("title",b.tooltiptext),d.on("mousedown",function(a,b){return b&&angular.extend(a,b),a.preventDefault(),!1}),b&&!b.display&&!c._display&&(d[0].innerHTML="",b.buttontext&&(d[0].innerHTML=b.buttontext),b.iconclass)){var e=angular.element(""),f=d[0].innerHTML;e.addClass(b.iconclass),d[0].innerHTML="",d.append(e),f&&""!==f&&d.append(" "+f)}return c._lastToolDefinition=angular.copy(b),a(d)(c)};g.tools={},g._parent={disabled:!0,showHtml:!1,queryFormatBlockState:function(){return!1},queryCommandState:function(){return!1}};var k={$window:f,$editor:function(){return g._parent},isDisabled:function(){return"function"!=typeof this.$eval("disabled")&&this.$eval("disabled")||this.$eval("disabled()")||"html"!==this.name&&this.$editor().showHtml||this.$parent.disabled||this.$editor().disabled},displayActiveToolClass:function(a){return a?g.classes.toolbarButtonActive:""},executeAction:e};angular.forEach(g.toolbar,function(a){var b=angular.element("");b.addClass(g.classes.toolbarGroup),angular.forEach(a,function(a){g.tools[a]=angular.extend(g.$new(!0),d[a],k,{name:a}),g.tools[a].$element=j(d[a],g.tools[a]),b.append(g.tools[a].$element)}),h.append(b)}),g.updateToolDisplay=function(a,b,c){var d=g.tools[a];if(d){if(d._lastToolDefinition&&!c&&(b=angular.extend({},d._lastToolDefinition,b)),null===b.buttontext&&null===b.iconclass&&null===b.display)throw'textAngular Error: Tool Definition for updating "'+a+'" does not have a valid display/iconclass/buttontext value';null===b.buttontext&&delete b.buttontext,null===b.iconclass&&delete b.iconclass,null===b.display&&delete b.display;var e=j(b,d);d.$element.replaceWith(e),d.$element=e}},g.addTool=function(a,b,c,e){g.tools[a]=angular.extend(g.$new(!0),d[a],k,{name:a}),g.tools[a].$element=j(d[a],g.tools[a]);var f;void 0===c&&(c=g.toolbar.length-1),f=angular.element(h.children()[c]),void 0===e?(f.append(g.tools[a].$element),g.toolbar[c][g.toolbar[c].length-1]=a):(f.children().eq(e).after(g.tools[a].$element),g.toolbar[c][e]=a)},b.registerToolbar(g),g.$on("$destroy",function(){b.unregisterToolbar(g.name)})}}}])}()}({},function(){return this}());
\ No newline at end of file
diff --git a/lib/main.js b/lib/main.js
index 072818ba..370c4de0 100644
--- a/lib/main.js
+++ b/lib/main.js
@@ -529,6 +529,8 @@ textAngular.directive("textAngular", [
// the following is for applying the active states to the tools that support it
scope._bUpdateSelectedStyles = false;
+ /* istanbul ignore next: browser window/tab leave check */
+ angular.element(window).on('blur', function(){ scope._bUpdateSelectedStyles = false; });
// loop through all the tools polling their activeState function if it exists
scope.updateSelectedStyles = function(){
var _selection;
@@ -538,8 +540,7 @@ textAngular.directive("textAngular", [
}else _toolbars.updateSelectedStyles();
// used to update the active state when a key is held down, ie the left arrow
/* istanbul ignore else: browser only check */
- if(scope._bUpdateSelectedStyles && $document.hasFocus()) $timeout(scope.updateSelectedStyles, 200);
- else scope._bUpdateSelectedStyles = false;
+ if(scope._bUpdateSelectedStyles) $timeout(scope.updateSelectedStyles, 200);
};
// start updating on keydown
_keydown = function(){
diff --git a/src/textAngular.js b/src/textAngular.js
index 6fe2b3b3..fe7d6150 100644
--- a/src/textAngular.js
+++ b/src/textAngular.js
@@ -1977,6 +1977,8 @@ textAngular.directive("textAngular", [
// the following is for applying the active states to the tools that support it
scope._bUpdateSelectedStyles = false;
+ /* istanbul ignore next: browser window/tab leave check */
+ angular.element(window).on('blur', function(){ scope._bUpdateSelectedStyles = false; });
// loop through all the tools polling their activeState function if it exists
scope.updateSelectedStyles = function(){
var _selection;
@@ -1986,8 +1988,7 @@ textAngular.directive("textAngular", [
}else _toolbars.updateSelectedStyles();
// used to update the active state when a key is held down, ie the left arrow
/* istanbul ignore else: browser only check */
- if(scope._bUpdateSelectedStyles && $document.hasFocus()) $timeout(scope.updateSelectedStyles, 200);
- else scope._bUpdateSelectedStyles = false;
+ if(scope._bUpdateSelectedStyles) $timeout(scope.updateSelectedStyles, 200);
};
// start updating on keydown
_keydown = function(){