"use strict";function string2array(a){return a.split(",").map(Function.prototype.call,String.prototype.trim)}function pasteHtmlAtCaret(a){var b,c;if(window.getSelection){if(b=window.getSelection(),b.getRangeAt&&b.rangeCount){c=b.getRangeAt(0),c.deleteContents();var d=document.createElement("div");d.innerHTML=a;for(var e,f,g=document.createDocumentFragment();e=d.firstChild;)f=g.appendChild(e);c.insertNode(g),f&&(c=c.cloneRange(),c.setStartAfter(f),c.collapse(!0),b.removeAllRanges(),b.addRange(c))}}else document.selection&&"Control"!=document.selection.type&&document.selection.createRange().pasteHTML(a)}var VERSION="3.0.6";angular.module("ngWig",["ngwig-app-templates"]),angular.ngWig={version:VERSION},angular.module("ngWig").component("ngWig",{bindings:{content:"=ngModel",options:"",onPaste:"&",buttons:"@",beforeExecCommand:"&",afterExecCommand:"&",placeholder:"@?"},require:{ngModelController:"ngModel"},templateUrl:"ng-wig/views/ng-wig.html",controller:["$scope","$element","$q","$attrs","$window","$document","ngWigToolbar",function(a,b,c,d,e,f,g){var h=this,i=angular.element(b[0].querySelector("#ng-wig-editable"));this.required="required"in d,this.isSourceModeAllowed="sourceModeAllowed"in d,this.editMode=!1,this.toolbarButtons=g.getToolbarButtons(this.buttons&&string2array(this.buttons)),this.placeholder=d.placeholder,d.$observe("disabled",function(a){h.disabled=a,i.attr("contenteditable",!a)}),this.isEditorActive=function(){return i[0]===f[0].activeElement},this.toggleEditMode=function(){h.editMode=!h.editMode,e.getSelection().removeAllRanges&&e.getSelection().removeAllRanges()},this.execCommand=function(b,c){return h.editMode?!1:void(("createlink"!==b&&"insertImage"!==b||(c=e.prompt("Please enter the URL","http://")))&&(h.beforeExecCommand({command:b,options:c}),a.$broadcast("execCommand",{command:b,options:c}),h.afterExecCommand({command:b,options:c})))},this.$onInit=function(){var b=Boolean(h.placeholder);h.ngModelController.$render=function(){return b?i.empty():i.html(h.ngModelController.$viewValue||"
")},i.bind("blur keyup change focus click",function(){(b&&!i.html().length||b&&"
"===i.html())&&i.empty(),h.ngModelController.$setViewValue(i.html()),a.$applyAsync()})},i.on("paste",function(a){if(d.onPaste){var b=void 0;b=window.clipboardData&&window.clipboardData.getData?window.clipboardData.getData("Text"):(a.originalEvent||a).clipboardData.getData("text/plain"),a.preventDefault(),c.when(h.onPaste({$event:a,pasteContent:b})).then(function(a){pasteHtmlAtCaret(a)})}}),a.$on("execCommand",function(a,b){var c=f[0].getSelection().toString(),d=b.command,e=b.options;if(a.stopPropagation&&a.stopPropagation(),i[0].focus(),f[0].queryCommandSupported&&!f[0].queryCommandSupported(d))throw'The command "'+d+'" is not supported';"createlink"===d&&""===c?f[0].execCommand("insertHtml",!1,''+e+""):f[0].execCommand(d,!1,e)})}]}),angular.module("ngWig").provider("ngWigToolbar",function(){var a={list1:{title:"Unordered List",command:"insertunorderedlist",styleClass:"list-ul"},list2:{title:"Ordered List",command:"insertorderedlist",styleClass:"list-ol"},bold:{title:"Bold",command:"bold",styleClass:"bold"},italic:{title:"Italic",command:"italic",styleClass:"italic"},link:{title:"Link",command:"createlink",styleClass:"link"}},b=["list1","list2","bold","italic","link"],c=function(){return!!this.command&&document.queryCommandState(this.command)};this.setButtons=function(a){if(!angular.isArray(a))throw'Argument "buttons" should be an array';b=a},this.addStandardButton=function(c,d,e,f){if(!c||!d||!e)throw'Arguments "name", "title" and "command" are required';f=f||"",a[c]={title:d,command:e,styleClass:f},b.push(c)},this.addCustomButton=function(c,d){if(!c||!d)throw'Arguments "name" and "pluginName" are required';a[c]={pluginName:d,isComplex:!0},b.push(c)},this.$get=function(){return{getToolbarButtons:function(d){var e=[];return(d||b).forEach(function(b){if(!a[b])throw'There is no "'+b+'" in your library. Possible variants: '+Object.keys(a);var d=angular.copy(a[b]);d.isActive=c,e.push(d)}),e}}}}),angular.module("ngWig").component("ngWigPlugin",{bindings:{plugin:"<",execCommand:"=",editMode:"=",disabled:"=",options:"<",content:"="},controller:["$scope","$element","$compile",function(a,b,c){b.replaceWith(c("<"+this.plugin.pluginName+' plugin="$ctrl.plugin"exec-command="$ctrl.execCommand"edit-mode="$ctrl.editMode"disabled="$ctrl.disabled"options="$ctrl.options"content="$ctrl.content"/>')(a))}]}),angular.module("ngwig-app-templates",["ng-wig/views/ng-wig.html"]),angular.module("ng-wig/views/ng-wig.html",[]).run(["$templateCache",function(a){a.put("ng-wig/views/ng-wig.html",'\n')}]);