From 18bfebe25e62640324aa8acb4e79fd1dd634d0da Mon Sep 17 00:00:00 2001 From: jbehuet Date: Fri, 29 Jul 2016 17:07:24 +0200 Subject: [PATCH] Add boolean to set edit mode enable or not --- ite.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/ite.js b/ite.js index 09dd69f..6e172cb 100644 --- a/ite.js +++ b/ite.js @@ -5,9 +5,10 @@ angular.module( 'InlineTextEditor', ['ngSanitize']); function inlineTextEditor($sce, $compile, $timeout, $window, $sanitize){ return { restrict: 'A', - require: '?ngModel', - link: function($scope, element, attrs, ngModel) { - + require: ['?ngModel', '?editMode'], + link: function($scope, element, attrs, args) { + var ngModel = args[0]; + var editMode = args[1] || false; var html, savedSelection, clickPosition, overToolbar, originalToolbar, toolbar; if (!ngModel) { return; } @@ -16,6 +17,10 @@ function inlineTextEditor($sce, $compile, $timeout, $window, $sanitize){ element.html(ngModel.$viewValue || ''); }; + attrs.$observe('editMode', function(value) { + editMode = value; + }); + // Write data to the model function read() { var html = element.html(); @@ -116,7 +121,7 @@ function inlineTextEditor($sce, $compile, $timeout, $window, $sanitize){ var start = range.anchorOffset; var end = range.focusOffset; - if (!range.isCollapsed) { + if (!range.isCollapsed && eval(editMode)) { createToolbar(); } else { removeToolbar();