94 lines
2.6 KiB
JavaScript
94 lines
2.6 KiB
JavaScript
|
/*globals React */
|
||
|
|
||
|
/**
|
||
|
* init.js
|
||
|
*
|
||
|
* Initialize app global
|
||
|
*/
|
||
|
|
||
|
(function () {
|
||
|
'use strict';
|
||
|
|
||
|
var App = window.App = {};
|
||
|
|
||
|
// move module methods out of the global namespace to
|
||
|
// prevent libraries like jQuery from creating AMD modules
|
||
|
if (window.module !== undefined) {
|
||
|
window.atom = {
|
||
|
require: window.require,
|
||
|
module: window.module
|
||
|
};
|
||
|
|
||
|
delete window.require;
|
||
|
delete window.module;
|
||
|
}
|
||
|
|
||
|
// components creation
|
||
|
App.components = {
|
||
|
/**
|
||
|
* Add React class to given namespace
|
||
|
*
|
||
|
* @param {namespace: string} Class namespace, skip to assign to global namespace
|
||
|
* @param {options: Object} Class options
|
||
|
* @return {Object} Object containing namespace object and created class
|
||
|
*/
|
||
|
create: function (namespace, options) {
|
||
|
var cclass;
|
||
|
|
||
|
if (typeof namespace === 'object') {
|
||
|
options = namespace;
|
||
|
namespace = App.components;
|
||
|
} else {
|
||
|
if (App.components[namespace] === undefined) {
|
||
|
App.components[namespace] = {};
|
||
|
}
|
||
|
|
||
|
namespace = App.components[namespace];
|
||
|
}
|
||
|
|
||
|
cclass = React.createClass(options);
|
||
|
namespace[options.displayName] = cclass;
|
||
|
|
||
|
return {
|
||
|
namespace: namespace,
|
||
|
cclass: cclass
|
||
|
};
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* Add Modal class to given namespace
|
||
|
*
|
||
|
* @param {namespace: string} Class namespace, skip to assign to global namespace
|
||
|
* @param {options: Object} Class options
|
||
|
* @return {Object} Object containing namespace object and created modal
|
||
|
*/
|
||
|
modal: function (namespace, options) {
|
||
|
var component, cclass, modal;
|
||
|
|
||
|
if (options === undefined) {
|
||
|
options = namespace;
|
||
|
}
|
||
|
|
||
|
modal = options.modal || {};
|
||
|
delete options.modal;
|
||
|
|
||
|
component = App.components.create(namespace, options);
|
||
|
cclass = function (props) {
|
||
|
return new App.Modal(component.cclass, modal, props);
|
||
|
};
|
||
|
|
||
|
component.namespace[options.displayName] = cclass;
|
||
|
|
||
|
return {
|
||
|
namespace: component.namespace,
|
||
|
cclass: cclass
|
||
|
};
|
||
|
}
|
||
|
};
|
||
|
|
||
|
// other globals
|
||
|
App.lang = navigator.language;
|
||
|
App.MIDI = {
|
||
|
keyOffset: 21
|
||
|
};
|
||
|
}());
|