text: "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.16";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,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(a,b){if(h.editMode)return!1;if(f[0].queryCommandSupported&&!f[0].queryCommandSupported(a))throw'The command "'+a+'" is not supported';if("createlink"!==a&&"insertImage"!==a||(b=e.prompt("Please enter the URL","http://"))){h.beforeExecCommand({command:a,options:b});var c=f[0].getSelection().toString();"createlink"===a&&""===c?f[0].execCommand("insertHtml",!1,'<a href="'+b+'" target="_blank" >'+b+"</a>"):f[0].execCommand(a,!1,b),h.afterExecCommand({command:a,options:b}),i.length&&i[0].focus()}},this.$onInit=function(){h.toolbarButtons=g.getToolbarButtons(h.buttons&&string2array(h.buttons));var b=Boolean(h.placeholder);h.ngModelController.$render=function(){return h.ngModelController.$viewValue?i.html(h.ngModelController.$viewValue):b?i.empty():i.html("<p></p>")},i.bind("blur keyup change focus click",function(){!b||i.html().length&&"<br>"!==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)})}})}]}),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){var d=this;this.$onInit=function(){b.replaceWith(c("<"+d.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",'<div class="ng-wig">\n  <ul class="nw-toolbar">\n    <li class="nw-toolbar__item" ng-repeat="button in $ctrl.toolbarButtons">\n        <div ng-if="!button.isComplex">\n          <button type="button"\n                  class="nw-button {{button.styleClass}}"\n                  title="{{button.title}}"\n                  ng-click="$ctrl.execCommand(button.command)"\n                  ng-class="{ \'nw-button--active\': !$ctrl.disabled && $ctrl.isEditorActive() && button.isActive() }"\n                  ng-disabled="$ctrl.editMode || $ctrl.disabled">\n            {{ button.title }}\n          </button>\n        </div>\n        <div ng-if="button.isComplex">\n          <ng-wig-plugin\n              exec-command="$ctrl.execCommand"\n              plugin="button"\n              edit-mode="$ctrl.editMode"\n              disabled="$ctrl.disabled"\n              options="$ctrl.options"\n              content="$ctrl.content"></ng-wig-plugin>\n        </div>\n    </li><!--\n    --><li class="nw-toolbar__item">\n      <button type="button"\n              class="nw-button nw-button--source"\n              title="Edit HTML"\n              ng-class="{ \'nw-button--active\': $ctrl.editMode }"\n              ng-if="$ctrl.isSourceModeAllowed"\n              ng-click="$ctrl.toggleEditMode()"\n              ng-disabled="$ctrl.disabled">\n        Edit HTML\n      </button>\n    </li>\n  </ul>\n\n  <div class="nw-editor-container">\n    <div class="nw-editor__src-container" ng-show="$ctrl.editMode">\n      <textarea ng-model="$ctrl.content"\n                ng-disabled="$ctrl.disabled"\n                class="nw-editor__src"></textarea>\n    </div>\n    <div class="nw-editor" ng-class="{ \'nw-disabled\': $ctrl.disabled }">\n      <div id="ng-wig-editable"\n           class="nw-editor__res"\n           ng-class="{\'nw-invisible\': $ctrl.editMode}"\n           ng-disabled="$ctrl.disabled"\n           contenteditable\n           placeholder="{{$ctrl.placeholder}}">\n      </div>\n    </div>\n  </div>\n</div>\n')}]);