mirror of
https://github.com/pebble-dev/clay.git
synced 2026-08-28 04:46:57 -04:00
WIP - no love for minified.js anymore :(
This commit is contained in:
+11
-10
@@ -5,17 +5,18 @@ module.exports = function() {
|
|||||||
/** @type {ClayConfig} */
|
/** @type {ClayConfig} */
|
||||||
var Clay = window.Clay = this;
|
var Clay = window.Clay = this;
|
||||||
|
|
||||||
Clay.getItemByAppKey('cool_stuff').on('change', function() {
|
Clay.on(Clay.EVENTS.BEFORE_BUILD, function() {
|
||||||
if (this.get()) {
|
console.debug('KEEGAN: BEFORE_BUILD', this);
|
||||||
Clay.getItemByAppKey('background').enable();
|
|
||||||
} else {
|
|
||||||
Clay.getItemByAppKey('background').disable();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Clay.on('test', function() {
|
Clay.on(Clay.EVENTS.AFTER_BUILD, function() {
|
||||||
console.debug('KEEGAN: this', this);
|
console.debug('KEEGAN: AFTER_BUILD', this);
|
||||||
|
Clay.getItemByAppKey('cool_stuff').on('change', function() {
|
||||||
|
if (this.get()) {
|
||||||
|
Clay.getItemByAppKey('background').enable();
|
||||||
|
} else {
|
||||||
|
Clay.getItemByAppKey('background').disable();
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
Clay.trigger('test');
|
|
||||||
};
|
};
|
||||||
|
|||||||
+1
-1
@@ -5,5 +5,5 @@ window.clayConfig = require('./config.js');
|
|||||||
window.claySettings = {};
|
window.claySettings = {};
|
||||||
window.customFn = require('./custom-fn.js');
|
window.customFn = require('./custom-fn.js');
|
||||||
|
|
||||||
var platform = window.navigator.userAgent.match('Android') ? 'android' : 'ios';
|
var platform = window.navigator.userAgent.match(/Android/) ? 'android' : 'ios';
|
||||||
document.documentElement.classList.add('platform-' + platform);
|
document.documentElement.classList.add('platform-' + platform);
|
||||||
|
|||||||
@@ -12,14 +12,26 @@ var customFn = window.customFn || function() {};
|
|||||||
var $mainForm = $('#main-form');
|
var $mainForm = $('#main-form');
|
||||||
var clayConfig = new ClayConfig(settings, config, $mainForm);
|
var clayConfig = new ClayConfig(settings, config, $mainForm);
|
||||||
|
|
||||||
function submit(event) {
|
clayConfig.on(clayConfig.EVENTS.BEFORE_BUILD, function() {
|
||||||
// Set the return URL depending on the runtime environment
|
// attach components here
|
||||||
location.href =
|
});
|
||||||
returnTo + encodeURIComponent(JSON.stringify(clayConfig.getSettings()));
|
|
||||||
event.preventDefault();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$mainForm.on('|submit', submit);
|
clayConfig.on(clayConfig.EVENTS.AFTER_BUILD, function() {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
// add listeners here
|
||||||
|
$mainForm.on('|submit', function(event) {
|
||||||
|
// Set the return URL depending on the runtime environment
|
||||||
|
location.href =
|
||||||
|
returnTo + encodeURIComponent(JSON.stringify(self.getSettings()));
|
||||||
|
event.preventDefault();
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Run the custom function in the context of the ClayConfig
|
||||||
customFn.call(clayConfig);
|
customFn.call(clayConfig);
|
||||||
|
|
||||||
|
// Now that we have given the dev's custom code to run and attach listeners,
|
||||||
|
// we build the config
|
||||||
|
clayConfig.build();
|
||||||
|
|||||||
@@ -29,11 +29,30 @@ var ClayEvents = require('./clay-events');
|
|||||||
function ClayConfig(settings, config, $rootContainer) {
|
function ClayConfig(settings, config, $rootContainer) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
self.test = Math.random();
|
||||||
|
|
||||||
var _settings = _.copyObj(settings);
|
var _settings = _.copyObj(settings);
|
||||||
var _items = [];
|
var _items = [];
|
||||||
var _itemsById = {};
|
var _itemsById = {};
|
||||||
var _itemsByAppKey = {};
|
var _itemsByAppKey = {};
|
||||||
|
|
||||||
|
self.EVENTS = {
|
||||||
|
/**
|
||||||
|
* Called before framework has initialized. This is when you would attach your
|
||||||
|
* custom items.
|
||||||
|
* @const
|
||||||
|
*/
|
||||||
|
BEFORE_BUILD: 'BEFORE_BUILD',
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called after the config has been parsed and all items have their initial value
|
||||||
|
* set
|
||||||
|
* @const
|
||||||
|
*/
|
||||||
|
AFTER_BUILD: 'AFTER_BUILD'
|
||||||
|
};
|
||||||
|
utils.updateProperties(self.EVENTS, {writable: false});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} key
|
* @param {string} key
|
||||||
* @returns {ClayItem}
|
* @returns {ClayItem}
|
||||||
@@ -73,6 +92,13 @@ function ClayConfig(settings, config, $rootContainer) {
|
|||||||
// attach event methods
|
// attach event methods
|
||||||
ClayEvents.call(self, $rootContainer);
|
ClayEvents.call(self, $rootContainer);
|
||||||
|
|
||||||
|
self.build = function() {
|
||||||
|
self.trigger(self.EVENTS.BEFORE_BUILD);
|
||||||
|
// initialize the config
|
||||||
|
_addItems(config, $rootContainer);
|
||||||
|
self.trigger(self.EVENTS.AFTER_BUILD);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add item(s) to the config
|
* Add item(s) to the config
|
||||||
* @param {Clay~ConfigItem|array} items
|
* @param {Clay~ConfigItem|array} items
|
||||||
@@ -114,8 +140,6 @@ function ClayConfig(settings, config, $rootContainer) {
|
|||||||
// prevent external modifications of properties
|
// prevent external modifications of properties
|
||||||
utils.updateProperties(self, { writable: false, configurable: false });
|
utils.updateProperties(self, { writable: false, configurable: false });
|
||||||
|
|
||||||
// initialize the config
|
|
||||||
_addItems(config, $rootContainer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = ClayConfig;
|
module.exports = ClayConfig;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ var $ = require('../vendor/minified/minified').$;
|
|||||||
/**
|
/**
|
||||||
* Attaches event methods to the context.
|
* Attaches event methods to the context.
|
||||||
* Call with ClayEvents.call(yourObject, $eventTarget)
|
* Call with ClayEvents.call(yourObject, $eventTarget)
|
||||||
* @param {EventEmitter} $eventTarget - An object that will be used as the event
|
* @param {EventEmitter|M} $eventTarget - An object that will be used as the event
|
||||||
* target. Must implement EventEmitter
|
* target. Must implement EventEmitter
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
@@ -70,7 +70,7 @@ function ClayEvents($eventTarget) {
|
|||||||
* @returns {object}
|
* @returns {object}
|
||||||
*/
|
*/
|
||||||
self.trigger = function(name, eventObj) {
|
self.trigger = function(name, eventObj) {
|
||||||
$eventTarget.trigger(name, eventObj);
|
$eventTarget.trigger(name);
|
||||||
return self;
|
return self;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,9 +59,9 @@ describe('ClayItem', function() {
|
|||||||
assert.strictEqual(clayItem.appKey, config.appKey);
|
assert.strictEqual(clayItem.appKey, config.appKey);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('.$manipulatorTarget', function() {
|
describe('.$manipulatorTarget', function() {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -27,5 +27,3 @@ describe('Utils', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user