diff options
author | brantje <brantje@gmail.com> | 2016-10-07 20:56:29 +0300 |
---|---|---|
committer | brantje <brantje@gmail.com> | 2016-10-07 20:56:29 +0300 |
commit | 15b32b7e5e11255ea13a80dc48257e5eea772b60 (patch) | |
tree | 6d12ac3f0cf7f56271c707cfe2fcf648f6774dbc /js/app/directives | |
parent | e818e40f2f740f0c4d74a331ad8d14245d97643e (diff) |
Add JSHint, solve all problems
Diffstat (limited to 'js/app/directives')
-rw-r--r-- | js/app/directives/autoscroll.js | 44 | ||||
-rw-r--r-- | js/app/directives/clickselect.js | 45 | ||||
-rw-r--r-- | js/app/directives/colorfromstring.js | 9 | ||||
-rw-r--r-- | js/app/directives/credentialfield.js | 119 | ||||
-rw-r--r-- | js/app/directives/fileselect.js | 116 | ||||
-rw-r--r-- | js/app/directives/ngenter.js | 42 | ||||
-rw-r--r-- | js/app/directives/otp.js | 176 | ||||
-rw-r--r-- | js/app/directives/passwordgen.js | 419 | ||||
-rw-r--r-- | js/app/directives/progressbar.js | 55 | ||||
-rw-r--r-- | js/app/directives/qrreader.js | 73 | ||||
-rw-r--r-- | js/app/directives/tooltip.js | 59 | ||||
-rw-r--r-- | js/app/directives/use-theme.js | 86 |
12 files changed, 644 insertions, 599 deletions
diff --git a/js/app/directives/autoscroll.js b/js/app/directives/autoscroll.js index a86a9d09..b30fd2ef 100644 --- a/js/app/directives/autoscroll.js +++ b/js/app/directives/autoscroll.js @@ -1,22 +1,24 @@ -'use strict'; +(function () { + 'use strict'; + /** + * @ngdoc directive + * @name passmanApp.directive:autoScroll + * @description + * # autoScroll + */ + angular.module('passmanApp') + .directive('autoScroll', function () { + return { + restrict: 'A', + scope: { + autoScroll: '=' + }, + link: function postLink (scope, element, attrs) { + scope.$watch('autoScroll', function () { + $('#import_log').scrollTop($('#import_log')[0].scrollHeight); + }, true); + } + }; + }); -/** - * @ngdoc directive - * @name passmanApp.directive:autoScroll - * @description - * # autoScroll - */ -angular.module('passmanApp') - .directive('autoScroll', function () { - return { - restrict: 'A', - scope: { - autoScroll: '=' - }, - link: function postLink(scope, element, attrs) { - scope.$watch('autoScroll', function () { - $('#import_log').scrollTop($('#import_log')[0].scrollHeight); - }, true); - } - }; - }); +}());
\ No newline at end of file diff --git a/js/app/directives/clickselect.js b/js/app/directives/clickselect.js index f6abfe35..86220e00 100644 --- a/js/app/directives/clickselect.js +++ b/js/app/directives/clickselect.js @@ -1,22 +1,23 @@ -'use strict'; - -/** - * @ngdoc directive - * @name passmanApp.directive:selectOnClick - * @description - * # selectOnClick - */ -angular.module('passmanApp') - .directive('selectOnClick', ['$window', function ($window) { - return { - restrict: 'A', - link: function (scope, element, attrs) { - element.on('click', function () { - if (!$window.getSelection().toString()) { - // Required for mobile Safari - this.setSelectionRange(0, this.value.length) - } - }); - } - }; - }]);
\ No newline at end of file +(function () { + 'use strict'; + /** + * @ngdoc directive + * @name passmanApp.directive:selectOnClick + * @description + * # selectOnClick + */ + angular.module('passmanApp') + .directive('selectOnClick', ['$window', function ($window) { + return { + restrict: 'A', + link: function (scope, element, attrs) { + element.on('click', function () { + if (!$window.getSelection().toString()) { + // Required for mobile Safari + this.setSelectionRange(0, this.value.length); + } + }); + } + }; + }]); +}());
\ No newline at end of file diff --git a/js/app/directives/colorfromstring.js b/js/app/directives/colorfromstring.js index b0552fab..62127749 100644 --- a/js/app/directives/colorfromstring.js +++ b/js/app/directives/colorfromstring.js @@ -1,5 +1,5 @@ -'use strict'; - +(function () { + 'use strict'; /** * @ngdoc directive * @name passmanApp.directive:passwordGen @@ -26,9 +26,10 @@ angular.module('passmanApp') return '#' + '00000'.substring(0, 6 - c.length) + c; } scope.$watch('string', function(){ - $(el).css('border-color', genColor(scope.string)); - }) + jQuery(el).css('border-color', genColor(scope.string)); + }); } }; }]); +}());
\ No newline at end of file diff --git a/js/app/directives/credentialfield.js b/js/app/directives/credentialfield.js index 1271c9b5..0d040aa7 100644 --- a/js/app/directives/credentialfield.js +++ b/js/app/directives/credentialfield.js @@ -1,66 +1,67 @@ -'use strict'; +(function () { + 'use strict'; + /** + * @ngdoc directive + * @name passmanApp.directive:passwordGen + * @description + * # passwordGen + */ -/** - * @ngdoc directive - * @name passmanApp.directive:passwordGen - * @description - * # passwordGen - */ + angular.module('passmanApp') + .directive('credentialField', ['$timeout', function ($timeout) { + return { + scope: { + value: '=value', + secret: '=secret' + }, + restrict: 'A', + replace: 'true', + template: "" + + '<span class="credential_field">' + + '<div class="value" ng-class="{\'ellipsis\': isLink}">' + + '<span ng-repeat="n in [] | range:value.length" ng-if="!valueVisible">*</span>' + + '<span ng-if="valueVisible">{{value}}</span>' + + '</div>' + + '<div class="tools">' + + '<div class="cell" ng-if="toggle" tooltip="\'Toggle visibility\'" ng-click="toggleVisibility()"><i class="fa" ng-class="{\'fa-eye\': !valueVisible, \'fa-eye-slash\': valueVisible }"></i></div>' + + '<div class="cell" ng-if="isLink"><a ng-href="{{value}}" target="_blank"><i tooltip="\'Open in new window\'" class="link fa fa-external-link"></i></a></div>' + + '<div class="cell" ngclipboard-success="onSuccess(e);" ngclipboard-error="onError(e);" ngclipboard data-clipboard-text="{{value}}"><i tooltip="copy_msg" class="fa fa-clipboard"></i></div>' + + '</div></span>', + link: function (scope, elem, attrs, modelCtrl) { + var expression = /(https?:\/\/(?:www\.|(?!www))[^\s\.]+\.[^\s]{2,}|www\.[^\s]+\.[^\s]{2,})/gi; + var regex = new RegExp(expression); -angular.module('passmanApp') - .directive('credentialField', ['$timeout', function ($timeout) { - return { - scope: { - value: '=value', - secret: '=secret' - }, - restrict: 'A', - replace: 'true', - template: "" + - '<span class="credential_field">' + - '<div class="value" ng-class="{\'ellipsis\': isLink}">' + - '<span ng-repeat="n in [] | range:value.length" ng-if="!valueVisible">*</span>' + - '<span ng-if="valueVisible">{{value}}</span>' + - '</div>' + - '<div class="tools">' + - '<div class="cell" ng-if="toggle" tooltip="\'Toggle visibility\'" ng-click="toggleVisibility()"><i class="fa" ng-class="{\'fa-eye\': !valueVisible, \'fa-eye-slash\': valueVisible }"></i></div>' + - '<div class="cell" ng-if="isLink"><a ng-href="{{value}}" target="_blank"><i tooltip="\'Open in new window\'" class="link fa fa-external-link"></i></a></div>' + - '<div class="cell" ngclipboard-success="onSuccess(e);" ngclipboard-error="onError(e);" ngclipboard data-clipboard-text="{{value}}"><i tooltip="copy_msg" class="fa fa-clipboard"></i></div>' + - '</div></span>', - link: function (scope, elem, attrs, modelCtrl) { - var expression = /(https?:\/\/(?:www\.|(?!www))[^\s\.]+\.[^\s]{2,}|www\.[^\s]+\.[^\s]{2,})/gi; - var regex = new RegExp(expression); + scope.$watch("value", function () { + if (scope.value) { + if (scope.secret) { + scope.valueVisible = false; + } + if (scope.value.match(regex)) { + scope.isLink = true; - scope.$watch("value", function () { - if(scope.value) { - if (scope.secret) { - scope.valueVisible = false; + } } - if (scope.value.match(regex)) { - console.log('is link') - scope.isLink = true; - + }); + if (!scope.toggle) { + if (scope.secret) { + scope.toggle = true; } } - }); - if (!scope.toggle) { - if (scope.secret) { - scope.toggle = true; - } - } - scope.copy_msg = 'Copy to clipboard'; - var timer; - scope.onSuccess = function () { - scope.copy_msg = 'Copied to clipboard!'; - $timeout.cancel(timer); - timer = $timeout(function () { - scope.copy_msg = 'Copy to clipboard'; - }, 5000) + scope.copy_msg = 'Copy to clipboard'; + var timer; + scope.onSuccess = function () { + scope.copy_msg = 'Copied to clipboard!'; + $timeout.cancel(timer); + timer = $timeout(function () { + scope.copy_msg = 'Copy to clipboard'; + }, 5000); + }; + scope.valueVisible = true; + scope.toggleVisibility = function () { + scope.valueVisible = !scope.valueVisible; + }; } - scope.valueVisible = true; - scope.toggleVisibility = function () { - scope.valueVisible = !scope.valueVisible; - }; - } - }; - }]); + }; + }]); + +}());
\ No newline at end of file diff --git a/js/app/directives/fileselect.js b/js/app/directives/fileselect.js index 187863a9..60b3e25a 100644 --- a/js/app/directives/fileselect.js +++ b/js/app/directives/fileselect.js @@ -1,65 +1,67 @@ -'use strict'; +(function () { + 'use strict'; -/** - * @ngdoc directive - * @name passmanApp.directive:passwordGen - * @description - * # passwordGen - */ -angular.module('passmanApp') - .directive('fileSelect', ['$window', function ($window) { - return { - restrict: 'A', - scope: { - success: '&success', - error: '&error', - progress: '&progress' - }, + /** + * @ngdoc directive + * @name passmanApp.directive:passwordGen + * @description + * # passwordGen + */ + angular.module('passmanApp') + .directive('fileSelect', ['$window', function ($window) { + return { + restrict: 'A', + scope: { + success: '&success', + error: '&error', + progress: '&progress' + }, - link: function (scope, el, attr, ctrl) { - scope.success = scope.success(); - scope.error = scope.error(); - scope.progress = scope.progress(); - var fileReader = new $window.FileReader(); - var _currentFile; + link: function (scope, el, attr, ctrl) { + scope.success = scope.success(); + scope.error = scope.error(); + scope.progress = scope.progress(); + var fileReader = new $window.FileReader(); + var _currentFile; - fileReader.onload = function () { - _currentFile.data = fileReader.result; - scope.success(_currentFile) - }; + fileReader.onload = function () { + _currentFile.data = fileReader.result; + scope.success(_currentFile); + }; - fileReader.onprogress = function (event) { - var percent = (event.loaded / event.total * 100); - scope.$apply(scope.progress({ - file_total: event.total, - file_loaded: event.loaded, - file_percent: percent - })); - }; + fileReader.onprogress = function (event) { + var percent = (event.loaded / event.total * 100); + scope.$apply(scope.progress({ + file_total: event.total, + file_loaded: event.loaded, + file_percent: percent + })); + }; - fileReader.onerror = function () { - scope.error() - }; + fileReader.onerror = function () { + scope.error(); + }; - el.bind('change', function (e) { - var _queueTotalFileSize = 0; - var _queueProgressBytes = 0; - - //Calcutate total size - for (var i = 0; i < e.target.files.length; i++) { - _queueTotalFileSize += e.target.files[i].size; - } - //Now load the files - for (var i = 0; i < e.target.files.length; i++) { - _currentFile = e.target.files[i]; - var mb_limit = 5; - if (_currentFile.size > (mb_limit * 1024 * 1024)) { - scope.error('TO_BIG', _currentFile); + el.bind('change', function (e) { + var _queueTotalFileSize = 0; + var _queueProgressBytes = 0; + var i; + //Calcutate total size + for (i = 0; i < e.target.files.length; i++) { + _queueTotalFileSize += e.target.files[i].size; } - fileReader.readAsDataURL(_currentFile); + //Now load the files + for (i = 0; i < e.target.files.length; i++) { + _currentFile = e.target.files[i]; + var mb_limit = 5; + if (_currentFile.size > (mb_limit * 1024 * 1024)) { + scope.error('TO_BIG', _currentFile); + } + fileReader.readAsDataURL(_currentFile); - } - }); - } - }; - }]); + } + }); + } + }; + }]); +}());
\ No newline at end of file diff --git a/js/app/directives/ngenter.js b/js/app/directives/ngenter.js index a7c824e8..57f28662 100644 --- a/js/app/directives/ngenter.js +++ b/js/app/directives/ngenter.js @@ -1,22 +1,24 @@ -'use strict'; +(function () { + 'use strict'; -/** - * @ngdoc directive - * @name passmanApp.directive:passwordGen - * @description - * # passwordGen - */ -angular.module('passmanApp') - .directive('ngEnter', function () { - return function (scope, element, attrs) { - element.bind("keydown keypress", function (event) { - if (event.which === 13) { - scope.$apply(function () { - scope.$eval(attrs.ngEnter); - }); + /** + * @ngdoc directive + * @name passmanApp.directive:passwordGen + * @description + * # passwordGen + */ + angular.module('passmanApp') + .directive('ngEnter', function () { + return function (scope, element, attrs) { + element.bind("keydown keypress", function (event) { + if (event.which === 13) { + scope.$apply(function () { + scope.$eval(attrs.ngEnter); + }); - event.preventDefault(); - } - }); - }; - });
\ No newline at end of file + event.preventDefault(); + } + }); + }; + }); +}());
\ No newline at end of file diff --git a/js/app/directives/otp.js b/js/app/directives/otp.js index 6cd0f3c9..b03610d0 100644 --- a/js/app/directives/otp.js +++ b/js/app/directives/otp.js @@ -1,96 +1,104 @@ -'use strict'; +(function () { + 'use strict'; -/** - * @ngdoc directive - * @name passmanApp.directive:passwordGen - * @description - * # passwordGen - */ -angular.module('passmanApp') - .directive('otpGenerator', ['$compile', '$timeout', - function ($compile, $timeout) { - function dec2hex(s) { return (s < 15.5 ? '0' : '') + Math.round(s).toString(16); } - function hex2dec(s) { return parseInt(s, 16); } - - function base32tohex(base32) { - if(!base32){ - return; + /** + * @ngdoc directive + * @name passmanApp.directive:passwordGen + * @description + * # passwordGen + */ + angular.module('passmanApp') + .directive('otpGenerator', ['$compile', '$timeout', + function ($compile, $timeout) { + function dec2hex (s) { + return (s < 15.5 ? '0' : '') + Math.round(s).toString(16); } - var base32chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"; - var bits = ""; - var hex = ""; - for (var i = 0; i < base32.length; i++) { - var val = base32chars.indexOf(base32.charAt(i).toUpperCase()); - bits += leftpad(val.toString(2), 5, '0'); + function hex2dec (s) { + return parseInt(s, 16); } - for (var i = 0; i+4 <= bits.length; i+=4) { - var chunk = bits.substr(i, 4); - hex = hex + parseInt(chunk, 2).toString(16) ; - } - return hex; + function base32tohex (base32) { + if (!base32) { + return; + } + var base32chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"; + var bits = ""; + var hex = ""; + var i; + for (i = 0; i < base32.length; i++) { + var val = base32chars.indexOf(base32.charAt(i).toUpperCase()); + bits += leftpad(val.toString(2), 5, '0'); + } - } + for (i = 0; i + 4 <= bits.length; i += 4) { + var chunk = bits.substr(i, 4); + hex = hex + parseInt(chunk, 2).toString(16); + } + return hex; - function leftpad(str, len, pad) { - if (len + 1 >= str.length) { - str = Array(len + 1 - str.length).join(pad) + str; } - return str; - } - return { - restrict: 'A', - template: '<span class="otp_generator"><span credential-field value="otp" secret="\'true\'"></span> <span ng-bind="timeleft"></span></span>', - transclude: false, - scope: { - secret: '=' - }, - replace: true, - link: function (scope, element) { - scope.otp = null; - scope.timeleft = null; - scope.timer = null; - var updateOtp = function () { - if (!scope.secret) { - return; - } - var key = base32tohex(scope.secret); - var epoch = Math.round(new Date().getTime() / 1000.0); - var time = leftpad(dec2hex(Math.floor(epoch / 30)), 16, '0'); - var hmacObj = new jsSHA(time, 'HEX'); - var hmac = hmacObj.getHMAC(key, 'HEX', 'SHA-1', "HEX"); - var offset = hex2dec(hmac.substring(hmac.length - 1)); - var otp = (hex2dec(hmac.substr(offset * 2, 8)) & hex2dec('7fffffff')) + ''; - otp = (otp).substr(otp.length - 6, 6); - scope.otp = otp; - }; + function leftpad (str, len, pad) { + if (len + 1 >= str.length) { + str = Array(len + 1 - str.length).join(pad) + str; + } + return str; + } - var timer = function () { - var epoch = Math.round(new Date().getTime() / 1000.0); - var countDown = 30 - (epoch % 30); - if (epoch % 30 == 0) updateOtp(); - scope.timeleft = countDown; - scope.timer = $timeout(timer, 1000); + return { + restrict: 'A', + template: '<span class="otp_generator"><span credential-field value="otp" secret="\'true\'"></span> <span ng-bind="timeleft"></span></span>', + transclude: false, + scope: { + secret: '=' + }, + replace: true, + link: function (scope, element) { + scope.otp = null; + scope.timeleft = null; + scope.timer = null; + var updateOtp = function () { + if (!scope.secret) { + return; + } + var key = base32tohex(scope.secret); + var epoch = Math.round(new Date().getTime() / 1000.0); + var time = leftpad(dec2hex(Math.floor(epoch / 30)), 16, '0'); + var hmacObj = new jsSHA(time, 'HEX'); + var hmac = hmacObj.getHMAC(key, 'HEX', 'SHA-1', "HEX"); + var offset = hex2dec(hmac.substring(hmac.length - 1)); + var otp = (hex2dec(hmac.substr(offset * 2, 8)) & hex2dec('7fffffff')) + ''; + otp = (otp).substr(otp.length - 6, 6); + scope.otp = otp; - }; - scope.$watch("secret", function (n) { - if (n) { - $timeout.cancel(scope.timer); - updateOtp(); - timer(); - } else { - $timeout.cancel(scope.timer); - } - }, true); - scope.$on( - "$destroy", - function (event) { - $timeout.cancel(scope.timer); - } - ); - } + }; + + var timer = function () { + var epoch = Math.round(new Date().getTime() / 1000.0); + var countDown = 30 - (epoch % 30); + if (epoch % 30 === 0) updateOtp(); + scope.timeleft = countDown; + scope.timer = $timeout(timer, 1000); + + }; + scope.$watch("secret", function (n) { + if (n) { + $timeout.cancel(scope.timer); + updateOtp(); + timer(); + } else { + $timeout.cancel(scope.timer); + } + }, true); + scope.$on( + "$destroy", + function (event) { + $timeout.cancel(scope.timer); + } + ); + } + }; } - } - ]); + ]); +}());
\ No newline at end of file diff --git a/js/app/directives/passwordgen.js b/js/app/directives/passwordgen.js index 1e3af42e..42511aea 100644 --- a/js/app/directives/passwordgen.js +++ b/js/app/directives/passwordgen.js @@ -1,208 +1,225 @@ -'use strict'; - -/** - * @ngdoc directive - * @name passmanApp.directive:passwordGen - * @description - * # passwordGen - */ - -angular.module('passmanApp') - .directive('passwordGen', function ($timeout,$window) { - function Arcfour () { - this.j = this.i = 0, this.S = [] - } - function ARC4init (r) { - var t, n, e; - for (t = 0; 256 > t; ++t)this.S[t] = t - for (t = n = 0; 256 > t; ++t)n = n + this.S[t] + r[t % r.length] & 255, e = this.S[t], this.S[t] = this.S[n], this.S[n] = e - this.j = this.i = 0 - } - function ARC4next () { - var r; - return this.i = this.i + 1 & 255, this.j = this.j + this.S[this.i] & 255, r = this.S[this.i], this.S[this.i] = this.S[this.j], this.S[this.j] = r, this.S[r + this.S[this.i] & 255] - } - function prng_newstate () { - return new Arcfour - } - function generatePassword (r, t, n, e, o, i, p, g) { - var _, a, s, f, d, h, u, l, c, v, w, y, m; - if (void 0 === r && (r = 8 + get_random(0, 1)), r > 256 && (r = 256, document.getElementById("length").value = 256), i > 256 && (i = 256), void 0 === t && (t = !0), void 0 === n && (n = !0), void 0 === e && (e = !0), void 0 === o && (o = !1), void 0 === i && (i = 0), void 0 === p && (p = !1), void 0 === g && (g = !0), _ = 0, a = 0, s = 0, g && (_ = a = s = 1), f = [], n && _ > 0)for (d = 0; _ > d; d++)f[f.length] = "L" - if (t && a > 0)for (d = 0; a > d; d++)f[f.length] = "U" - if (e && i > 0)for (d = 0; i > d; d++)f[f.length] = "D" - if (o && s > 0)for (d = 0; s > d; d++)f[f.length] = "S" - for (; f.length < r;)f[f.length] = "A" - for (f.sort(function () { - return 2 * get_random(0, 1) - 1 - }), h = "", u = "abcdefghjkmnpqrstuvwxyz", p || (u += "ilo"), n && (h += u), l = "ABCDEFGHJKMNPQRSTUVWXYZ", p || (l += "ILO"), t && (h += l), c = "23456789", p || (c += "10"), e && (h += c), v = "!@#$%^&*", o && (h += v), w = "", y = 0; r > y; y++) { - switch (f[y]) { - case"L": - m = u; - break; - case"U": - m = l; - break; - case"D": - m = c; - break; - case"S": - m = v; - break; - case"A": - m = h - } - d = get_random(0, m.length - 1), w += m.charAt(d) +(function () { + 'use strict'; + + /** + * @ngdoc directive + * @name passmanApp.directive:passwordGen + * @description + * # passwordGen + */ + + angular.module('passmanApp') + .directive('passwordGen', function ($timeout, $window) { + /* jshint ignore:start */ + function Arcfour () { + this.j = this.i = 0, this.S = [] } - return w - } - function rng_seed_int (r) { - rng_pool[rng_pptr++] ^= 255 & r, rng_pool[rng_pptr++] ^= r >> 8 & 255, rng_pool[rng_pptr++] ^= r >> 16 & 255, rng_pool[rng_pptr++] ^= r >> 24 & 255, rng_pptr >= rng_psize && (rng_pptr -= rng_psize) - } - function rng_seed_time () { - rng_seed_int((new Date).getTime()) - } - function rng_get_byte () { - if (null == rng_state) { - for (rng_seed_time(), rng_state = prng_newstate(), rng_state.init(rng_pool), rng_pptr = 0; rng_pptr < rng_pool.length; ++rng_pptr)rng_pool[rng_pptr] = 0 - rng_pptr = 0 + + function ARC4init (r) { + var t, n, e; + for (t = 0; 256 > t; ++t)this.S[t] = t + for (t = n = 0; 256 > t; ++t)n = n + this.S[t] + r[t % r.length] & 255, e = this.S[t], this.S[t] = this.S[n], this.S[n] = e + this.j = this.i = 0 } - return rng_state.next() - } - function rng_get_bytes (r) { - var t; - for (t = 0; t < r.length; ++t)r[t] = rng_get_byte() - } - function SecureRandom () { - } - function get_random (r, t) { - var n, e, o, i = t - r + 1 - for (rng_seed_time(), n = [], e = 0; 4 > e; e++)n[e] = 0 - for (rng_get_bytes(n), o = 0, e = 0; 4 > e; e++)o *= 256, o += n[e] - return o %= i, o += r - } - function get_random_password (r, t) { - var n; - var pwlen, newpw; - for ("number" != typeof r && (r = 12), "number" != typeof t && (t = 16), r > t && (n = r, r = t, t = n), pwlen = get_random(r, t), newpw = ""; newpw.length < pwlen;)newpw += String.fromCharCode(get_random(32, 127)) - return newpw - } - var rng_psize, rng_state, rng_pool, rng_pptr, t, z, crypt_obj, num, buf, i - if (Arcfour.prototype.init = ARC4init, Arcfour.prototype.next = ARC4next, rng_psize = 256, null == rng_pool) { - if (rng_pool = [], rng_pptr = 0, "undefined" != typeof navigator && "Netscape" == navigator.appName && navigator.appVersion < "5" && "undefined" != typeof window && window.crypto)for (z = window.crypto.random(32), t = 0; t < z.length; ++t)rng_pool[rng_pptr++] = 255 & z.charCodeAt(t) - try { - if (crypt_obj = null, "undefined" != typeof window && void 0 !== window.crypto ? crypt_obj = window.crypto : "undefined" != typeof window && void 0 !== window.msCrypto && (crypt_obj = window.msCrypto), void 0 !== crypt_obj && "function" == typeof crypt_obj.getRandomValues && rng_psize > rng_pptr)for (num = Math.floor((rng_psize - rng_pptr) / 2) + 1, buf = new Uint16Array(num), crypt_obj.getRandomValues(buf), i = 0; i < buf.length; i++)t = buf[i], rng_pool[rng_pptr++] = t >>> 8, rng_pool[rng_pptr++] = 255 & t - } catch (e) { + + function ARC4next () { + var r; + return this.i = this.i + 1 & 255, this.j = this.j + this.S[this.i] & 255, r = this.S[this.i], this.S[this.i] = this.S[this.j], this.S[this.j] = r, this.S[r + this.S[this.i] & 255] } - for (; rng_psize > rng_pptr;)t = Math.floor(65536 * Math.random()), rng_pool[rng_pptr++] = t >>> 8, rng_pool[rng_pptr++] = 255 & t - rng_pptr = 0, rng_seed_time() - } - SecureRandom.prototype.nextBytes = rng_get_bytes; - - return { - scope: { - model : "=ngModel", - length : "@", - placeholder: "@", - settings: '=settings', - callback: '&callback' - }, - - restrict: "E", - replace : "true", - template: "" + - "<div class=\" pw-gen \">" + - "<div class=\"input-group \">" + - "<input ng-show=\"!passwordVisible\" type=\"password\" ng-disabled=\"disabled\" class=\"form-control \" ng-model=\"password\" placeholder=\"{{placeholder}}\">" + - "<input ng-show=\"passwordVisible\" type=\"text\" ng-disabled=\"disabled\" class=\"form-control \" ng-model=\"password\" placeholder=\"{{placeholder}}\">" + - - '<span class="generate_pw">' + - '<div class="cell" tooltip="\'Generate password\'" ng-click="generatePasswordStart()"><i class="fa fa-refresh"></i></div>' + - '<div class="cell" tooltip="\'Toggle password visibility\'" ng-click="toggleVisibility()"><i class="fa" ng-class="{\'fa-eye\': passwordVisible, \'fa-eye-slash\': !passwordVisible }"></i></div>' + - '<div class="cell" tooltip="\'Copy password to clipboard\'"><i class="fa fa-clipboard" ngclipboard-success="onSuccess(e);" ngclipboard-error="onError(e);" ngclipboard data-clipboard-text="{{password}}"></i></div>' + - "</button>" + - "</div>" + - "</div>", - link: function(scope, elem, attrs, modelCtrl) { - scope.callback = scope.callback(); - scope.$watch("model", function () { - scope.password = scope.model; - }); - scope.passwordVisible = false; - scope.toggleVisibility = function(){ - scope.passwordVisible = !scope.passwordVisible; - }; - - scope.passwordNotNull = false; - scope.$watch("settings", function () { - if(scope.settings) { - if (!scope.password && scope.settings.generateOnCreate) { - scope.generatePasswordStart(); - } + + function prng_newstate () { + return new Arcfour + } + + function generatePassword (r, t, n, e, o, i, p, g) { + var _, a, s, f, d, h, u, l, c, v, w, y, m; + if (void 0 === r && (r = 8 + get_random(0, 1)), r > 256 && (r = 256, document.getElementById("length").value = 256), i > 256 && (i = 256), void 0 === t && (t = !0), void 0 === n && (n = !0), void 0 === e && (e = !0), void 0 === o && (o = !1), void 0 === i && (i = 0), void 0 === p && (p = !1), void 0 === g && (g = !0), _ = 0, a = 0, s = 0, g && (_ = a = s = 1), f = [], n && _ > 0)for (d = 0; _ > d; d++)f[f.length] = "L" + if (t && a > 0)for (d = 0; a > d; d++)f[f.length] = "U" + if (e && i > 0)for (d = 0; i > d; d++)f[f.length] = "D" + if (o && s > 0)for (d = 0; s > d; d++)f[f.length] = "S" + for (; f.length < r;)f[f.length] = "A" + for (f.sort(function () { + return 2 * get_random(0, 1) - 1 + }), h = "", u = "abcdefghjkmnpqrstuvwxyz", p || (u += "ilo"), n && (h += u), l = "ABCDEFGHJKMNPQRSTUVWXYZ", p || (l += "ILO"), t && (h += l), c = "23456789", p || (c += "10"), e && (h += c), v = "!@#$%^&*", o && (h += v), w = "", y = 0; r > y; y++) { + switch (f[y]) { + case"L": + m = u; + break; + case"U": + m = l; + break; + case"D": + m = c; + break; + case"S": + m = v; + break; + case"A": + m = h } - }); - - - scope.$watch("password", function () { - scope.model = scope.password; - scope.password_repeat = scope.model; - }); - // - scope.onSuccess = function(e) { - //@TODO move OC.Notification to a service - OC.Notification.showTemporary('Password copied to clipboard!'); - e.clearSelection(); - }; - - scope.onError = function(e) { - OC.Notification.showTemporary('Press Ctrl+C to copy!'); - }; - scope.progressDivShow = false; - scope.generatePasswordStart = function() { - scope.progressDivShow = true; - scope.progressValue = 0; - scope.progressWidth = {"width": scope.progressValue + "%"}; - scope.generatePasswordProgress(); - }; - scope.generatePasswordProgress = function() { - $timeout(function() { - if(scope.progressValue < 100) { - scope.password = scope._generatePassword(scope.settings); - scope.progressValue += 10; - scope.progressWidth = {"width": scope.progressValue + "%"}; - scope.disabled = true; - scope.generatePasswordProgress(); - } else { - scope.disabled = false; - if(scope.callback) { - scope.callback(scope.password) + d = get_random(0, m.length - 1), w += m.charAt(d) + } + return w + } + + function rng_seed_int (r) { + rng_pool[rng_pptr++] ^= 255 & r, rng_pool[rng_pptr++] ^= r >> 8 & 255, rng_pool[rng_pptr++] ^= r >> 16 & 255, rng_pool[rng_pptr++] ^= r >> 24 & 255, rng_pptr >= rng_psize && (rng_pptr -= rng_psize) + } + + function rng_seed_time () { + rng_seed_int((new Date).getTime()) + } + + function rng_get_byte () { + if (null == rng_state) { + for (rng_seed_time(), rng_state = prng_newstate(), rng_state.init(rng_pool), rng_pptr = 0; rng_pptr < rng_pool.length; ++rng_pptr)rng_pool[rng_pptr] = 0 + rng_pptr = 0 + } + return rng_state.next() + } + + function rng_get_bytes (r) { + var t; + for (t = 0; t < r.length; ++t)r[t] = rng_get_byte() + } + + function SecureRandom () { + } + + function get_random (r, t) { + var n, e, o, i = t - r + 1 + for (rng_seed_time(), n = [], e = 0; 4 > e; e++)n[e] = 0 + for (rng_get_bytes(n), o = 0, e = 0; 4 > e; e++)o *= 256, o += n[e] + return o %= i, o += r + } + + function get_random_password (r, t) { + var n; + var pwlen, newpw; + for ("number" != typeof r && (r = 12), "number" != typeof t && (t = 16), r > t && (n = r, r = t, t = n), pwlen = get_random(r, t), newpw = ""; newpw.length < pwlen;)newpw += String.fromCharCode(get_random(32, 127)) + return newpw + } + + var rng_psize, rng_state, rng_pool, rng_pptr, t, z, crypt_obj, num, buf, i + if (Arcfour.prototype.init = ARC4init, Arcfour.prototype.next = ARC4next, rng_psize = 256, null == rng_pool) { + if (rng_pool = [], rng_pptr = 0, "undefined" != typeof navigator && "Netscape" == navigator.appName && navigator.appVersion < "5" && "undefined" != typeof window && window.crypto)for (z = window.crypto.random(32), t = 0; t < z.length; ++t)rng_pool[rng_pptr++] = 255 & z.charCodeAt(t) + try { + if (crypt_obj = null, "undefined" != typeof window && void 0 !== window.crypto ? crypt_obj = window.crypto : "undefined" != typeof window && void 0 !== window.msCrypto && (crypt_obj = window.msCrypto), void 0 !== crypt_obj && "function" == typeof crypt_obj.getRandomValues && rng_psize > rng_pptr)for (num = Math.floor((rng_psize - rng_pptr) / 2) + 1, buf = new Uint16Array(num), crypt_obj.getRandomValues(buf), i = 0; i < buf.length; i++)t = buf[i], rng_pool[rng_pptr++] = t >>> 8, rng_pool[rng_pptr++] = 255 & t + } catch (e) { + } + for (; rng_psize > rng_pptr;)t = Math.floor(65536 * Math.random()), rng_pool[rng_pptr++] = t >>> 8, rng_pool[rng_pptr++] = 255 & t + rng_pptr = 0, rng_seed_time() + } + SecureRandom.prototype.nextBytes = rng_get_bytes; + /* jshint ignore:end */ + return { + scope: { + model: "=ngModel", + length: "@", + placeholder: "@", + settings: '=settings', + callback: '&callback' + }, + + restrict: "E", + replace: "true", + template: "" + + "<div class=\" pw-gen \">" + + "<div class=\"input-group \">" + + "<input ng-show=\"!passwordVisible\" type=\"password\" ng-disabled=\"disabled\" class=\"form-control \" ng-model=\"password\" placeholder=\"{{placeholder}}\">" + + "<input ng-show=\"passwordVisible\" type=\"text\" ng-disabled=\"disabled\" class=\"form-control \" ng-model=\"password\" placeholder=\"{{placeholder}}\">" + + + '<span class="generate_pw">' + + '<div class="cell" tooltip="\'Generate password\'" ng-click="generatePasswordStart()"><i class="fa fa-refresh"></i></div>' + + '<div class="cell" tooltip="\'Toggle password visibility\'" ng-click="toggleVisibility()"><i class="fa" ng-class="{\'fa-eye\': passwordVisible, \'fa-eye-slash\': !passwordVisible }"></i></div>' + + '<div class="cell" tooltip="\'Copy password to clipboard\'"><i class="fa fa-clipboard" ngclipboard-success="onSuccess(e);" ngclipboard-error="onError(e);" ngclipboard data-clipboard-text="{{password}}"></i></div>' + + "</button>" + + "</div>" + + "</div>", + link: function (scope, elem, attrs, modelCtrl) { + scope.callback = scope.callback(); + scope.$watch("model", function () { + scope.password = scope.model; + }); + scope.passwordVisible = false; + scope.toggleVisibility = function () { + scope.passwordVisible = !scope.passwordVisible; + }; + + scope.passwordNotNull = false; + scope.$watch("settings", function () { + if (scope.settings) { + if (!scope.password && scope.settings.generateOnCreate) { + scope.generatePasswordStart(); } } - }, 10); - }; - - - scope._generatePassword = function (settings) { - var _settings = { - 'length': 12, - 'useUppercase': true, - 'useLowercase': true, - 'useDigits': true, - 'useSpecialChars': true, - 'minimumDigitCount': 3, - 'avoidAmbiguousCharacters': false, - 'requireEveryCharType': true + }); + + + scope.$watch("password", function () { + scope.model = scope.password; + scope.password_repeat = scope.model; + }); + // + scope.onSuccess = function (e) { + //@TODO move OC.Notification to a service + OC.Notification.showTemporary('Password copied to clipboard!'); + e.clearSelection(); }; - settings = angular.merge(_settings, settings); - var password = generatePassword(settings['length'], - settings.useUppercase, - settings.useLowercase, - settings.useDigits, - settings.useSpecialChars, - settings.minimumDigitCount, - settings.avoidAmbiguousCharacters, - settings.requireEveryCharType); - return password; - }; - } - }; - }); + + scope.onError = function (e) { + OC.Notification.showTemporary('Press Ctrl+C to copy!'); + }; + scope.progressDivShow = false; + scope.generatePasswordStart = function () { + scope.progressDivShow = true; + scope.progressValue = 0; + scope.progressWidth = {"width": scope.progressValue + "%"}; + scope.generatePasswordProgress(); + }; + scope.generatePasswordProgress = function () { + $timeout(function () { + if (scope.progressValue < 100) { + scope.password = scope._generatePassword(scope.settings); + scope.progressValue += 10; + scope.progressWidth = {"width": scope.progressValue + "%"}; + scope.disabled = true; + scope.generatePasswordProgress(); + } else { + scope.disabled = false; + if (scope.callback) { + scope.callback(scope.password); + } + } + }, 10); + }; + + + scope._generatePassword = function (settings) { + var _settings = { + 'length': 12, + 'useUppercase': true, + 'useLowercase': true, + 'useDigits': true, + 'useSpecialChars': true, + 'minimumDigitCount': 3, + 'avoidAmbiguousCharacters': false, + 'requireEveryCharType': true + }; + settings = angular.merge(_settings, settings); + /* jshint ignore:start */ + var password = generatePassword(settings['length'], + settings.useUppercase, + settings.useLowercase, + settings.useDigits, + settings.useSpecialChars, + settings.minimumDigitCount, + settings.avoidAmbiguousCharacters, + settings.requireEveryCharType); + /* jshint ignore:end */ + return password; + }; + } + }; + }); +}());
\ No newline at end of file diff --git a/js/app/directives/progressbar.js b/js/app/directives/progressbar.js index 19423f35..0b4d9e11 100644 --- a/js/app/directives/progressbar.js +++ b/js/app/directives/progressbar.js @@ -1,31 +1,32 @@ -'use strict'; - -/** - * @ngdoc directive - * @name passmanApp.directive:passwordGen - * @description - * # passwordGen - */ -angular.module('passmanApp') - .directive('progressBar', ['$window', function ($window) { - return { - restrict: 'A', - template:''+ - '<div class="progress">'+ - '<div class="progress-bar" role="progressbar" aria-valuenow="{{progress}}"aria-valuemin="0" aria-valuemax="100" style="width:{{progress}}%;" use-theme>'+ +(function () { + 'use strict'; + /** + * @ngdoc directive + * @name passmanApp.directive:passwordGen + * @description + * # passwordGen + */ + angular.module('passmanApp') + .directive('progressBar', ['$window', function ($window) { + return { + restrict: 'A', + template: '' + + '<div class="progress">' + + '<div class="progress-bar" role="progressbar" aria-valuenow="{{progress}}"aria-valuemin="0" aria-valuemax="100" style="width:{{progress}}%;" use-theme>' + '<span class="sr-only">{{progress}}% Complete</span>' + - '<span ng-if="index && total" class="progress-label" use-theme type="\'color\'" color="\'true\'">{{index}} / {{total}}</span>'+ - '<span ng-if="!index && !total" class="progress-label" use-theme type="\'color\'" color="\'true\'">{{progress}}%</span>'+ - '</div>'+ + '<span ng-if="index && total" class="progress-label" use-theme type="\'color\'" color="\'true\'">{{index}} / {{total}}</span>' + + '<span ng-if="!index && !total" class="progress-label" use-theme type="\'color\'" color="\'true\'">{{progress}}%</span>' + + '</div>' + '</div>', - scope: { - progress: '=progressBar', - index: '=index', - total: '=total' - }, + scope: { + progress: '=progressBar', + index: '=index', + total: '=total' + }, - link: function (scope, el, attr, ctrl) { + link: function (scope, el, attr, ctrl) { - } - }; - }]); + } + }; + }]); +}());
\ No newline at end of file diff --git a/js/app/directives/qrreader.js b/js/app/directives/qrreader.js index acba6a05..824e99a6 100644 --- a/js/app/directives/qrreader.js +++ b/js/app/directives/qrreader.js @@ -1,37 +1,44 @@ -'use strict'; +(function () { + 'use strict'; -/** - * @ngdoc directive - * @name passmanApp.directive:passwordGen - * @description - * # passwordGen - */ -angular.module('passmanApp').directive("qrread", ['$parse','$compile', - function($parse,$compile) { - return { - scope : true, - link : function(scope, element, attributes) { - var gCtx = null,gCanvas = null, c= 0, stype= 0, gUM=false, webkit=false, moz=false; - var invoker = $parse(attributes.onRead); - scope.imageData = null; + /** + * @ngdoc directive + * @name passmanApp.directive:passwordGen + * @description + * # passwordGen + */ + angular.module('passmanApp').directive("qrread", ['$parse', '$compile', + function ($parse, $compile) { + return { + scope: true, + link: function (scope, element, attributes) { + var gCtx = null, gCanvas = null, c = 0, stype = 0, gUM = false, webkit = false, moz = false; + var invoker = $parse(attributes.onRead); + scope.imageData = null; - qrcode.callback = function(result){ - //console.log('QR callback:',result); - invoker(scope, {qrdata: {qrData: result, image: scope.imageData } }); - //element.val(''); + qrcode.callback = function (result) { + //console.log('QR callback:',result); + invoker(scope, { + qrdata: { + qrData: result, + image: scope.imageData + } + }); + //element.val(''); + }; + element.bind("change", function (changeEvent) { + var reader = new FileReader(), file = changeEvent.target.files[0]; + reader.readAsDataURL(file); + reader.onload = (function (theFile) { + return function (e) { + //gCtx.clearRect(0, 0, gCanvas.width, gCanvas.height); + scope.imageData = e.target.result; + qrcode.decode(e.target.result); + }; + })(file); + }); } - element.bind("change", function(changeEvent) { - var reader = new FileReader(),file = changeEvent.target.files[0]; - reader.readAsDataURL(file); - reader.onload = (function(theFile) { - return function(e) { - //gCtx.clearRect(0, 0, gCanvas.width, gCanvas.height); - scope.imageData = e.target.result; - qrcode.decode(e.target.result); - }; - })(file); - }); - } + }; } - } -]);
\ No newline at end of file + ]); +}());
\ No newline at end of file diff --git a/js/app/directives/tooltip.js b/js/app/directives/tooltip.js index 8729bfa6..78c3257f 100644 --- a/js/app/directives/tooltip.js +++ b/js/app/directives/tooltip.js @@ -1,32 +1,33 @@ -'use strict'; +(function () { + 'use strict'; + /** + * @ngdoc directive + * @name passmanApp.directive:passwordGen + * @description + * # passwordGen + */ + angular.module('passmanApp') + .directive('tooltip', ['$window', function ($window) { + return { + restrict: 'A', + scope: { + tooltip: '=tooltip' + }, -/** - * @ngdoc directive - * @name passmanApp.directive:passwordGen - * @description - * # passwordGen - */ -angular.module('passmanApp') - .directive('tooltip', ['$window', function ($window) { - return { - restrict: 'A', - scope: { - tooltip: '=tooltip' - }, + link: function (scope, el, attr, ctrl) { + scope.$watch('tooltip', function (newVal, old) { + if (scope.tooltip) { + jQuery(el).attr('title', scope.tooltip); + jQuery(el).tooltip(); + jQuery(el).attr('title', scope.tooltip).tooltip('fixTitle'); + jQuery('.tooltip-inner').text(scope.tooltip); // Dirty hack + if (jQuery(el).is(':visible')) { + //$(el).tooltip('show') + } - link: function (scope, el, attr, ctrl) { - scope.$watch('tooltip', function (newVal, old) { - if (scope.tooltip) { - $(el).attr('title', scope.tooltip); - $(el).tooltip(); - $(el).attr('title', scope.tooltip).tooltip('fixTitle'); - $('.tooltip-inner').text(scope.tooltip); // Dirty hack - if($(el).is(':visible')){ - //$(el).tooltip('show') } - - } - }) - } - }; - }]); + }); + } + }; + }]); +}());
\ No newline at end of file diff --git a/js/app/directives/use-theme.js b/js/app/directives/use-theme.js index a1a10c51..d981d158 100644 --- a/js/app/directives/use-theme.js +++ b/js/app/directives/use-theme.js @@ -1,45 +1,47 @@ -'use strict'; +(function () { + 'use strict'; + /** + * @ngdoc directive + * @name passmanApp.directive:passwordGen + * @description + * # passwordGen + */ + angular.module('passmanApp') + .directive('useTheme', ['$window', function ($window) { -/** - * @ngdoc directive - * @name passmanApp.directive:passwordGen - * @description - * # passwordGen - */ -angular.module('passmanApp') - .directive('useTheme', ['$window', function ($window) { + function invertColor (hexTripletColor) { + var color = hexTripletColor; + color = color.substring(1); // remove # + color = parseInt(color, 16); // convert to integer + color = 0xFFFFFF ^ color; // invert three bytes + color = color.toString(16); // convert to hex + color = ("000000" + color).slice(-6); // pad with leading zeros + color = "#" + color; // prepend # + return color; + } - function invertColor(hexTripletColor) { - var color = hexTripletColor; - color = color.substring(1); // remove # - color = parseInt(color, 16); // convert to integer - color = 0xFFFFFF ^ color; // invert three bytes - color = color.toString(16); // convert to hex - color = ("000000" + color).slice(-6); // pad with leading zeros - color = "#" + color; // prepend # - return color; - } - return { - restrict: 'A', - scope:{ - type: '=type', - color: '=', - negative: '=' - }, - link: function (scope, el, attr, ctrl) { - var _color = $('#header').css('background-color'); - var _bg = _color; - if(scope.negative){ - _bg = invertColor(_bg) - } - if(!scope.type) { - $(el).css('background-color', _bg); - } else { - $(el).css(scope.type, _bg); + return { + restrict: 'A', + scope: { + type: '=type', + color: '=', + negative: '=' + }, + link: function (scope, el, attr, ctrl) { + var _color = jQuery('#header').css('background-color'); + var _bg = _color; + if (scope.negative) { + _bg = invertColor(_bg); + } + if (!scope.type) { + jQuery(el).css('background-color', _bg); + } else { + jQuery(el).css(scope.type, _bg); + } + if (scope.color) { + jQuery(el).css('color', invertColor(_color)); + } } - if(scope.color){ - $(el).css('color', invertColor(_color)); - } - } - }; - }]); + }; + }]); +}());
\ No newline at end of file |