Permalink
Browse files

refactor for cleanness

  • Loading branch information...
1 parent 6760630 commit f8c789b047d52a8041927eadcf6ee7579676aac7 @dtudury committed Jul 5, 2011
View
@@ -10,13 +10,17 @@
<script language="javascript" src="js/utils/deepPrint.js"></script>
<script language="javascript" src="js/cryptopotamus/Model.js"></script>
<script language="javascript" src="js/cryptopotamus/View.js"></script>
+ <script language="javascript" src="js/cryptopotamus/view/Base.js"></script>
+ <script language="javascript" src="js/cryptopotamus/view/Text.js"></script>
+ <script language="javascript" src="js/cryptopotamus/view/TextInputPrompted.js"></script>
+ <script language="javascript" src="js/cryptopotamus/view/PasswordInputPrompted.js"></script>
<script language="javascript" src="js/cryptopotamus/view/Div.js"></script>
<script language="javascript" src="js/cryptopotamus/view/FancyDiv.js"></script>
<script language="javascript" src="js/cryptopotamus/view/FancierDiv.js"></script>
<script language="javascript" src="js/cryptopotamus/Controller.js"></script>
<script language="javascript" src="js/cryptopotamus/handle_onload.js"></script>
</head>
- <body onload="IMPORT_FUNCTION( 'cryptopotamus.handle_onload')()">
+ <body onload="IMPORT( 'cryptopotamus.handle_onload')()">
<div id="content"></div>
</body>
</html>
View
@@ -4,66 +4,68 @@
*****************************************************************************/
(function() {
-
- var _name_space = {};
- var _packaged_functions = {};
-
var global = ( function(){ return this;}).call();
+ var _name_space = {};
- /*****************************************************************************
- *
- *****************************************************************************/
- global.PACKAGE_FUNCTION = function( qualified_name, in_function) {
- _packaged_functions[ qualified_name] = in_function;
- };
-
- global.IMPORT_FUNCTION = function( qualified_name) {
- if( !_name_space[ qualified_name]) {
+ var is_initializing = false;
+ function initialize( in_constructor) {
+ var was_initializing = is_initializing;
+ is_initializing = true;
+ var instance = new in_constructor();
+ is_initializing = was_initializing;
+ return instance;
+ }
+ global.CLASS = function( in_name) {
+ if( !_name_space[ in_name]) {
var _class = function() {
- return _packaged_functions[ qualified_name].apply( this, [].slice.call( arguments));
+ if( _class.function_only) return _class.mixins[ 0].apply( this, [].slice.call( arguments));
+ if( this.super_constructor) this.SUPER = initialize( this.super_constructor);
+ for( var i = 0; i < _class.mixins.length; i++) _class.mixins[ i].call( this);
+ if( this.constructor != _class) this.CONSTRUCTOR = this.constructor;
+ if( !is_initializing && this.CONSTRUCTOR) {
+ this.CONSTRUCTOR.apply( this, [].slice.call( arguments));
+ }
};
- _name_space[ qualified_name] = _class;
- }
- return _name_space[ qualified_name];
- };
-
-
- /*****************************************************************************
- *
- *****************************************************************************/
- global.IMPORT = function( qualified_name) {
- if( !_name_space[ qualified_name]) {
- var _class = function() {
- if( !_class.prototype.super_class) {
- var temp_prototype = new _class.super_class();
- for( var name in temp_prototype) _class.prototype[ name] = temp_prototype[ name];
- _class.prototype.constructor = _class;
- _class.prototype.super_class = _class.super_class.prototype;
- if( _class.instance_definition) _class.instance_definition( _class.prototype);
+ _class.mixins = [];
+ _class.uninitialized = false;
+ _class.EXTENDS = function( in_super_name){
+ _class.super_name = in_super_name;
+ _class.uninitialized = true;
+ return _class;
+ };
+ _class.DEFINITION = function( in_function){
+ _class.mixins.push( in_function);
+ return _class;
+ };
+ _class.STATIC = function( in_definition) {
+ var temp_instance = new in_definition();
+ for( var member in temp_instance) {
+ _class[ member] = temp_instance[ member];
+ if( _class[ member] instanceof Function) {
+ FUNCTION( in_name + "." + member).DEFINITION( _class[ member]);
+ }
}
- if( _class.prototype.constructor == _class) _class.prototype.constructor = _class.super_class.prototype.constructor;
- if( _class.prototype.constructor) _class.prototype.constructor.apply( _class.prototype, [].slice.call( arguments));
+ return _class;
};
- _class.define_instance = function( in_definition) { _class.instance_definition = in_definition; return _class;};
- _class.define_static = function( in_definition) { if( in_definition) in_definition( _class); return _class;};
- _name_space[ qualified_name] = _class;
+ _name_space[ in_name] = _class;
}
- return _name_space[ qualified_name];
+ return _name_space[ in_name];
};
-
- /*****************************************************************************
- *
- *****************************************************************************/
- global.PACKAGE = function( qualified_name, super_class, instance_definition, static_definition) {
- if( !super_class) super_class = function() {};
-
- var _class = IMPORT( qualified_name);
- _class.qualified_name = qualified_name;
- _class.super_class = super_class;
- _class.define_instance( instance_definition);
- _class.define_static( static_definition);
- _name_space[ qualified_name] = _class;
- return _class;
+ global.FUNCTION = function( in_name) {
+ var wrapper_class = CLASS( in_name);
+ wrapper_class.function_only = true;
+ return wrapper_class;
+ };
+ global.IMPORT = function( in_name) {
+ var wrapper_class = CLASS( in_name);
+ if( wrapper_class.uninitialized) {
+ var super_class = CLASS( wrapper_class.super_name);
+ wrapper_class.prototype = initialize( super_class);
+ wrapper_class.prototype.constructor = wrapper_class;
+ wrapper_class.prototype.super_constructor = super_class;
+ wrapper_class.uninitialized = false;
+ }
+ return wrapper_class;
};
-
+
})();
@@ -1,15 +1,16 @@
-PACKAGE( "cryptopotamus.Controller").define_static( function( _) {
+CLASS( "cryptopotamus.Controller")
+.STATIC( function() {
var model = IMPORT( "cryptopotamus.Model");
- _.update_salt = function( in_event) {
+ this.update_salt = function( in_event) {
var _event = window.event || in_event;
if (!_event.target) _event.target = _event.srcElement;
model.set_salt( _event.target.value);
};
- _.generate_all = function( in_event) {
+ this.generate_all = function( in_event) {
window.alert( "generate based on " + model.get_salt());
};
View
@@ -1,18 +1,19 @@
-PACKAGE( "cryptopotamus.Model").define_static( function( _) {
+CLASS( "cryptopotamus.Model")
+.STATIC( function() {
var PubSub = IMPORT( "utils.PubSub");
- _.publisher = new PubSub();
+ this.publisher = new PubSub();
- _.NEW_SALT = "newsalt";
+ this.NEW_SALT = "newsalt";
var _salt;
- _.set_salt = function( salt) {
+ this.set_salt = function( salt) {
if( _salt == salt) return;
_salt = salt;
- _.publisher.sendMessage( _.NEW_SALT);
+ this.publisher.sendMessage( this.NEW_SALT);
};
- _.get_salt = function() { return _salt;};
+ this.get_salt = function() { return _salt;};
var _configs = [];
});
View
@@ -1,17 +1,18 @@
-PACKAGE( "cryptopotamus.View").define_static( function( _) {
+CLASS( "cryptopotamus.View")
+.STATIC( function() {
var controller = IMPORT( "cryptopotamus.Controller");
- var configure = IMPORT_FUNCTION( "utils.configure");
+ var configure = IMPORT( "utils.configure");
- _.new_top_nav = function() {
- var div = _.new_div();
- div.appendChild( _.new_text( "salt: "));
- div.appendChild( _.new_password_input( controller.update_salt));
- div.appendChild( _.new_button_input( controller.generate_all, "generate all"));
+ this.new_top_nav = function() {
+ var div = this.new_div();
+ div.appendChild( this.new_text( "salt: "));
+ div.appendChild( this.new_password_input( controller.update_salt));
+ div.appendChild( this.new_button_input( controller.generate_all, "generate all"));
return div;
};
- _.new_text_input = function( value, size) {
+ this.new_text_input = function( value, size) {
var input = document.createElement( "input");
var _defaults = { value: "text here", size: 20};
var _no_prompt = { onfocus: null, onblur: null};
@@ -27,7 +28,7 @@ PACKAGE( "cryptopotamus.View").define_static( function( _) {
configure( configuration, _prompt);
return configure( input, configuration, _defaults);
};
- _.new_button_input = function( onclick, value) {
+ this.new_button_input = function( onclick, value) {
var input = document.createElement( "input");
var configuration = { type: "button", value: value, onclick: onclick};
return configure( input, configuration);
@@ -59,13 +60,13 @@ PACKAGE( "cryptopotamus.View").define_static( function( _) {
};
return configure( input, configuration);
};
- _.new_password_input = function( onchange, size) {
+ this.new_password_input = function( onchange, size) {
return _new_password_input_prompt();
};
- _.new_div = function() {
+ this.new_div = function() {
return document.createElement( "div");
};
- _.new_text = function( text) {
+ this.new_text = function( text) {
return document.createTextNode( text);
};
});
Oops, something went wrong.

0 comments on commit f8c789b

Please sign in to comment.