Skip to content

Commit

Permalink
feat(textAngularSetup): fixed test coverage when commonElement is doc…
Browse files Browse the repository at this point in the history
…ument
  • Loading branch information
JoelParke committed Jul 8, 2015
1 parent dbea624 commit b807423
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 32 deletions.
13 changes: 7 additions & 6 deletions dist/textAngular.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ See README.md or https://github.com/fraywing/textAngular/wiki for requirements a
*/

(function(){ // encapsulate all variables so they don't become global vars
"use strict";
"use strict";
// IE version detection - http://stackoverflow.com/questions/4169160/javascript-ie-detection-why-not-use-simple-conditional-comments
// We need this as IE sometimes plays funny tricks with the contenteditable.
// ----------------------------------------------------------
Expand All @@ -30,12 +30,12 @@ var _browserDetect = {
v = 3,
div = document.createElement('div'),
all = div.getElementsByTagName('i');

while (
div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->',
all[0]
);

return v > 4 ? v : undef;
}()),
webkit: /AppleWebKit\/([\d.]+)/i.test(navigator.userAgent)
Expand Down Expand Up @@ -63,11 +63,11 @@ if(_browserDetect.webkit) {
curelement.select(); // use select to place cursor for input elements.
}
}
}
}
globalContentEditableBlur = false;
}, false); // add global click handler
angular.element(document).ready(function () {
angular.element(document.body).append(angular.element('<input id="textAngular-editableFix-010203040506070809" class="ta-hidden-input" unselectable="on" tabIndex="-1">'));
angular.element(document.body).append(angular.element('<input id="textAngular-editableFix-010203040506070809" class="ta-hidden-input" aria-hidden="true" unselectable="on" tabIndex="-1">'));
});
}

Expand Down Expand Up @@ -140,7 +140,7 @@ if(_browserDetect.ie > 8 || _browserDetect.ie === undefined){
/* istanbul ignore next: browser catches */
if(_sheet.cssRules) insertIndex = Math.max(_sheet.cssRules.length - 1, 0);
else if(_sheet.rules) insertIndex = Math.max(_sheet.rules.length - 1, 0);

/* istanbul ignore else: untestable IE option */
if(_sheet.insertRule) {
_sheet.insertRule(selector + "{" + rules + "}", insertIndex);
Expand Down Expand Up @@ -182,6 +182,7 @@ if(_browserDetect.ie > 8 || _browserDetect.ie === undefined){
}
};
}

angular.module('textAngular.factories', [])
.factory('taBrowserTag', [function(){
return function(tag){
Expand Down
6 changes: 3 additions & 3 deletions dist/textAngular.min.js

Large diffs are not rendered by default.

25 changes: 15 additions & 10 deletions dist/textAngularSetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,17 +439,18 @@ angular.module('textAngularSetup', [])
return this.$editor().wrapSelection("justifyLeft", null);
},
activeState: function(commonElement){
/* istanbul ignore next: */
if (commonElement && commonElement.nodeName === '#document') return false;
var result = false;
if(commonElement) result =
commonElement.css('text-align') === 'left' ||
commonElement.attr('align') === 'left' ||
(
commonElement.css('text-align') !== 'right' &&
commonElement.css('text-align') !== 'center' &&
commonElement.css('text-align') !== 'justify' &&
!this.$editor().queryCommandState('justifyRight') &&
!this.$editor().queryCommandState('justifyCenter')
) && !this.$editor().queryCommandState('justifyFull');
if (commonElement)
result =
commonElement.css('text-align') === 'left' ||
commonElement.attr('align') === 'left' ||
(
commonElement.css('text-align') !== 'right' &&
commonElement.css('text-align') !== 'center' &&
commonElement.css('text-align') !== 'justify' && !this.$editor().queryCommandState('justifyRight') && !this.$editor().queryCommandState('justifyCenter')
) && !this.$editor().queryCommandState('justifyFull');
result = result || this.$editor().queryCommandState('justifyLeft');
return result;
}
Expand All @@ -461,6 +462,8 @@ angular.module('textAngularSetup', [])
return this.$editor().wrapSelection("justifyRight", null);
},
activeState: function(commonElement){
/* istanbul ignore next: */
if (commonElement && commonElement.nodeName === '#document') return false;
var result = false;
if(commonElement) result = commonElement.css('text-align') === 'right';
result = result || this.$editor().queryCommandState('justifyRight');
Expand All @@ -474,6 +477,8 @@ angular.module('textAngularSetup', [])
return this.$editor().wrapSelection("justifyCenter", null);
},
activeState: function(commonElement){
/* istanbul ignore next: */
if (commonElement && commonElement.nodeName === '#document') return false;
var result = false;
if(commonElement) result = commonElement.css('text-align') === 'center';
result = result || this.$editor().queryCommandState('justifyCenter');
Expand Down
28 changes: 15 additions & 13 deletions src/textAngularSetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,18 +439,18 @@ angular.module('textAngularSetup', [])
return this.$editor().wrapSelection("justifyLeft", null);
},
activeState: function(commonElement){
/* istanbul ignore next: */
if (commonElement && commonElement.nodeName === '#document') return false;
var result = false;
if (!commonElement || commonElement.nodeName === '#document') return false;
if(commonElement) result =
commonElement.css('text-align') === 'left' ||
commonElement.attr('align') === 'left' ||
(
commonElement.css('text-align') !== 'right' &&
commonElement.css('text-align') !== 'center' &&
commonElement.css('text-align') !== 'justify' &&
!this.$editor().queryCommandState('justifyRight') &&
!this.$editor().queryCommandState('justifyCenter')
) && !this.$editor().queryCommandState('justifyFull');
if (commonElement)
result =
commonElement.css('text-align') === 'left' ||
commonElement.attr('align') === 'left' ||
(
commonElement.css('text-align') !== 'right' &&
commonElement.css('text-align') !== 'center' &&
commonElement.css('text-align') !== 'justify' && !this.$editor().queryCommandState('justifyRight') && !this.$editor().queryCommandState('justifyCenter')
) && !this.$editor().queryCommandState('justifyFull');
result = result || this.$editor().queryCommandState('justifyLeft');
return result;
}
Expand All @@ -462,8 +462,9 @@ angular.module('textAngularSetup', [])
return this.$editor().wrapSelection("justifyRight", null);
},
activeState: function(commonElement){
/* istanbul ignore next: */
if (commonElement && commonElement.nodeName === '#document') return false;
var result = false;
if (!commonElement || commonElement.nodeName === '#document') return false;
if(commonElement) result = commonElement.css('text-align') === 'right';
result = result || this.$editor().queryCommandState('justifyRight');
return result;
Expand All @@ -476,8 +477,9 @@ angular.module('textAngularSetup', [])
return this.$editor().wrapSelection("justifyCenter", null);
},
activeState: function(commonElement){
/* istanbul ignore next: */
if (commonElement && commonElement.nodeName === '#document') return false;
var result = false;
if (!commonElement || commonElement.nodeName === '#document') return false;
if(commonElement) result = commonElement.css('text-align') === 'center';
result = result || this.$editor().queryCommandState('justifyCenter');
return result;
Expand Down

0 comments on commit b807423

Please sign in to comment.