Permalink
Browse files

minor improvements

  • Loading branch information...
1 parent 528d9e5 commit d4249acc6c4c0714718e6c1b1cb7d898d1624b4f unknown committed Jul 19, 2011
View
@@ -3,24 +3,31 @@
<head>
<meta charset=utf-8 />
<title>local cryptopotamus</title>
+ <script language="javascript" src="js/LOGGER.js"></script>
<script language="javascript" src="js/CORE.js"></script>
<script language="javascript" src="js/utils/Closure.js"></script>
<script language="javascript" src="js/utils/PubSub.js"></script>
<script language="javascript" src="js/utils/configure.js"></script>
<script language="javascript" src="js/utils/deepPrint.js"></script>
<script language="javascript" src="js/cryptopotamus/Model.js"></script>
+ <script language="javascript" src="js/cryptopotamus/model/Generator.js"></script>
<script language="javascript" src="js/cryptopotamus/View.js"></script>
+ <script language="javascript" src="js/cryptopotamus/Controller.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/GlobalPassword.js"></script>
+ <script language="javascript" src="js/cryptopotamus/view/Button.js"></script>
+ <script language="javascript" src="js/cryptopotamus/view/GenerateAllButton.js"></script>
+ <script language="javascript" src="js/cryptopotamus/view/TopNav.js"></script>
+ <script language="javascript" src="js/cryptopotamus/view/GeneratorList.js"></script>
+ <script language="javascript" src="js/cryptopotamus/view/NewGeneratorButton.js"></script>
+ <script language="javascript" src="js/cryptopotamus/view/Generator.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/view/FancierDiv.js"></script -->
<script language="javascript" src="js/cryptopotamus/handle_onload.js"></script>
</head>
- <body onload="IMPORT( 'cryptopotamus.handle_onload')()">
- <div id="content"></div>
- </body>
-</html>
+ <body onload="IMPORT( 'cryptopotamus.handle_onload')()"></body>
+</html>
View
@@ -4,68 +4,93 @@
*****************************************************************************/
(function() {
+
+ //get global namespace so we can call CLASS, IMPORT, and FUNCTION
var global = ( function(){ return this;}).call();
+
+ //name space for storing constructors and static functions
var _name_space = {};
- 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;
- }
+ //method to create class(like) defining functionality
global.CLASS = function( in_name) {
if( !_name_space[ in_name]) {
+ //setup our class; it relies heavily on things to be set up later, but in case it's imported
+ //before it's setup, return a pointer to where it will be
var _class = function() {
- 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));
+ //we store static functions here too, if this is one, return it (well, a wrapped version)
+ if( _class.function_only) return _class.MIXINS[ 0].apply( this, [].slice.call( arguments));
+ //pointer to the super class so our instance can access it
+ this.SUPER = _class.prototype;
+ //for debugging
+ this.NAME = in_name;
+ //build our class by applying our mixins
+ for( var i = 0; i < _class.MIXINS.length; i++) _class.MIXINS[ i].call( this);
+ //if one of our mixins defined a "constructor" method, then let it handle any arguments
+ if( !is_initializing && this.constructor != _class) {
+ this.constructor.apply( this, [].slice.call( arguments));
}
};
- _class.mixins = [];
- _class.uninitialized = false;
- _class.EXTENDS = function( in_super_name){
- _class.super_name = in_super_name;
- _class.uninitialized = true;
+ //functions that define our methods and members
+ _class.MIXINS = [];
+ //add a mixin
+ _class.DEFINITION = function( in_function){
+ _class.MIXINS.push( in_function);
return _class;
};
- _class.DEFINITION = function( in_function){
- _class.mixins.push( in_function);
+ //the class we'll inherit from (and set prototype to)
+ _class.EXTENDS = function( in_super_name){
+ //set super_name until we add a prototype
+ _class.SUPER_NAME = in_super_name;
return _class;
};
+ //execute any functions that will define static methods and members
_class.STATIC = function( in_definition) {
var temp_instance = new in_definition();
for( var member in temp_instance) {
_class[ member] = temp_instance[ member];
+ //break out any static functions so they can be grabbed on their own
if( _class[ member] instanceof Function) {
FUNCTION( in_name + "." + member).DEFINITION( _class[ member]);
}
}
return _class;
};
+ //store it for later
_name_space[ in_name] = _class;
}
return _name_space[ in_name];
};
+
+ //store static package method
global.FUNCTION = function( in_name) {
- var wrapper_class = CLASS( in_name);
- wrapper_class.function_only = true;
- return wrapper_class;
+ var _class = CLASS( in_name);
+ _class.function_only = true;
+ return _class;
};
+
+ //look up static or constructor method
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;
+ var _class = CLASS( in_name);
+ //apply inheritance by setting prototype to an instance of the super-class
+ if( _class.SUPER_NAME) {
+ var super_class = IMPORT( _class.SUPER_NAME);
+ _class.prototype = initialize( super_class);
+ //we don't need this anymore and don't do this twice
+ _class.SUPER_NAME = null;
}
- return wrapper_class;
+ return _class;
};
-})();
+ //helper method to construct classes for linking without initializing them
+ function initialize( in_constructor) {
+ //console.log( "initializing " + in_constructor.prototype.name);
+ var was_initializing = is_initializing;
+ is_initializing = true;
+ var instance = new in_constructor();
+ is_initializing = was_initializing;
+ return instance;
+ }
+ //if we're initializing then classes are only being constructed for linking
+ var is_initializing = false;
+
+})();
@@ -2,16 +2,21 @@
CLASS( "cryptopotamus.Controller")
.STATIC( function() {
- var model = IMPORT( "cryptopotamus.Model");
+ var Model = IMPORT( "cryptopotamus.Model");
- 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);
+ this.update_salt = function( in_salt) {
+ LOG( "cryptopotamus.Controller.update_salt " + in_salt);
};
-
- this.generate_all = function( in_event) {
- window.alert( "generate based on " + model.get_salt());
+ this.generate_all = function() {
+ LOG( "cryptopotamus.Controller.generate_all");
+ };
+ this.add_generator = function() {
+ LOG( "cryptopotamus.Controller.add_generator");
+ Model.add_new_generator();
};
+ this.remove_generator = function( in_index) {
+ LOG( "cryptopotamus.Controller.remove_generator " + in_index);
+ Model.remove_generator( in_index);
+ }
-});
+});
View
@@ -3,10 +3,14 @@ CLASS( "cryptopotamus.Model")
.STATIC( function() {
var PubSub = IMPORT( "utils.PubSub");
+ var Generator = IMPORT( "cryptopotamus.model.Generator");
this.publisher = new PubSub();
this.NEW_SALT = "newsalt";
+ this.INSERTION = "insertion";
+ this.INSERTION = "deletion";
+
var _salt;
this.set_salt = function( salt) {
if( _salt == salt) return;
@@ -15,5 +19,19 @@ CLASS( "cryptopotamus.Model")
};
this.get_salt = function() { return _salt;};
- var _configs = [];
-});
+ var _generators = [];
+ this.add_new_generator = function( in_index) {
+ if( in_index === undefined) {
+ in_index = _generators.length;
+ }
+ _generators.splice( in_index, 0, new Generator());
+ this.publisher.sendMessage( this.INSERTION, in_index);
+ };
+ this.remove_generator = function( in_index) {
+ _generators.splice( in_index, 1);
+ this.publisher.sendMessage( this.DELETION, in_index);
+ };
+ this.get_generator_count = function() {
+ return _generators.length;
+ };
+});
Oops, something went wrong.

0 comments on commit d4249ac

Please sign in to comment.