| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- /**
- * @fileoverview
- * Trex 정의
- */
- /** @namespace */
- var Trex = {
- __WORD_JOINER: "\ufeff",
- __WORD_JOINER_REGEXP: /\ufeff/g,
- __KEY: {
- ENTER: '13',
- DELETE: '46',
- SPACE: '32',
- BACKSPACE: '8',
- TAB: '9',
- PASTE: '86', //+ ctrl
- CUT: '88' //+ ctrl
- },
- I: {},
- X: {},
- define: function(destination, properties) {
- return Object.extend(destination, properties);
- },
- available: function(config, name) {
- if(!$tx("tx_" + name)){
- //console.log("Warning: JsObject is existed but element 'tx_" + name + "' is not found.");
- return _FALSE;
- }
- if(!config){
- //console.log("Warning: no config for" + name);
- return _FALSE;
- }
- if(config.use == _FALSE) {
- //console.log("Warning: config.use == _FALSE");
- return _FALSE;
- }
- return _TRUE;
- }
- };
- //oop
- (function(Trex){
- function $$reference($instance) {
- var _$ref = $instance;
- while(_$ref.$reference) {
- _$ref = _$ref.$reference;
- }
- return _$ref;
- }
-
- function $$super($instance) {
- var _$superclass = $instance.constructor.superclass;
- if(_$superclass) {
- var _$initbak = _$superclass.prototype.initialize;
- _$superclass.prototype.initialize = function() {
- this.$reference = $instance;
- }; //fake initialize
- var _$superobj = new _$superclass();
- _$superclass.prototype.initialize = _$initbak;
-
- var _wrapFunc = function(name) {
- if(!_$superobj[name]) return _NULL;
- return function() {
- var _arguments = arguments;
- var _$reference = $$reference($instance);
- var _$superbak = _$reference.$super;
- _$reference.$super = _$superobj.$super;
- var _returns = _$superobj[name].apply(_$reference, _arguments);
- _$reference.$super = _$superbak;
- return _returns;
- };
- };
-
- var _$wrapobj = {};
- for(var _name in _$superobj) {
- if(_name.charAt(0) != '$') {
- if (typeof(_$superobj[_name]) == 'function') {
- _$wrapobj[_name] = _wrapFunc(_name);
- }
- }
- }
- $instance.$super = _$wrapobj;
- }
- }
-
- /**
- * @namespace
- * @name Trex.Class
- */
- Trex.Class = /** @lends Trex.Class */ {
- /**
- * creates class
- * @param {Object} properties
- */
- create: function(properties) {
- var _class = function() {
- var _proto = this.constructor.prototype; //NOTE: Cuz properties must not share
- for(var _name in _proto) {
- if(_proto[_name] && typeof(_proto[_name]) === 'object') {
- if(_proto[_name].constructor == Array) { //Array
- this[_name] = [].concat(_proto[_name]);
- } else {
- this[_name] = Object.extend({}, _proto[_name]);
- }
- }
- }
- $$super(this);
- var _arguments = arguments;
- this.initialize.apply(this, _arguments);
- };
- return Trex.Class.draft(properties, _class);
- },
- draft: function(properties, aClass) {
- var _class = aClass ?
- aClass :
- function() {
- $$super(this);
- };
-
- if(properties.$const) {
- Object.extend(_class, properties.$const);
- }
-
- if(properties.$extend) {
- Object.extend(_class.prototype, properties.$extend.prototype);
- _class.superclass = properties.$extend;
- }
-
- if(properties.$mixins) {
- var sources = $A(properties.$mixins);
- sources.each(function(source) {
- Object.extend(_class.prototype, source);
- });
- }
- for(var _name in properties) {
- if(_name.charAt(0) != '$') {
- _class.prototype[_name] = properties[_name];
- }
- }
- return _class;
- },
- overwrite: function(source, properties) {
- if(source.prototype) {
- Object.extend(source.prototype, properties);
- }
- return source;
- }
- };
-
- /**
- * @namespace
- * @name Trex.Faculty, Trex.Mixin
- */
- Trex.Mixin = Trex.Faculty = /** @lends Trex.Mixin */ {
- /**
- * Creates
- * @param {Object} properties
- */
- create: function(properties) {
- var _class = {};
- for(var _name in properties) {
- if(properties[_name] && typeof(properties[_name]) === 'object') {
- if(properties[_name].constructor == Array) { //Array
- _class[_name] = [].concat(properties[_name]);
- } else {
- _class[_name] = Object.extend({}, properties[_name]);
- }
- } else {
- _class[_name] = properties[_name];
- }
- }
- return _class;
- },
- toClass: function(properties, initializeFunc) {
- return Trex.Class.create(
- Object.extend({
- initialize: initializeFunc? initializeFunc: function() {}
- }, properties)
- );
- }
- };
- })(Trex);
- //module
- (function(Trex){
- Object.extend(Trex, /** @lends Trex */ {
- installs: [],
- registers: [],
- modules: [],
- modulesX: [],
- /**
- * Installs component
- * @param {Object} description
- * @param {Object} fn
- */
- install: function(description, fn){
- fn.desc = '[install] ' + description;
- Trex.installs.push(fn);
- },
- register: function(description, fn){
- fn.desc = '[register] ' + description;
- Trex.registers.push(fn);
- },
- module: function(description, fn){
- //console.log(' >>> ' + description);
- fn.desc = '[module] ' + description;
- Trex.modules.push(fn);
- },
- moduleX: function(description, fn){
- fn.desc = '[moduleX] ' + description;
- Trex.modulesX.push(fn);
- },
- invoke: function(fns, editor, toolbar, sidebar, canvas, config){
- for(var i=0,len=fns.length; i<len; i++){
- var fn = fns[i];
- fn(editor, toolbar, sidebar, canvas, config);
- }
- },
- invokeInstallation: function(editor, toolbar, sidebar, canvas, config){
- Trex.invoke(Trex.installs, editor, toolbar, sidebar, canvas, config);
- },
- invokeRegisters: function(editor, toolbar, sidebar, canvas, config){
- Trex.invoke(Trex.registers, editor, toolbar, sidebar, canvas, config);
- },
- invokeModules: function(editor, toolbar, sidebar, canvas, config){
- Trex.invoke(Trex.modules, editor, toolbar, sidebar, canvas, config);
- },
- group: function(){},
- groupEnd: function(){}
- });
- })(Trex);
- _WIN.Trex = Trex;
|