Files
cdnjs/ajax/libs/textAngular/1.0.2/text-angular.min.js
T
Austin 23ca971f11 added textAngular
added textAngular script files

Update package.json

fixed lack of quotes in name

Update package.json

fixed quote missing

Update package.json

fixed package

Update package.json

fixed again

updated minified scope issue with dependencies

updated minified scope issue with dependencies

Updated to 1.0.2

Rename textAngular.js to text-angular.js

Rename textAngular.min.js to text-angular.min.js

Update package.json

Rename textAngular.js to text-angular.js

Rename textAngular.min.js to text-angular.min.js
2013-10-14 20:09:55 -06:00

2 lines
7.3 KiB
JavaScript

var textAngular=angular.module("textAngular",[]);textAngular.directive("compile",function($compile){return function(scope,element,attrs){scope.$watch(function(scope){return scope.$eval(attrs.compile)},function(value){element.html(value);$compile(element.contents())(scope)})}});textAngular.directive("textAngular",function($compile,$sce,$window,$timeout){var methods={theme:function(scope,opts){if(opts.disableStyle){return false}scope.theme=!!!opts.theme?{}:opts.theme;var editorDefault={resize:"both","overflow-y":"auto","min-height":"300px","text-align":"left",padding:"4px"};var toolbarDefault={margin:"0.2em","text-align":"right",overflow:"hidden","border-radius":"3px",display:"inline-block"};scope.theme.editor=!!!scope.theme.editor?{background:"#FFFFFF",color:"#5E5E5E",border:"1px solid #C4C4C4",padding:"4px",resize:"both","overflow-y":"auto","min-height":"300px","text-align":"left","border-radius":"3px"}:angular.extend(scope.theme.editor,editorDefault);scope.theme.toolbar=!!!scope.theme.toolbar?{margin:"0.2em","text-align":"right",overflow:"hidden","border-radius":"3px",border:"1px #C4C4C4",display:"inline-block"}:angular.extend(scope.theme.toolbar,toolbarDefault);scope.theme.toolbarItems=!!!scope.theme.toolbarItems?{cursor:"pointer",display:"inline-block",padding:"0.2em 0.4em","margin-left":"0em",background:"gray",color:"white","font-size":"14px"}:scope.theme.toolbarItems;scope.theme.insertForm=!!!scope.theme.insertForm?{"text-align":"right",padding:"0.2em"}:scope.theme.insertForm;scope.theme.insertFormBtn=!!!scope.theme.insertFormBtn?{"margin-top":"0.2em"}:scope.theme.insertFormBtn},compileHtml:function(scope,html){var compHtml=$("<div>").append(html).html().replace(/(class="(.*?)")|(class='(.*?)')/g,"").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/style=("|')(.*?)("|')/g,"");if(scope.showHtml=="load"){scope.textAngularModel.text=$sce.trustAsHtml(compHtml);scope.textAngularModel.html=$sce.trustAsHtml(compHtml.replace(/</g,"&lt;"));scope.showHtml=(scope.showHtmlDefault||false)}else{if(scope.showHtml){scope.textAngularModel.text=$sce.trustAsHtml(compHtml)}else{scope.textAngularModel.html=$sce.trustAsHtml(compHtml.replace(/</g,"&lt;"))}}scope.$parent.textAngularOpts.textAngularEditors[scope.name]["html"]=compHtml},wrapSelection:function(command,opt){document.execCommand(command,false,opt)},preCompileHtml:function(scope,el){if(scope.showHtml){var ht=$(el).find(".textAngular-html").html()}else{var ht=$(el).find(".textAngular-text").html()}methods.compileHtml(scope,ht)},toolbarFn:{html:function(scope,el){scope.showHtml=!scope.showHtml;if(scope.showHtml){var ht=$(el).find(".textAngular-text").html();$timeout(function(){$(el).find(".textAngular-html").focus()},100)}else{var ht=$(el).find(".textAngular-html").html();$timeout(function(){$(el).find(".textAngular-text").focus()},100)}methods.compileHtml(scope,ht)},h1:function(scope){methods.wrapSelection("formatBlock","<H1>")},h2:function(scope){methods.wrapSelection("formatBlock","<H2>")},h3:function(scope){methods.wrapSelection("formatBlock","<H3>")},p:function(scope){methods.wrapSelection("formatBlock","<P>")},pre:function(scope){methods.wrapSelection("formatBlock","<PRE>")},ul:function(scope){methods.wrapSelection("insertUnorderedList",null)},ol:function(scope){methods.wrapSelection("insertOrderedList",null)},quote:function(scope){methods.wrapSelection("formatBlock","<BLOCKQUOTE>")},undo:function(scope){methods.wrapSelection("undo",null)},redo:function(scope){methods.wrapSelection("redo",null)},b:function(scope){methods.wrapSelection("bold",null)},justifyLeft:function(scope){methods.wrapSelection("justifyLeft",null)},justifyRight:function(scope){methods.wrapSelection("justifyRight",null)},justifyCenter:function(scope){methods.wrapSelection("justifyCenter",null)},i:function(scope){methods.wrapSelection("italic",null)},clear:function(scope){methods.wrapSelection("FormatBlock","<div>")},insertImage:function(scope){if(scope.inserting==true){scope.inserting=false;return false}scope.insert.model="";scope.inserting=true;scope.insert.text="Insert Image";scope.currentInsert="insertImage"},insertHtml:function(scope){if(scope.inserting==true){scope.inserting=false;return false}scope.insert.model="";scope.inserting=true;scope.insert.text="Insert HTML";scope.currentInsert="insertHtml"},createLink:function(scope){if(scope.inserting==true){scope.inserting=false;return false}scope.insert.model="";scope.inserting=true;scope.insert.text="Make a Link";scope.currentInsert="createLink"}}};return{template:"<div class='textAngular-root' style='text-align:right;'><div class='textAngular-toolbar' ng-style='theme.toolbar'><span ng-repeat='toolbarItem in toolbar' title='{{toolbarItem.title}}' class='textAngular-toolbar-item' ng-style='theme.toolbarItems' ng-mousedown='runToolbar(toolbarItem.name,$event)' unselectable='on' compile='toolbarItem.icon' name='toolbarItem.name'></span></div><form class='textAngular-insert' ng-show='inserting' ng-style='theme.insertForm'><input type='text' ng-model='insert.model' required><div class='textAngular-insert-submit'><button ng-style='theme.insertFormBtn' ng-mousedown='finishInsert();'>{{insert.text}}</button></div></form><pre contentEditable='true' ng-show='showHtml' class='textAngular-html' ng-style='theme.editor' ng-bind-html='textAngularModel.html' ></pre><div contentEditable='true' ng-hide='showHtml' class='textAngular-text' ng-style='theme.editor' ng-bind-html='textAngularModel.text' ></div></div>",replace:true,scope:{},restrict:"A",controller:function($scope,$element,$attrs){console.log("Thank you for using textAngular! http://www.textangular.com");$scope.insert={};$scope.finishInsert=function(){methods.wrapSelection($scope.currentInsert,$scope.insert.model);methods.preCompileHtml($scope,$element);$scope.inserting=false};$scope.runToolbar=function(name,$event){$event.preventDefault();var wd=methods.toolbarFn[name]($scope,$element);if(name=="html"){return}methods.preCompileHtml($scope,$element)}},link:function(scope,el,attr){scope.$parent.$watch("textAngularOpts",function(){if(!!!scope.$parent.textAngularOpts){console.log("No textAngularOpts config object found in scope! Please create one!")}scope.showHtml="load";if(!!!attr.textAngularName){console.log("No 'text-angular-name' directive found on directve root element. Please add one! ");return false}var name=attr.textAngularName;scope.name=name;if(!!!scope.$parent.textAngularOpts.textAngularEditors){scope.$parent.textAngularOpts.textAngularEditors={}}if(!!!scope.$parent.textAngularOpts.textAngularEditors[name]){scope.$parent.textAngularOpts.textAngularEditors[name]={};var opts=scope.$parent.textAngularOpts;scope.toolbar=scope.$parent.textAngularOpts.toolbar}else{var opts=scope.$parent.textAngularOpts.textAngularEditors[name];scope.toolbar=scope.$parent.textAngularOpts.textAngularEditors[name].toolbar}scope.$parent.$watch('textAngularOpts.textAngularEditors["'+name+'"].html',function(oldVal,newVal){if(!!!$(":focus").parents(".textAngular-root")[0]){scope.textAngularModel.text=$sce.trustAsHtml(newVal);scope.textAngularModel.html=$sce.trustAsHtml(newVal.replace(/</g,"&lt;"))}},true);methods.theme(scope,opts);scope.textAngularModel={};methods.compileHtml(scope,opts.html);$(el).find(".textAngular-text,.textAngular-html").on("keyup",function(e){if(scope.showHtml){var ht=$(this.parentNode).find(".textAngular-html").html()}else{var ht=$(this.parentNode).find(".textAngular-text").html()}scope.$apply(methods.preCompileHtml(scope,this.parentNode))})})}}});