From 4a8d6f49f4961e03d2eb5343c2ccc197b1b82199 Mon Sep 17 00:00:00 2001 From: isqua Date: Thu, 8 Jan 2015 18:53:24 +0300 Subject: [PATCH] Move OptionsManager to separate file --- chrome_point_plus/js/options-manager.js | 37 +++++++++++++++++++++++ chrome_point_plus/js/point-plus.js | 39 ------------------------- chrome_point_plus/manifest.json | 4 ++- 3 files changed, 40 insertions(+), 40 deletions(-) create mode 100644 chrome_point_plus/js/options-manager.js diff --git a/chrome_point_plus/js/options-manager.js b/chrome_point_plus/js/options-manager.js new file mode 100644 index 0000000..0a5072b --- /dev/null +++ b/chrome_point_plus/js/options-manager.js @@ -0,0 +1,37 @@ +/** + * Объект для получения опций + * @param {Object} options Хеш настроек + * @constructor + */ +function OptionsManager(options) { + this._options = options || {}; +} + +/** + * @param {String} optionName Имя опции + * @returns {Boolean|String|Null} Значение опции + */ +OptionsManager.prototype.get = function(optionName) { + return this._options.hasOwnProperty(optionName) ? this._options[optionName].value : null; +}; + +/** + * Проверяет, равна ли опция значению value. Если value не переданно, проверяет задана ли она и не равна ли false/'' + * @param {String} optionName Имя опции + * @param {Boolean|String} [value=true] Значение опции + * @returns {Boolean} + */ +OptionsManager.prototype.is = function(optionName, value) { + if (typeof value !== 'undefined') { + return this.get(optionName) === value; + } else { + return Boolean(this.get(optionName)); + } +}; + +/** + * @returns {Object} Хеш опций + */ +OptionsManager.prototype.getOptions = function() { + return this._options; +}; diff --git a/chrome_point_plus/js/point-plus.js b/chrome_point_plus/js/point-plus.js index 3be4249..007a0b8 100644 --- a/chrome_point_plus/js/point-plus.js +++ b/chrome_point_plus/js/point-plus.js @@ -5,45 +5,6 @@ chrome.runtime.sendMessage({ console.debug('showPageAction response: %O', response); }); -// @todo Move OptionsManager to the separate file -/** - * Объект для получения опций - * @param {Object} options Хеш настроек - * @constructor - */ -function OptionsManager(options) { - this._options = options || {}; -} - -/** - * @param {String} optionName Имя опции - * @returns {Boolean|String|Null} Значение опции - */ -OptionsManager.prototype.get = function(optionName) { - return this._options.hasOwnProperty(optionName) ? this._options[optionName].value : null; -}; - -/** - * Проверяет, равна ли опция значению value. Если value не переданно, проверяет задана ли она и не равна ли false/'' - * @param {String} optionName Имя опции - * @param {Boolean|String} [value=true] Значение опции - * @returns {Boolean} - */ -OptionsManager.prototype.is = function(optionName, value) { - if (typeof value !== 'undefined') { - return this.get(optionName) === value; - } else { - return Boolean(this.get(optionName)); - } -}; - -/** - * @returns {Object} Хеш опций - */ -OptionsManager.prototype.getOptions = function() { - return this._options; -}; - var ppVersion; chrome.runtime.sendMessage(null, { diff --git a/chrome_point_plus/manifest.json b/chrome_point_plus/manifest.json index aed0994..8030e2c 100644 --- a/chrome_point_plus/manifest.json +++ b/chrome_point_plus/manifest.json @@ -30,7 +30,9 @@ "vendor/jquery/jquery.min.js", "js/bquery_ajax.js", - + + "js/options-manager.js", + "js/point-plus.js" ], "css": [