diff --git a/Gruntfile.js b/Gruntfile.js index b1214dad..54878e28 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -164,9 +164,7 @@ capIsNewExceptions: [ 'QueryInterface', 'ConvertToUnicode', 'ConvertFromUnicode' ] - }], - 'one-var': 0, - indent: 0 + }] } } }, diff --git a/test/manual/expand_test_patch.js b/test/manual/expand_test_patch.js index 15cc939f..a2db8ef7 100644 --- a/test/manual/expand_test_patch.js +++ b/test/manual/expand_test_patch.js @@ -315,6 +315,35 @@ assert(JSON.stringify(arr.cutIn(1, ...['b', 'd'])), '["a","b","d","c"]'); } + assert(Function.execute(), null); + assert(Function.execute(function () {}), void 0); + assert(Function.execute(function () { return this; }, Array), Array); + assert(Function.execute(a => a, null, 0), 0); + assert(Function.execute(function () { return this instanceof Boolean; }, false)); + assert(Function.execute('toString', false), 'false'); + assert(Function.execute(function (target) { return this.isArray(target); }, Array, [[]]), true); + assert(Function.execute(function (target) { return this.isArray(target); }, Array, []), false); + assert(Function.execute(function (num1, num2) { return num1 + num2; }, null, [1, 2]), 3); + assert(Function.execute(Object.keys, Object, {hoge : 0})[0], 'hoge'); + assert(Function.execute('keys', Object, {hoge : 0})[0], 'hoge'); + assert(Function.execute(void 0, Object, {hoge : 0}), null); + assert(Function.execute(void 0, Object), null); + assert(Function.execute('hoge', {hoge : arg => arg}, 0), 0); + assert(Function.execute('hoge', {}, 0), null); + assert(Function.execute('hoge', null, 0), null); + assert(Function.execute('hoge'), null); + + assert((function () {}).async(), void 0); + assert((function () {}).async(void 0), void 0); + assert((function () {}).async(null), void 0); + assert((function () {}).async({}), void 0); + assert((function () {}).async(null, 'hoge'), void 0); + assert((function () {}).async({}, 'hoge'), void 0); + assert((function () {}).async(null, ['hoge', 'fuga']), void 0); + assert((function () {}).async({}, ['hoge', 'fuga']), void 0); + assert((function () {}).async({}, [['hoge', 'fuga']]), void 0); + assert((function () { return this instanceof Boolean; }).async(false), void 0); + assert(JSON.parseable(void 0), false); assert(JSON.parseable(''), false); assert(JSON.parseable(NaN), false); diff --git a/xpi/chrome/content/changeAccount/changeAccount.css b/xpi/chrome/content/changeAccount/changeAccount.css index 879c1727..7895f43d 100644 --- a/xpi/chrome/content/changeAccount/changeAccount.css +++ b/xpi/chrome/content/changeAccount/changeAccount.css @@ -1,14 +1,29 @@ -.services > radio, -.accounts > listitem, +dialog { + padding-top: 10px; + padding-right: 10px; + padding-bottom: 10px; + padding-left: 10px; +} + +.main, +.left-box, +.right-box, +.accounts { + -moz-box-flex: 1; +} + +.services, +.account, .login-button:not([disabled]) { cursor: pointer; } -.right-box { - margin-left: 0.7em; +.services .menulist-icon { + width: 16px; + height: 16px; } -.accounts > listitem { +.account { padding-top: 0.5em; padding-right: 0.2em; padding-bottom: 0.5em; diff --git a/xpi/chrome/content/changeAccount/changeAccount.js b/xpi/chrome/content/changeAccount/changeAccount.js index de2e30ec..6a486e43 100644 --- a/xpi/chrome/content/changeAccount/changeAccount.js +++ b/xpi/chrome/content/changeAccount/changeAccount.js @@ -4,73 +4,88 @@ 'use strict'; let env = Components.classes[ - '@tombfix.github.io/tombfix-service;1' - ].getService().wrappedJSObject, - {Models} = env, - services = doc.querySelector('.services'); - - for (let model of Models.values) { - if ( - model.login && model.getCurrentUser && - model.getPasswords && model.getPasswords().length - ) { - let modelName = model.name; + '@tombfix.github.io/tombfix-service;1' + ].getService().wrappedJSObject; + let {Models} = env; + + function getAccountInfoList(model) { + let infoList; - services.appendItem(modelName, modelName).setAttribute('src', model.ICON); + if (model.getPasswords) { + infoList = model.getPasswords(); } + + return Array.isArray(infoList) ? infoList : []; } - if (!services.childElementCount) { + let targets = Models.values.filter(model => + model.login && model.getCurrentUser && getAccountInfoList(model).length + ); + + if (!targets.length) { + doc.querySelector('.left-box').hidden = true; + win.addEventListener('load', () => { // load時は、まだダイアログが表示されていない - setTimeout(() => { - win.alert(env.getMessage('message.changeAccount.infoNotFound')); - }, 0); + env.showMessage.async(env, ['message.changeAccount.infoNotFound', win]); }); return; } - let loginButton = doc.querySelector('.login-button'), - accounts = doc.querySelector('.accounts'); + let services = doc.querySelector('.services'); + let loginButton = doc.querySelector('.login-button'); + let accounts = doc.querySelector('.accounts'); + + function createAccountList(accountInfoList, currentUserList) { + for (let {user, password} of accountInfoList) { + let account = accounts.appendItem(user, password); + + account.classList.add('listitem-iconic', 'account'); + + if (currentUserList.some(currentUser => + currentUser && currentUser === user + )) { + account.image = 'chrome://tombfix/skin/tick.png'; + account.disabled = true; + } else { + account.image = 'chrome://tombfix/skin/empty.png'; + + if (!accounts.selectedItem) { + accounts.selectedItem = account; + } + } + } + } services.addEventListener('select', () => { loginButton.disabled = true; let model = Models[services.value]; - model.getCurrentUser().addBoth(result => { + model.getCurrentUser().addErrback(() => []).addCallback(list => { if (model.name !== services.value) { return; } env.clearChildren(accounts); - let currentUser = typeof result === 'string' ? result : ''; - - for (let {user, password} of model.getPasswords()) { - let account = accounts.appendItem(user, password); - - account.classList.add('listitem-iconic'); - - if (currentUser && currentUser === user) { - account.image = 'chrome://tombfix/skin/tick.png'; - account.disabled = true; - - accounts.selectedItem = account; - } else { - account.image = 'chrome://tombfix/skin/empty.png'; - } - } + // 「アカウントの切り替え」を開いて2回目以降にアカウントリストの表示がおかしくなるのを防ぐ + createAccountList.async(null, [ + getAccountInfoList(model), + Array.wrap(list) + ]); }); }); accounts.addEventListener('select', () => { let account = accounts.selectedItem; - if (account) { - loginButton.disabled = account.disabled; + if (!account) { + return; } + + loginButton.disabled = account.disabled; }); win.addEventListener('dialogaccept', () => { @@ -80,6 +95,15 @@ }); win.addEventListener('load', () => { + // load後でないとアイコンが表示されない + for (let model of targets) { + let modelName = model.name; + let menuitem = services.appendItem(modelName, modelName); + + menuitem.classList.add('menuitem-iconic'); + menuitem.image = model.ICON; + } + services.selectedIndex = 0; }); }(window, document)); diff --git a/xpi/chrome/content/changeAccount/changeAccount.xul b/xpi/chrome/content/changeAccount/changeAccount.xul index af22047a..535d03cd 100755 --- a/xpi/chrome/content/changeAccount/changeAccount.xul +++ b/xpi/chrome/content/changeAccount/changeAccount.xul @@ -2,19 +2,26 @@ - - - - - -