envjs 0.1.5 → 0.1.6
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/lib/envjs/env.js +52 -28
- data/lib/envjs/static.js +34 -27
- metadata +2 -2
data/lib/envjs/env.js
CHANGED
@@ -149,7 +149,8 @@ $env.log = function(msg, level){
|
|
149
149
|
};
|
150
150
|
|
151
151
|
$env.location = function(path, base){
|
152
|
-
|
152
|
+
var debug = false;
|
153
|
+
debug && print("loc",path,base);
|
153
154
|
if ( path == "about:blank" ) {
|
154
155
|
return path;
|
155
156
|
}
|
@@ -161,7 +162,7 @@ $env.location = function(path, base){
|
|
161
162
|
if ( s.substring(0,6) == "file:/" && s[6] != "/" ) {
|
162
163
|
s = "file://" + s.substring(5,s.length);
|
163
164
|
}
|
164
|
-
|
165
|
+
debug && print("YY",s);
|
165
166
|
return s;
|
166
167
|
}else if(base){
|
167
168
|
base = Ruby.URI.parse(base);
|
@@ -178,7 +179,7 @@ $env.location = function(path, base){
|
|
178
179
|
if ( result.substring(0,7) == "file://" ) {
|
179
180
|
result = result.substring(7,result.length);
|
180
181
|
}
|
181
|
-
|
182
|
+
debug && print("ZZ",result);
|
182
183
|
return result;
|
183
184
|
}else{
|
184
185
|
//return an absolute url from a url relative to the window location
|
@@ -188,6 +189,13 @@ $env.location = function(path, base){
|
|
188
189
|
( base != "about:blank" ) &&
|
189
190
|
base.href &&
|
190
191
|
(base.href.length > 0) ) {
|
192
|
+
|
193
|
+
base_uri = Ruby.URI.parse(base.href);
|
194
|
+
new_uri = Ruby.URI.parse(path);
|
195
|
+
result = Ruby.eval("lambda { |a,b| a+b; }")(base_uri,new_uri)+"";
|
196
|
+
debug && print("IIII",result);
|
197
|
+
return result;
|
198
|
+
|
191
199
|
base = base.href.substring(0, base.href.lastIndexOf('/'));
|
192
200
|
var result;
|
193
201
|
// print("XXXXX",base);
|
@@ -199,7 +207,7 @@ $env.location = function(path, base){
|
|
199
207
|
if ( result.substring(0,6) == "file:/" && result[6] != "/" ) {
|
200
208
|
result = "file://" + result.substring(5,result.length);
|
201
209
|
}
|
202
|
-
|
210
|
+
debug && print("****",result);
|
203
211
|
return result;
|
204
212
|
} else {
|
205
213
|
// print("RRR",result);
|
@@ -514,22 +522,28 @@ $env.__eval__ = function(script,scope){
|
|
514
522
|
if (script == "")
|
515
523
|
return undefined;
|
516
524
|
try {
|
517
|
-
var
|
525
|
+
var scope = node;
|
526
|
+
var __scopes__ = [];
|
518
527
|
var original = script;
|
519
528
|
if(scope) {
|
520
|
-
script = "(function(){return eval(original)}).call(
|
529
|
+
// script = "(function(){return eval(original)}).call(__scopes__[0])";
|
530
|
+
script = "return (function(){"+original+"}).call(__scopes__[0])";
|
521
531
|
while(scope) {
|
522
|
-
|
532
|
+
__scopes__.push(scope);
|
523
533
|
scope = scope.parentNode;
|
524
|
-
script = "with(
|
534
|
+
script = "with(__scopes__["+(__scopes__.length-1)+"] ){"+script+"};";
|
525
535
|
}
|
526
536
|
}
|
527
|
-
script = "function(original,
|
537
|
+
script = "function(original,__scopes__){"+script+"}";
|
538
|
+
// print("scripta",script);
|
539
|
+
// print("scriptb",original);
|
528
540
|
var original_script_window = $master.first_script_window;
|
529
541
|
if ( !$master.first_script_window ) {
|
530
542
|
// $master.first_script_window = window;
|
531
543
|
}
|
532
|
-
|
544
|
+
// FIX!!!
|
545
|
+
var $inner = node.ownerDocument._parentWindow["$inner"];
|
546
|
+
var result = $master.evaluate(script,$inner)(original,__scopes__);
|
533
547
|
// $master.first_script_window = original_script_window;
|
534
548
|
return result;
|
535
549
|
}catch(e){
|
@@ -638,8 +652,8 @@ var Envjs = function(){
|
|
638
652
|
|
639
653
|
//set this if you want to get some internal log statements
|
640
654
|
$env.logLevel = $env.INFO;
|
641
|
-
$env.logLevel = $env.DEBUG;
|
642
655
|
$env.logLevel = $env.ERROR;
|
656
|
+
$env.logLevel = $env.DEBUG;
|
643
657
|
$env.logLevel = $env.WARN;
|
644
658
|
|
645
659
|
$env.debug = function(msg){
|
@@ -2110,7 +2124,7 @@ $w.removeEventListener = function(type, fn){
|
|
2110
2124
|
|
2111
2125
|
function __dispatchEvent__(target, event, bubbles){
|
2112
2126
|
try{
|
2113
|
-
|
2127
|
+
$debug("dispatching event " + event.type);
|
2114
2128
|
|
2115
2129
|
//the window scope defines the $event object, for IE(^^^) compatibility;
|
2116
2130
|
$event = event;
|
@@ -2123,6 +2137,7 @@ try{
|
|
2123
2137
|
event.target = target;
|
2124
2138
|
}
|
2125
2139
|
//$debug("event target: " + event.target);
|
2140
|
+
var handled = false;
|
2126
2141
|
if ( event.type && (target.nodeType ||
|
2127
2142
|
target.window === window || // compares outer objects under TM (inner == outer, but !== (currently)
|
2128
2143
|
target === window ||
|
@@ -2131,27 +2146,27 @@ try{
|
|
2131
2146
|
//$debug("nodeType: " + target.nodeType);
|
2132
2147
|
if ( target.uuid && $events[target.uuid][event.type] ) {
|
2133
2148
|
var _this = target;
|
2134
|
-
|
2149
|
+
$debug('calling event handlers '+$events[target.uuid][event.type].length);
|
2135
2150
|
$events[target.uuid][event.type].forEach(function(fn){
|
2136
|
-
|
2137
|
-
fn(
|
2151
|
+
$debug('calling event handler '+fn+' on target '+_this);
|
2152
|
+
handled = (fn(event) == false) || handled;
|
2138
2153
|
});
|
2139
2154
|
}
|
2140
2155
|
|
2141
2156
|
if (target["on" + event.type]) {
|
2142
|
-
|
2143
|
-
target["on" + event.type](event);
|
2157
|
+
$debug('calling event handler on'+event.type+' on target '+target);
|
2158
|
+
handled = (target["on" + event.type](event) == false) || handled;
|
2144
2159
|
}
|
2145
2160
|
|
2146
|
-
|
2161
|
+
// SMP FIX: cancel/stop prop
|
2147
2162
|
|
2148
|
-
|
2163
|
+
// print(event.type,target,handled);
|
2149
2164
|
|
2150
|
-
if ( event.type == "click" && target instanceof HTMLAnchorElement && target.href ) {
|
2165
|
+
if (!handled && event.type == "click" && target instanceof HTMLAnchorElement && target.href ) {
|
2151
2166
|
window.location = target.href;
|
2152
2167
|
}
|
2153
2168
|
|
2154
|
-
if ( event.type == "click" &&
|
2169
|
+
if (!handled && event.type == "click" &&
|
2155
2170
|
target.form &&
|
2156
2171
|
( target instanceof HTMLInputElement || target instanceof HTMLTypeValueInputs ) &&
|
2157
2172
|
( ( target.tagName === "INPUT" &&
|
@@ -2169,11 +2184,11 @@ try{
|
|
2169
2184
|
}
|
2170
2185
|
|
2171
2186
|
// print(event.type,target.type,target.constructor+"");
|
2172
|
-
if ( event.type == "click" && target instanceof HTMLInputElement && target.type == "checkbox" ) {
|
2187
|
+
if (!handled && event.type == "click" && target instanceof HTMLInputElement && target.type == "checkbox" ) {
|
2173
2188
|
target.checked = target.checked ? "" : "checked";
|
2174
2189
|
}
|
2175
2190
|
|
2176
|
-
if ((event.type == "submit") && target instanceof HTMLFormElement) {
|
2191
|
+
if (!handled && (event.type == "submit") && target instanceof HTMLFormElement) {
|
2177
2192
|
$env.unload($w);
|
2178
2193
|
var proxy = $w.window;
|
2179
2194
|
var data;
|
@@ -2195,7 +2210,7 @@ try{
|
|
2195
2210
|
}else{
|
2196
2211
|
//$debug("non target: " + event.target + " \n this->"+target);
|
2197
2212
|
}
|
2198
|
-
if (bubbles && target.parentNode){
|
2213
|
+
if (!handled && bubbles && target.parentNode){
|
2199
2214
|
//$debug('bubbling to parentNode '+target.parentNode);
|
2200
2215
|
__dispatchEvent__(target.parentNode, event, bubbles);
|
2201
2216
|
}
|
@@ -2243,7 +2258,14 @@ $w.__defineGetter__('onunload', function(){
|
|
2243
2258
|
|
2244
2259
|
$w.__defineSetter__('onunload', function(fn){
|
2245
2260
|
//$w.addEventListener('unload', fn);
|
2246
|
-
})
|
2261
|
+
});*/
|
2262
|
+
|
2263
|
+
// Local Variables:
|
2264
|
+
// espresso-indent-level:4
|
2265
|
+
// c-basic-offset:4
|
2266
|
+
// tab-width:4
|
2267
|
+
// End:
|
2268
|
+
/*
|
2247
2269
|
* xhr.js
|
2248
2270
|
*/
|
2249
2271
|
$debug("Initializing Window XMLHttpRequest.");
|
@@ -2320,8 +2342,9 @@ try{
|
|
2320
2342
|
makeRequest();
|
2321
2343
|
}
|
2322
2344
|
}catch(e){
|
2323
|
-
print("
|
2324
|
-
print("
|
2345
|
+
print("oops xhr",e);
|
2346
|
+
print("oops xhr",e.stack);
|
2347
|
+
throw e;
|
2325
2348
|
}
|
2326
2349
|
|
2327
2350
|
},
|
@@ -2446,7 +2469,8 @@ $w.alert = function(message){
|
|
2446
2469
|
};
|
2447
2470
|
|
2448
2471
|
$w.confirm = function(question){
|
2449
|
-
//
|
2472
|
+
//FIX (?)
|
2473
|
+
return true;
|
2450
2474
|
};
|
2451
2475
|
|
2452
2476
|
$w.prompt = function(message, defaultMsg){
|
data/lib/envjs/static.js
CHANGED
@@ -4522,36 +4522,36 @@ __extend__(HTMLElement.prototype, {
|
|
4522
4522
|
},
|
4523
4523
|
|
4524
4524
|
onclick: function(event){
|
4525
|
-
|
4525
|
+
return __eval__(this.getAttribute('onclick')||'', this);
|
4526
4526
|
},
|
4527
4527
|
|
4528
4528
|
|
4529
4529
|
ondblclick: function(event){
|
4530
|
-
__eval__(this.getAttribute('ondblclick')||'', this);
|
4530
|
+
return __eval__(this.getAttribute('ondblclick')||'', this);
|
4531
4531
|
},
|
4532
4532
|
onkeydown: function(event){
|
4533
|
-
__eval__(this.getAttribute('onkeydown')||'', this);
|
4533
|
+
return __eval__(this.getAttribute('onkeydown')||'', this);
|
4534
4534
|
},
|
4535
4535
|
onkeypress: function(event){
|
4536
|
-
__eval__(this.getAttribute('onkeypress')||'', this);
|
4536
|
+
return __eval__(this.getAttribute('onkeypress')||'', this);
|
4537
4537
|
},
|
4538
4538
|
onkeyup: function(event){
|
4539
|
-
__eval__(this.getAttribute('onkeyup')||'', this);
|
4539
|
+
return __eval__(this.getAttribute('onkeyup')||'', this);
|
4540
4540
|
},
|
4541
4541
|
onmousedown: function(event){
|
4542
|
-
__eval__(this.getAttribute('onmousedown')||'', this);
|
4542
|
+
return __eval__(this.getAttribute('onmousedown')||'', this);
|
4543
4543
|
},
|
4544
4544
|
onmousemove: function(event){
|
4545
|
-
__eval__(this.getAttribute('onmousemove')||'', this);
|
4545
|
+
return __eval__(this.getAttribute('onmousemove')||'', this);
|
4546
4546
|
},
|
4547
4547
|
onmouseout: function(event){
|
4548
|
-
__eval__(this.getAttribute('onmouseout')||'', this);
|
4548
|
+
return __eval__(this.getAttribute('onmouseout')||'', this);
|
4549
4549
|
},
|
4550
4550
|
onmouseover: function(event){
|
4551
|
-
__eval__(this.getAttribute('onmouseover')||'', this);
|
4551
|
+
return __eval__(this.getAttribute('onmouseover')||'', this);
|
4552
4552
|
},
|
4553
4553
|
onmouseup: function(event){
|
4554
|
-
__eval__(this.getAttribute('onmouseup')||'', this);
|
4554
|
+
return __eval__(this.getAttribute('onmouseup')||'', this);
|
4555
4555
|
}
|
4556
4556
|
});
|
4557
4557
|
|
@@ -4574,24 +4574,27 @@ var __eval__ = function(script,node){
|
|
4574
4574
|
return undefined;
|
4575
4575
|
try {
|
4576
4576
|
var scope = node;
|
4577
|
-
var
|
4577
|
+
var __scopes__ = [];
|
4578
4578
|
var original = script;
|
4579
4579
|
if(scope) {
|
4580
|
-
script = "(function(){return eval(original)}).call(
|
4580
|
+
// script = "(function(){return eval(original)}).call(__scopes__[0])";
|
4581
|
+
script = "return (function(){"+original+"}).call(__scopes__[0])";
|
4581
4582
|
while(scope) {
|
4582
|
-
|
4583
|
+
__scopes__.push(scope);
|
4583
4584
|
scope = scope.parentNode;
|
4584
|
-
script = "with(
|
4585
|
+
script = "with(__scopes__["+(__scopes__.length-1)+"] ){"+script+"};";
|
4585
4586
|
}
|
4586
4587
|
}
|
4587
|
-
script = "function(original,
|
4588
|
+
script = "function(original,__scopes__){"+script+"}";
|
4589
|
+
// print("scripta",script);
|
4590
|
+
// print("scriptb",original);
|
4588
4591
|
var original_script_window = $master.first_script_window;
|
4589
4592
|
if ( !$master.first_script_window ) {
|
4590
4593
|
// $master.first_script_window = window;
|
4591
4594
|
}
|
4592
4595
|
// FIX!!!
|
4593
4596
|
var $inner = node.ownerDocument._parentWindow["$inner"];
|
4594
|
-
var result = $master.evaluate(script,$inner)(original,
|
4597
|
+
var result = $master.evaluate(script,$inner)(original,__scopes__);
|
4595
4598
|
// $master.first_script_window = original_script_window;
|
4596
4599
|
return result;
|
4597
4600
|
}catch(e){
|
@@ -4882,7 +4885,7 @@ var inputElements_status = {};
|
|
4882
4885
|
|
4883
4886
|
var inputElements_onchange = {
|
4884
4887
|
onchange: function(event){
|
4885
|
-
__eval__(this.getAttribute('onchange')||'', this)
|
4888
|
+
return __eval__(this.getAttribute('onchange')||'', this)
|
4886
4889
|
}
|
4887
4890
|
};
|
4888
4891
|
|
@@ -5366,10 +5369,10 @@ var HTMLBodyElement = function(ownerDocument) {
|
|
5366
5369
|
HTMLBodyElement.prototype = new HTMLElement;
|
5367
5370
|
__extend__(HTMLBodyElement.prototype, {
|
5368
5371
|
onload: function(event){
|
5369
|
-
__eval__(this.getAttribute('onload')||'', this)
|
5372
|
+
return __eval__(this.getAttribute('onload')||'', this)
|
5370
5373
|
},
|
5371
5374
|
onunload: function(event){
|
5372
|
-
__eval__(this.getAttribute('onunload')||'', this)
|
5375
|
+
return __eval__(this.getAttribute('onunload')||'', this)
|
5373
5376
|
}
|
5374
5377
|
});
|
5375
5378
|
|
@@ -5616,14 +5619,18 @@ __extend__(HTMLFormElement.prototype,{
|
|
5616
5619
|
|
5617
5620
|
},
|
5618
5621
|
onsubmit:function(){
|
5619
|
-
|
5620
|
-
|
5622
|
+
var v;
|
5623
|
+
if ((v = __eval__(this.getAttribute('onsubmit')||'', this)) != false) {
|
5624
|
+
// this.submit();
|
5621
5625
|
}
|
5626
|
+
return v;
|
5622
5627
|
},
|
5623
5628
|
onreset:function(){
|
5624
|
-
|
5629
|
+
var v;
|
5630
|
+
if ((v = __eval__(this.getAttribute('onreset')||'', this)) != false) {
|
5625
5631
|
this.reset();
|
5626
5632
|
}
|
5633
|
+
return v;
|
5627
5634
|
}
|
5628
5635
|
});
|
5629
5636
|
|
@@ -6106,7 +6113,7 @@ __extend__(HTMLFrameElement.prototype, {
|
|
6106
6113
|
return this._content;
|
6107
6114
|
},
|
6108
6115
|
onload: function(event){
|
6109
|
-
__eval__(this.getAttribute('onload')||'', this)
|
6116
|
+
return __eval__(this.getAttribute('onload')||'', this)
|
6110
6117
|
}
|
6111
6118
|
});
|
6112
6119
|
|
@@ -6265,7 +6272,7 @@ __extend__(HTMLImageElement.prototype, {
|
|
6265
6272
|
this.setAttribute('width', value);
|
6266
6273
|
},
|
6267
6274
|
onload: function(event){
|
6268
|
-
__eval__(this.getAttribute('onload')||'', this)
|
6275
|
+
return __eval__(this.getAttribute('onload')||'', this)
|
6269
6276
|
}
|
6270
6277
|
});
|
6271
6278
|
|
@@ -6434,7 +6441,7 @@ __extend__(HTMLLinkElement.prototype, {
|
|
6434
6441
|
this.setAttribute('type',value);
|
6435
6442
|
},
|
6436
6443
|
onload: function(event){
|
6437
|
-
__eval__(this.getAttribute('onload')||'', this)
|
6444
|
+
return __eval__(this.getAttribute('onload')||'', this)
|
6438
6445
|
}
|
6439
6446
|
});
|
6440
6447
|
|
@@ -6817,10 +6824,10 @@ __extend__(HTMLScriptElement.prototype, {
|
|
6817
6824
|
this.setAttribute('type',value);
|
6818
6825
|
},
|
6819
6826
|
onload: function(event){
|
6820
|
-
__eval__(this.getAttribute('onload')||'', this);
|
6827
|
+
return __eval__(this.getAttribute('onload')||'', this);
|
6821
6828
|
},
|
6822
6829
|
onerror: function(event){
|
6823
|
-
__eval__(this.getAttribute('onerror')||'', this);
|
6830
|
+
return __eval__(this.getAttribute('onerror')||'', this);
|
6824
6831
|
}
|
6825
6832
|
});
|
6826
6833
|
|