diff --git a/gulpfile.js b/gulpfile.js index a51a25d..6409b2f 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -16,7 +16,7 @@ gulp.task('clean', function(done) { }); gulp.task('browserify', ['clean'], function(done) { - return browserify('src/scripts/config-page.js', { debug: true }) + return browserify('src/scripts/config-page.js', { debug: false }) .transform(stringify(['.html', '.mustache'])) .bundle() .pipe(source('config-page.js')) diff --git a/index.js b/index.js index 7c7a202..885f275 100644 --- a/index.js +++ b/index.js @@ -51,20 +51,22 @@ function encodeDataUri(input) { return 'data:text/html;base64,' + encodeURIComponent(out.join('')); } -function Clay(config) { +/** + * @param {array} config - the Clay config + * @param {function} [customFn] - custom code to run from the config page. + * Will run with api as context + * @constructor + */ +function Clay(config, customFn) { this.config = config; - /** - * @type {{}} - * @private - */ - this._defaults = {}; + this.customFn = customFn || function() {}; } /** * Generate the Data URI used by the config Page with settings injected - * @param {string} clayData - the entire HTML page as a data URI + * @param {string} returnTo - used while developing on desktop. */ -Clay.prototype.generateUrl = function() { +Clay.prototype.generateUrl = function(returnTo) { var settings; try { settings = JSON.parse(localStorage.getItem('clay-settings')) || {}; @@ -74,6 +76,8 @@ Clay.prototype.generateUrl = function() { } // Show config page return encodeDataUri(configPageHtml + .replace('$$CUSTOM_FN$$', this.customFn.toString().replace(/^.*?\{/, '{')) + .replace('$$RETURN_TO$$', returnTo || 'pebblejs://close#') .replace('$$CONFIG$$', JSON.stringify(this.config)) .replace('$$SETTINGS$$', JSON.stringify(settings)) ); @@ -86,10 +90,7 @@ Clay.prototype.getSettings = function(response) { if (!settings) return {}; localStorage.setItem('clay-settings', JSON.stringify(settings)); -}; - -Clay.prototype.getDefaults = function() { - return this._defaults; + return settings; }; module.exports = Clay; diff --git a/src/config-page.html b/src/config-page.html index 79804ad..2419edd 100644 --- a/src/config-page.html +++ b/src/config-page.html @@ -6,13 +6,15 @@
- +