angular-content-editable
Advanced tools
Comparing version 1.1.2 to 1.1.3
@@ -9,3 +9,3 @@ angular.module('angular-content-editable', []); | ||
restrict: 'A', | ||
require: '?ngModel', | ||
require: 'ngModel', | ||
scope: { editCallback: '=' }, | ||
@@ -37,9 +37,3 @@ link: _link | ||
}); | ||
// if model is invalid or null | ||
// fill his value with elem html content | ||
if( !scope.ngModel ) { | ||
ngModel.$setViewValue( elem.html() ); | ||
} | ||
// add editable class | ||
@@ -50,3 +44,3 @@ attrs.$addClass(options.editableClass); | ||
ngModel.$render = function() { | ||
elem.html( ngModel.$modelValue || '' ); | ||
elem.html( ngModel.$modelValue || elem.html() ); | ||
} | ||
@@ -64,4 +58,6 @@ | ||
function onFocus(e) { | ||
// turn on the flag | ||
noEscape = true; | ||
// select all on focus | ||
@@ -75,2 +71,3 @@ if( options.focusSelect ) { | ||
} | ||
// if render-html is enabled convert | ||
@@ -82,2 +79,3 @@ // all text content to plaintext | ||
} | ||
} | ||
@@ -84,0 +82,0 @@ |
@@ -1,1 +0,1 @@ | ||
angular.module("angular-content-editable",[]),angular.module("angular-content-editable").directive("contentEditable",["$log","$sce","$parse","$window","contentEditable",function($log,$sce,$parse,$window,contentEditable){function _link(scope,elem,attrs,ngModel){function onClick(e){return e.preventDefault(),attrs.$set("contenteditable","true"),originalElement.focus()}function onFocus(e){if(noEscape=!0,options.focusSelect){var range=$window.document.createRange(),selection=$window.getSelection();range.selectNodeContents(originalElement),selection.removeAllRanges(),selection.addRange(range)}options.renderHtml&&(originalElement.textContent=elem.html())}function onBlur(e){var html;if(attrs.$set("contenteditable","false"),options.renderHtml&&noEscape?(html=originalElement.textContent.replace(/\u00a0/g," "),elem.html(html)):html=elem.html().replace(/ /g," "),html!=ngModel.$modelValue&&(ngModel.$setViewValue(html),scope.editCallback&&angular.isFunction(scope.editCallback)))return scope.$apply(scope.editCallback(html,elem))}function onKeyDown(e){return 9==e.which?void originalElement.blur():27==e.which?(ngModel.$rollbackViewValue(),noEscape=!1,originalElement.blur()):13==e.which&&(options.singleLine||e.ctrlKey)?originalElement.blur():void 0}if(!ngModel)return void $log.warn("Error: ngModel is required in elem: ",elem);var noEscape=!0,originalElement=elem[0],options=angular.copy(contentEditable);angular.forEach(options,function(val,key){key in attrs&&(options[key]=$parse(attrs[key])(scope))}),scope.ngModel||ngModel.$setViewValue(elem.html()),attrs.$addClass(options.editableClass),ngModel.$render=function(){elem.html(ngModel.$modelValue||"")},elem.on("click",onClick),elem.on("focus",onFocus),elem.on("blur",onBlur),elem.on("keydown",onKeyDown),scope.$on("$destroy",function(){elem.off("click",onClick),elem.off("focus",onFocus),elem.off("blur",onBlur),elem.off("keydown",onKeyDown)})}return{restrict:"A",require:"?ngModel",scope:{editCallback:"="},link:_link}}]),angular.module("angular-content-editable").provider("contentEditable",function(){var defaults={editableClass:"editable",keyBindings:!0,singleLine:!1,focusSelect:!0,renderHtml:!1,editCallback:!1};this.configure=function(options){return angular.extend(defaults,options)},this.$get=function(){return defaults}}); | ||
angular.module("angular-content-editable",[]),angular.module("angular-content-editable").directive("contentEditable",["$log","$sce","$parse","$window","contentEditable",function($log,$sce,$parse,$window,contentEditable){function _link(scope,elem,attrs,ngModel){function onClick(e){return e.preventDefault(),attrs.$set("contenteditable","true"),originalElement.focus()}function onFocus(e){if(noEscape=!0,options.focusSelect){var range=$window.document.createRange(),selection=$window.getSelection();range.selectNodeContents(originalElement),selection.removeAllRanges(),selection.addRange(range)}options.renderHtml&&(originalElement.textContent=elem.html())}function onBlur(e){var html;if(attrs.$set("contenteditable","false"),options.renderHtml&&noEscape?(html=originalElement.textContent.replace(/\u00a0/g," "),elem.html(html)):html=elem.html().replace(/ /g," "),html!=ngModel.$modelValue&&(ngModel.$setViewValue(html),scope.editCallback&&angular.isFunction(scope.editCallback)))return scope.$apply(scope.editCallback(html,elem))}function onKeyDown(e){return 9==e.which?void originalElement.blur():27==e.which?(ngModel.$rollbackViewValue(),noEscape=!1,originalElement.blur()):13==e.which&&(options.singleLine||e.ctrlKey)?originalElement.blur():void 0}if(!ngModel)return void $log.warn("Error: ngModel is required in elem: ",elem);var noEscape=!0,originalElement=elem[0],options=angular.copy(contentEditable);angular.forEach(options,function(val,key){key in attrs&&(options[key]=$parse(attrs[key])(scope))}),attrs.$addClass(options.editableClass),ngModel.$render=function(){elem.html(ngModel.$modelValue||elem.html())},elem.on("click",onClick),elem.on("focus",onFocus),elem.on("blur",onBlur),elem.on("keydown",onKeyDown),scope.$on("$destroy",function(){elem.off("click",onClick),elem.off("focus",onFocus),elem.off("blur",onBlur),elem.off("keydown",onKeyDown)})}return{restrict:"A",require:"ngModel",scope:{editCallback:"="},link:_link}}]),angular.module("angular-content-editable").provider("contentEditable",function(){var defaults={editableClass:"editable",keyBindings:!0,singleLine:!1,focusSelect:!0,renderHtml:!1,editCallback:!1};this.configure=function(options){return angular.extend(defaults,options)},this.$get=function(){return defaults}}); |
@@ -27,3 +27,4 @@ module.exports = function(grunt) { | ||
options: { | ||
spawn: false | ||
spawn: false, | ||
livereload: true | ||
}, | ||
@@ -45,2 +46,19 @@ files: ['src/**/*.js'], | ||
connect: { | ||
server: { | ||
options: { | ||
port: 8080, | ||
hostname: 'localhost', | ||
livereload: true, | ||
base: { | ||
path: '.', | ||
options: { | ||
index: 'example/index.html' | ||
} | ||
}, | ||
open: true | ||
} | ||
} | ||
} | ||
}) | ||
@@ -51,7 +69,8 @@ | ||
grunt.loadNpmTasks('grunt-contrib-watch'); | ||
grunt.loadNpmTasks('grunt-contrib-connect'); | ||
grunt.loadNpmTasks('grunt-ng-annotate'); | ||
grunt.registerTask('default', ['watch']); | ||
grunt.registerTask('default', ['connect', 'watch']); | ||
grunt.registerTask('build', ['concat', 'ngAnnotate', 'uglify']); | ||
} |
{ | ||
"name": "angular-content-editable", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"description": "modify in real time any html tag you want", | ||
@@ -10,3 +10,3 @@ "main": "dist/angular-content-editable.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "node node_modules/karma/bin/karma start" | ||
}, | ||
@@ -30,6 +30,11 @@ "repository": { | ||
"grunt-contrib-concat": "^1.0.1", | ||
"grunt-contrib-connect": "^1.0.2", | ||
"grunt-contrib-uglify": "^0.9.2", | ||
"grunt-contrib-watch": "^1.0.0", | ||
"grunt-ng-annotate": "^3.0.0" | ||
"grunt-ng-annotate": "^3.0.0", | ||
"jasmine-core": "^2.6.1", | ||
"karma": "^1.6.0", | ||
"karma-jasmine": "^1.1.0", | ||
"karma-phantomjs-launcher": "^1.0.4" | ||
} | ||
} |
@@ -7,3 +7,3 @@ angular.module('angular-content-editable') | ||
restrict: 'A', | ||
require: '?ngModel', | ||
require: 'ngModel', | ||
scope: { editCallback: '=' }, | ||
@@ -35,9 +35,3 @@ link: _link | ||
}); | ||
// if model is invalid or null | ||
// fill his value with elem html content | ||
if( !scope.ngModel ) { | ||
ngModel.$setViewValue( elem.html() ); | ||
} | ||
// add editable class | ||
@@ -48,3 +42,3 @@ attrs.$addClass(options.editableClass); | ||
ngModel.$render = function() { | ||
elem.html( ngModel.$modelValue || '' ); | ||
elem.html( ngModel.$modelValue || elem.html() ); | ||
} | ||
@@ -62,4 +56,6 @@ | ||
function onFocus(e) { | ||
// turn on the flag | ||
noEscape = true; | ||
// select all on focus | ||
@@ -73,2 +69,3 @@ if( options.focusSelect ) { | ||
} | ||
// if render-html is enabled convert | ||
@@ -80,2 +77,3 @@ // all text content to plaintext | ||
} | ||
} | ||
@@ -82,0 +80,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
28799
14
522
0
10