From 92abfb9e7576faee14c3bb2b65a42548d174696b Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Mon, 21 Dec 2015 17:31:08 +0100 Subject: [PATCH] add Clipboard action on button copy --- app/app.js | 86 +++++++++++++++++++++++++++---------------------- app/lesspass.js | 3 +- package.json | 4 ++- static/index.html | 43 ++++++++++++++----------- tests/lesspass.tests.js | 4 +-- 5 files changed, 79 insertions(+), 61 deletions(-) diff --git a/app/app.js b/app/app.js index 08f4748..d2c58e1 100644 --- a/app/app.js +++ b/app/app.js @@ -1,38 +1,59 @@ import {lesspass} from '../app/lesspass'; import angular from 'angular'; +import Clipboard from 'clipboard'; + class lesspassController { - constructor() { - this.lowercase = true; - this.uppercase = true; - this.numbers = true; - this.symbols = true; - } - displayHelp(){ - $('body').chardinJs('start'); + constructor($scope) { + var vm = this; + + this.password = ''; + this.site = { + site_name: '', + password_length: 12, + password_types: ['lowercase', 'uppercase', 'numbers', 'symbols'], + counter: 1 + }; + + $scope.$watch(function () { + return vm.password; + }, function () { + vm.updatePassword(); + }); + $scope.$watchCollection(function () { + return vm.site; + }, function () { + vm.updatePassword(); + }); + + new Clipboard('.copy-btn'); } - createPassword() { - var passwordTypes = []; - if (this.lowercase) { - passwordTypes.push('lowercase'); - } - if (this.uppercase) { - passwordTypes.push('uppercase'); - } - if (this.numbers) { - passwordTypes.push('numbers'); + + updatePasswordTypes(type) { + var passwordTypes = this.site.password_types; + var indexOfId = passwordTypes.indexOf(type); + if (indexOfId == -1) { + passwordTypes.push(type) + } else { + passwordTypes.splice(indexOfId, 1) } - if (this.symbols) { - passwordTypes.push('symbols'); + this.updatePassword(); + } + + updatePassword() { + if(this.password && this.site.site_name){ + this.generatedPassword = lesspass.create_password(this.password, this.site); } - var site_information = { - 'site_name': this.site, - 'password_length': 12, - 'password_types': passwordTypes, - 'counter': 1 - }; + } - this.generatedPassword = lesspass.create_password(this.password, site_information); + displayHelp() { + if (this.helpDisplayed) { + $('body').chardinJs('stop'); + this.helpDisplayed = false; + } else { + $('body').chardinJs('start'); + this.helpDisplayed = true; + } } } @@ -40,14 +61,3 @@ class lesspassController { angular .module('app', []) .controller('lesspassController', lesspassController); - - -/* -var clipboard = new Clipboard('#copy-btn',{ - text: function(trigger) { - $('body').chardinJs('stop'); - var elements = document.getElementById('foo').value.split(':'); - return PasswordGenerator.make_password(elements[0], elements[1]); - } -}); -*/ \ No newline at end of file diff --git a/app/lesspass.js b/app/lesspass.js index ace2005..984779a 100644 --- a/app/lesspass.js +++ b/app/lesspass.js @@ -31,7 +31,7 @@ export class lesspass { }; return passwordTypes .map(passwordType => passwordTypesInfo[passwordType]) - .sort((pt1, pt2) => pt1.order > pt2.order) + .sort((passwordType1, passwordType2) => passwordType1.order > passwordType2.order) .map(passwordType => passwordType.value) .join(''); } @@ -56,7 +56,6 @@ export class lesspass { return passwordChar[index % passwordChar.length]; } - static _encode(hash, template) { var password = ''; this._string2charCodes(hash).map( diff --git a/package.json b/package.json index 43cdee1..318cccf 100644 --- a/package.json +++ b/package.json @@ -34,12 +34,14 @@ "homepage": "https://github.com/guillaumevincent/lesspass#readme", "dependencies": { "angular": "^1.4.8", - "bootstrap": "^3.3.6" + "bootstrap": "^3.3.6", + "clipboard": "^1.5.5" }, "devDependencies": { "babel-core": "latest", "babel-polyfill": "latest", "babel-preset-es2015": "latest", + "babelify": "latest", "browserify": "latest", "jshint": "latest", "mocha": "latest", diff --git a/static/index.html b/static/index.html index a1eb38d..a8a2732 100644 --- a/static/index.html +++ b/static/index.html @@ -3,6 +3,7 @@ lesspass + @@ -33,11 +34,8 @@ - - -