| 1 | 1 |
new file mode 100755 |
| ... | ... |
@@ -0,0 +1,39 @@ |
| 1 |
+'use strict'; |
|
| 2 |
+ |
|
| 3 |
+var minified = require('./vendor/minified');
|
|
| 4 |
+var ClayConfig = require('./lib/clay-config');
|
|
| 5 |
+ |
|
| 6 |
+var $ = minified.$; |
|
| 7 |
+var _ = minified._; |
|
| 8 |
+ |
|
| 9 |
+var config = _.extend([], window.clayConfig || []); |
|
| 10 |
+var settings = _.extend({}, window.claySettings || {});
|
|
| 11 |
+var returnTo = window.returnTo || 'pebblejs://close#'; |
|
| 12 |
+var customFn = window.customFn || function() {};
|
|
| 13 |
+var clayComponents = window.clayComponents || {};
|
|
| 14 |
+var clayMeta = window.clayMeta || {};
|
|
| 15 |
+ |
|
| 16 |
+var platform = window.navigator.userAgent.match(/android/i) ? 'android' : 'ios'; |
|
| 17 |
+document.documentElement.classList.add('platform-' + platform);
|
|
| 18 |
+ |
|
| 19 |
+// Register the passed components |
|
| 20 |
+_.eachObj(clayComponents, function(key, component) {
|
|
| 21 |
+ ClayConfig.registerComponent(component); |
|
| 22 |
+}); |
|
| 23 |
+ |
|
| 24 |
+var $mainForm = $('#main-form');
|
|
| 25 |
+var clayConfig = new ClayConfig(settings, config, $mainForm, clayMeta); |
|
| 26 |
+ |
|
| 27 |
+// add listeners here |
|
| 28 |
+$mainForm.on('submit', function() {
|
|
| 29 |
+ // Set the return URL depending on the runtime environment |
|
| 30 |
+ location.href = returnTo + |
|
| 31 |
+ encodeURIComponent(JSON.stringify(clayConfig.serialize())); |
|
| 32 |
+}); |
|
| 33 |
+ |
|
| 34 |
+// Run the custom function in the context of the ClayConfig |
|
| 35 |
+customFn.call(clayConfig, minified); |
|
| 36 |
+ |
|
| 37 |
+// Now that we have given the dev's custom code to run and attach listeners, |
|
| 38 |
+// we build the config |
|
| 39 |
+clayConfig.build(); |