js2 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Changelog CHANGED
@@ -1,7 +1,5 @@
1
- == 0.0.4 2009-12-02
2
- * Adding JS2.createClass() and JS2.getClass()
3
- * Deprecating classes.js file in favor of js2bootstrap.js
4
- * Adding super function
1
+ == 0.0.5 2009-12-04
2
+ * added bootstrap
5
3
 
6
4
  == 0.0.3 2009-11-30
7
5
  * Selenium test bug fixes
data/Manifest.txt CHANGED
@@ -10,6 +10,8 @@ Rakefile
10
10
  examples/js2.yml
11
11
  examples/test.yml
12
12
  lib/javascript/sel_marker.js2
13
+ lib/javascript/bootstrap.js
14
+ lib/javascript/observer.js2
13
15
  lib/javascript/test.js2
14
16
  lib/js2.rb
15
17
  lib/js2/ast/class_node.rb
@@ -43,3 +45,4 @@ meta/c_tokenizer.rl.erb
43
45
  meta/replace.rb
44
46
  bin/js2
45
47
  website/index.txt
48
+
@@ -0,0 +1,42 @@
1
+ var JS2 = {};
2
+ JS2.createClass = function (name) {
3
+ var splitName = name.split('.');
4
+ var namespace = window;
5
+ while (splitName.length) {
6
+ var subName = splitName.shift();
7
+ if (! namespace[subName]) {
8
+ namespace =
9
+ namespace[subName] =
10
+ function () { if (this.initialize) this.initialize.apply(this, arguments) };
11
+ } else {
12
+ namespace = namespace[subName];
13
+ }
14
+ }
15
+ }
16
+
17
+ JS2.getClass = function (name) {
18
+ var splitName = name.split('.');
19
+ var namespace = window;
20
+
21
+ while (splitName.length) {
22
+ var subName = splitName.shift();
23
+ if (namespace[subName]) {
24
+ namespace = namespace[subName];
25
+ } else {
26
+ return null;
27
+ }
28
+ }
29
+
30
+ return namespace;
31
+ }
32
+
33
+ function _super () {
34
+ var method = arguments.callee.caller._super;
35
+ if (! method) return;
36
+ var self = arguments[0];
37
+ var args = [];
38
+ for (var i=1,len=arguments.length;i<len;i++) {
39
+ args.push(arguments[i]);
40
+ }
41
+ return method.apply(self, args);
42
+ }
@@ -0,0 +1,59 @@
1
+ class JS2.Observer {
2
+ function initialize (owner) {
3
+ this.lookupBefore = {};
4
+ this.lookupAfter = {};
5
+
6
+ this.replaced = {};
7
+ this.replacedValues = {};
8
+ }
9
+
10
+ function replaceFunction (owner, eventName) {
11
+ if (this.replaced[eventName]) return;
12
+
13
+ this.replacedValues[eventName] = owner[eventName];
14
+ this.replaced[eventName] = true;
15
+ owner[eventName] = this.getTrigger(eventName);
16
+ }
17
+
18
+ function trigger (owner, eventName, args) {
19
+ var beforeChain = this.lookupBefore[eventName];
20
+ if (beforeChain) this.executeChain(beforeChain, args);
21
+
22
+ var funct = this.replacedValues[eventName];
23
+ if (funct) funct.apply(owner, args);
24
+
25
+ var afterChain = this.lookupAfter[eventName];
26
+ if (afterChain) this.executeChain(afterChain, args);
27
+ }
28
+
29
+ function addListener (eventName, funct, before) {
30
+ var lookup = before ? this.lookupBefore : this.lookupAfter;
31
+
32
+ var chain = lookup[eventName] = lookup[eventName] || [];
33
+ chain.push(funct);
34
+ }
35
+
36
+ private
37
+
38
+ function getTrigger (eventName) {
39
+ return function () { this.__observer.trigger(this, eventName, arguments); };
40
+ }
41
+
42
+ function executeChain (chain, args) {
43
+ foreach (var f:i in chain) if (f) f.apply(this, args);
44
+ }
45
+ }
46
+
47
+ module JS2.Observable {
48
+ function addListener (eventName, funct, before) {
49
+ if (! this.__observer) this.__observer = new Factual.Core.Observer();
50
+
51
+ var id = this.__observer.addListener(eventName, funct, before);
52
+ this.__observer.replaceFunction(this, eventName);
53
+ return id;
54
+ }
55
+
56
+ function triggerEvent (eventName, args) {
57
+ if (this.__observer) this.__observer.trigger(this, eventName, args);
58
+ }
59
+ }
data/lib/js2.rb CHANGED
@@ -2,7 +2,7 @@ $:.unshift(File.dirname(__FILE__)) unless
2
2
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
4
  module Js2
5
- VERSION = '0.0.4'
5
+ VERSION = '0.0.5'
6
6
  end
7
7
 
8
8
  module JS2
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: js2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Su
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-02 00:00:00 -08:00
12
+ date: 2009-12-04 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -68,6 +68,8 @@ files:
68
68
  - examples/js2.yml
69
69
  - examples/test.yml
70
70
  - lib/javascript/sel_marker.js2
71
+ - lib/javascript/bootstrap.js
72
+ - lib/javascript/observer.js2
71
73
  - lib/javascript/test.js2
72
74
  - lib/js2.rb
73
75
  - lib/js2/ast/class_node.rb