Skip to content

Commit

Permalink
Merge 77b771b into ab1c344
Browse files Browse the repository at this point in the history
  • Loading branch information
a8m committed Aug 19, 2014
2 parents ab1c344 + 77b771b commit 0188167
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 67 deletions.
37 changes: 19 additions & 18 deletions src/textAngular.js
Expand Up @@ -471,12 +471,12 @@ See README.md or https://github.com/fraywing/textAngular/wiki for requirements a
});
scope.displayElements.scrollWindow.attr({'ng-hide': 'showHtml'});
if(attrs.taDefaultWrap) scope.displayElements.text.attr('ta-default-wrap', attrs.taDefaultWrap);

if(attrs.taUnsafeSanitizer){
scope.displayElements.text.attr('ta-unsafe-sanitizer', attrs.taUnsafeSanitizer);
scope.displayElements.html.attr('ta-unsafe-sanitizer', attrs.taUnsafeSanitizer);
}

// add the main elements to the origional element
scope.displayElements.scrollWindow.append(scope.displayElements.text);
element.append(scope.displayElements.scrollWindow);
Expand Down Expand Up @@ -958,7 +958,8 @@ See README.md or https://github.com/fraywing/textAngular/wiki for requirements a
var _isReadonly = false;
var _focussed = false;
var _disableSanitizer = attrs.taUnsafeSanitizer || taOptions.disableSanitizer;

var BLOCKED_KEYS = /^(9|19|20|27|33|34|35|36|37|38|39|40|45|46|112|113|114|115|116|117|118|119|120|121|122|123|144|145)$/;

// defaults to the paragraph element, but we need the line-break or it doesn't allow you to type into the empty element
// non IE is '<p><br/></p>', ie is '<p></p>' as for once IE gets it correct...
var _defaultVal, _defaultTest, _trimTest;
Expand All @@ -982,7 +983,7 @@ See README.md or https://github.com/fraywing/textAngular/wiki for requirements a
'<' + attrs.taDefaultWrap + '>&nbsp;</' + attrs.taDefaultWrap + '>';
_trimTest = new RegExp('^<' + attrs.taDefaultWrap + '>(\\s|&nbsp;)*<\\/' + attrs.taDefaultWrap + '>$', 'ig');
}

element.addClass('ta-bind');

// in here we are undoing the converts used elsewhere to prevent the < > and & being displayed when they shouldn't in the code.
Expand All @@ -991,7 +992,7 @@ See README.md or https://github.com/fraywing/textAngular/wiki for requirements a
if(_isInputFriendly) return element.val();
throw ('textAngular Error: attempting to update non-editable taBind');
};

var _setViewValue = function(val){
if(!val) val = _compileHtml();
if(val === _defaultTest || val.match(_trimTest)){
Expand All @@ -1001,12 +1002,12 @@ See README.md or https://github.com/fraywing/textAngular/wiki for requirements a
if(ngModel.$viewValue !== val) ngModel.$setViewValue(val);
}
};

//used for updating when inserting wrapped elements
scope.$parent['updateTaBind' + (attrs.id || '')] = function(){
if(!_isReadonly) _setViewValue();
};

//this code is used to update the models when data is entered/deleted
if(_isInputFriendly){
if(!_isContentEditable){
Expand Down Expand Up @@ -1063,7 +1064,7 @@ See README.md or https://github.com/fraywing/textAngular/wiki for requirements a
element.on('keyup', function(event, eventData){
/* istanbul ignore else: this is for catching the jqLite testing*/
if(eventData) angular.extend(event, eventData);
if(!_isReadonly){
if(!_isReadonly && !BLOCKED_KEYS.test(event.keyCode)){
// if enter - insert new taDefaultWrap, if shift+enter insert <br/>
if(_defaultVal !== '' && event.keyCode === 13){
if(!event.shiftKey){
Expand Down Expand Up @@ -1109,22 +1110,22 @@ See README.md or https://github.com/fraywing/textAngular/wiki for requirements a
_focussed = true;
ngModel.$render();
});

// prevent propagation on mousedown in editor, see #206
element.on('mousedown', function(event, eventData){
/* istanbul ignore else: this is for catching the jqLite testing*/
if(eventData) angular.extend(event, eventData);
event.stopPropagation();
event.stopPropagation();
});
}
}

// catch DOM XSS via taSanitize
// Sanitizing both ways is identical
var _sanitize = function(unsafe){
return (ngModel.$oldViewValue = taSanitize(taFixChrome(unsafe), ngModel.$oldViewValue, _disableSanitizer));
};

// trigger the validation calls
var _validity = function(value){
if(attrs.required) ngModel.$setValidity('required', !(!value || value.trim() === _defaultTest || value.trim().match(_trimTest) || value.trim() === ''));
Expand Down Expand Up @@ -1167,11 +1168,11 @@ See README.md or https://github.com/fraywing/textAngular/wiki for requirements a
.on('click', selectorClickHandler);
});
};

var _setInnerHTML = function(newval){
element[0].innerHTML = newval;
};

// changes to the model variable from outside the html/text inputs
ngModel.$render = function(){
// catch model being null or undefined
Expand Down Expand Up @@ -1219,7 +1220,7 @@ See README.md or https://github.com/fraywing/textAngular/wiki for requirements a
}
}
};

if(attrs.taReadonly){
//set initial value
_isReadonly = scope.$parent.$eval(attrs.taReadonly);
Expand Down Expand Up @@ -1769,7 +1770,7 @@ See README.md or https://github.com/fraywing/textAngular/wiki for requirements a
break;
}
}
if(result) break;
if(result) break;
}
}
return result;
Expand Down Expand Up @@ -1955,7 +1956,7 @@ See README.md or https://github.com/fraywing/textAngular/wiki for requirements a
range = _document.createRange();
range.setStart(sel.anchorNode, sel.anchorOffset);
range.setEnd(sel.focusNode, sel.focusOffset);

// Handle the case when the selection was selected backwards (from the end to the start in the document)
if (range.collapsed !== sel.isCollapsed) {
range.setStart(sel.focusNode, sel.focusOffset);
Expand All @@ -1981,7 +1982,7 @@ See README.md or https://github.com/fraywing/textAngular/wiki for requirements a
},
container: container,
collapsed: sel.isCollapsed

};
else return {
start: {
Expand Down

0 comments on commit 0188167

Please sign in to comment.