envjs 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
data/lib/envjs/env.js CHANGED
@@ -257,7 +257,7 @@ $env.connection = $master.connection || function(xhr, responseHandler, data){
257
257
  //xhr.responseHeaders['Content-Length'] = headerValue+'';
258
258
  //xhr.responseHeaders['Date'] = new Date()+'';*/
259
259
  }catch(e){
260
- $env.error('failed to load response headers',e);
260
+ $env.warn('failed to load response headers',e);
261
261
  }
262
262
 
263
263
  }
@@ -300,13 +300,20 @@ $env.connection = $master.connection || function(xhr, responseHandler, data){
300
300
  //write data to output stream if required
301
301
  if(data&&data.length&&data.length>0){
302
302
  if ( xhr.method == "PUT" || xhr.method == "POST" ) {
303
- req.body = data;
303
+ Ruby.eval("lambda { |req,data| req.body = data}").call(req,data);
304
+ // req.body = data;
304
305
  }
305
306
  }
306
307
 
307
- connection = Ruby.Net.HTTP.start( url.host, url.port );
308
+ try {
309
+ connection = Ruby.Net.HTTP.start( url.host, url.port );
310
+ resp = connection.request(req);
311
+ } catch(e) {
312
+ $env.warn("XHR net request failed: "+e);
313
+ // FIX: do the on error stuff ...
314
+ throw e;
315
+ }
308
316
 
309
- resp = connection.request(req);
310
317
  }
311
318
  if(connection){
312
319
  try{
@@ -324,7 +331,8 @@ $env.connection = $master.connection || function(xhr, responseHandler, data){
324
331
  xhr.responseHeaders[k] = v;
325
332
  });
326
333
  }catch(e){
327
- $env.error('failed to load response headers',e);
334
+ $env.error('failed to load response headers: '+e);
335
+ throw e;
328
336
  }
329
337
 
330
338
  xhr.readyState = 4;
@@ -547,7 +555,8 @@ $env.__eval__ = function(script,scope){
547
555
  // $master.first_script_window = original_script_window;
548
556
  return result;
549
557
  }catch(e){
550
- $error(e);
558
+ $warn("Exception during on* event eval: "+e);
559
+ throw e;
551
560
  }
552
561
  };
553
562
 
@@ -1113,7 +1122,8 @@ $env.load = function(url,xhr_options){
1113
1122
  try{
1114
1123
  $w.document.load($location,xhr_options);
1115
1124
  }catch(e){
1116
- print("oopsw",e,e.stack);
1125
+ $warn("Exception while loading window: "+e);
1126
+ throw e;
1117
1127
  }
1118
1128
  };
1119
1129
 
@@ -2163,7 +2173,46 @@ try{
2163
2173
  // print(event.type,target,handled);
2164
2174
 
2165
2175
  if (!handled && event.type == "click" && target instanceof HTMLAnchorElement && target.href ) {
2166
- window.location = target.href;
2176
+ // window.location = target.href;
2177
+
2178
+ var url = target.href;
2179
+
2180
+ var skip = false;
2181
+
2182
+ if (url[0] === "#") {
2183
+ // print("return anchor only");
2184
+ skip = true;
2185
+ }
2186
+
2187
+ if (!skip) {
2188
+ var now = window.location.href.replace(/^file:\/\//,"").replace(/#.*/,"");
2189
+ var to = $master.first_script_window && $master.first_script_window.location.href;
2190
+ // var to = $env.location(url,window.location.href != "about:blank" ? window.location.href: undefined);
2191
+ // I'm not sure why this code is here ... looking at the FSW
2192
+ // print("nu",now,url,to);
2193
+ to = to || $env.location(url,window.location.href);
2194
+ // print("nu",now,url,to);
2195
+ if (to && to.indexOf(now)===0 && to[now.length]==="#") {
2196
+ skip = true;
2197
+ }
2198
+ }
2199
+ if (!skip) {
2200
+ if (url && url.indexOf(now)===0 && url[now.length]==="#") {
2201
+ // print("return diff anchor only");
2202
+ skip = true;
2203
+ }
2204
+ }
2205
+ if (!skip) {
2206
+ // print($location, window.location.href === $location, $location.indexOf("#")>0);
2207
+ if (url === window.location.href && $location.indexOf("#")>0) {
2208
+ // print('returning same with anchor');
2209
+ skip = true;
2210
+ }
2211
+ }
2212
+
2213
+ if (!skip){
2214
+ $env.reload(window, target.href, {referer: window.location.href});
2215
+ }
2167
2216
  }
2168
2217
 
2169
2218
  if (!handled && event.type == "click" &&
@@ -2179,12 +2228,18 @@ try{
2179
2228
  try{
2180
2229
  target.form.submit();
2181
2230
  // __submit__(target.form);
2182
- }catch(e){print("oopse",e);print(e.stack);};
2231
+ }catch(e){
2232
+ print("oopse",e);
2233
+ print(e.stack);
2234
+ e.backtrace && print(e.backtrace().join("\n"));
2235
+ throw e;
2236
+ };
2183
2237
  delete target.form.clk;
2184
2238
  }
2185
2239
 
2186
2240
  // print(event.type,target.type,target.constructor+"");
2187
- if (!handled && event.type == "click" && target instanceof HTMLInputElement && target.type == "checkbox" ) {
2241
+ // print("A",handled,event.type,target,target.type);
2242
+ if (!handled && event.type == "click" && target instanceof HTMLInputElement && ( target.type == "checkbox" || target.type == "radio" ) ) {
2188
2243
  target.checked = target.checked ? "" : "checked";
2189
2244
  }
2190
2245
 
@@ -2197,13 +2252,33 @@ try{
2197
2252
  boundary = (new Date).getTime();
2198
2253
  }
2199
2254
  data = $master["static"].__formSerialize__(target,undefined,boundary);
2200
- var options = {method: target.method || "get", data: data};
2255
+ var options = {method: target.method || "get", referer: this.location.href};
2256
+ if (options.method === "post" || options.method === "put") {
2257
+ options.data = data;
2258
+ var undef;
2259
+ data = undef;
2260
+ }
2201
2261
  if (boundary) {
2202
2262
  options["Content-Type"] = "multipart/form-data; boundary="+boundary;
2203
2263
  } else {
2204
2264
  options["Content-Type"] = 'application/x-www-form-urlencoded';
2205
2265
  }
2206
2266
  var action = target.action || window.location.href;
2267
+ if (data) {
2268
+ if (action.indexOf("?") < 0) {
2269
+ action = action + "?";
2270
+ }
2271
+ if (action[action.length-1] != "?") {
2272
+ action = action + "&";
2273
+ }
2274
+ var params = unescape(data).split("&");
2275
+ var new_params = [];
2276
+ for(var pi=0; pi < params.length; pi++) {
2277
+ var pair = params[pi].split("=");
2278
+ new_params.push(escape(pair[0])+"="+escape(pair[1]));
2279
+ }
2280
+ action = action + new_params.join("&");
2281
+ }
2207
2282
  $env.reload(proxy, action, options );
2208
2283
  }
2209
2284
 
@@ -2215,8 +2290,11 @@ try{
2215
2290
  __dispatchEvent__(target.parentNode, event, bubbles);
2216
2291
  }
2217
2292
  }catch(e){
2218
- print("oops",e);
2219
- print(e.stack);
2293
+ $warn("Exception while dispatching events: "+e);
2294
+ // print("oops e",e.stack);
2295
+ // print("oops e",e.backtrace && e.backtrace().join("\n"));
2296
+ // try { throw new Error("here"); } catch(x) { print("oops e",x.stack); }
2297
+ throw e;
2220
2298
  }
2221
2299
  };
2222
2300
 
@@ -2333,7 +2411,6 @@ XMLHttpRequest.prototype = {
2333
2411
  }
2334
2412
 
2335
2413
  try{
2336
- // print("pk");
2337
2414
  if (this.async){
2338
2415
  $debug("XHR sending asynch;");
2339
2416
  $env.runAsync(makeRequest);
@@ -2342,8 +2419,7 @@ try{
2342
2419
  makeRequest();
2343
2420
  }
2344
2421
  }catch(e){
2345
- print("oops xhr",e);
2346
- print("oops xhr",e.stack);
2422
+ $warn("Exception while processing XHR: " + e);
2347
2423
  throw e;
2348
2424
  }
2349
2425
 
@@ -2561,8 +2637,7 @@ $w.__defineGetter__("document", function(){
2561
2637
  init();
2562
2638
 
2563
2639
  } catch(e) {
2564
- print("oops0",e);
2565
- print("oops0",e.stack);
2640
+ // $warn("Exception during load: "+e);
2566
2641
  throw e;
2567
2642
  }
2568
2643
 
data/lib/envjs/runtime.rb CHANGED
@@ -265,7 +265,6 @@ EOJS
265
265
  loc = nil
266
266
  add_dep.call w, f
267
267
  evaluate(v, f, 1, w, w, f)
268
- # print "load #{uri_s}: #{Time.now-now}\n"
269
268
  else
270
269
  load *files
271
270
  end
@@ -416,6 +415,8 @@ if true
416
415
 
417
416
  static["$master"] = master
418
417
 
418
+ # fake it ...
419
+ static["isInner"] = true
419
420
  master.load.call Envjs::STATIC, static
420
421
 
421
422
  master["static"] = static
data/lib/envjs/static.js CHANGED
@@ -3651,7 +3651,17 @@ __extend__(DOMDocument.prototype, {
3651
3651
  xhr.open(method, url, this._parentWindow.document.async);
3652
3652
  // FIXME: not all XHRs have this right now
3653
3653
  xhr.setRequestHeader && xhr.setRequestHeader('Content-Type', xhr_options["Content-Type"] || 'application/x-www-form-urlencoded');
3654
+ xhr.setRequestHeader && xhr.setRequestHeader('Cookie', _this.cookie);
3655
+ // print("rf",xhr_options["referer"]);
3656
+ xhr.setRequestHeader && xhr_options["referer"] && xhr.setRequestHeader('Referer', xhr_options["referer"]);
3657
+ // print(_this._parentWindow.location.href);
3654
3658
  xhr.onreadystatechange = function(){
3659
+ // print(url,xhr.status,xhr.responseText);
3660
+ if(xhr.status === 302) {
3661
+ // print(302,xhr.responseHeaders["location"]);
3662
+ _this.load(xhr.responseHeaders["location"],{});
3663
+ return;
3664
+ }
3655
3665
  if (xhr.status != 200) {
3656
3666
  $warn("Could not retrieve XHR content from " + url + ": status code " + xhr.status);
3657
3667
  _this.loadXML(
@@ -3660,7 +3670,21 @@ __extend__(DOMDocument.prototype, {
3660
3670
  "</body></html>");
3661
3671
  } else {
3662
3672
  try{
3663
- _this.loadXML(xhr.responseText);
3673
+ _this.loadXML(xhr.responseText);
3674
+ _this.__original_text__ = xhr.responseText;
3675
+ if(xhr.responseHeaders && xhr.responseHeaders["set-cookie"]) {
3676
+ try {
3677
+ _this.cookie = xhr.responseHeaders["set-cookie"];
3678
+ } catch(e) {
3679
+ $error("could not set cookie: "+e);
3680
+ }
3681
+ }
3682
+ if(xhr.responseHeaders) {
3683
+ var h = _this.__headers__ = {};
3684
+ for(var key in xhr.responseHeaders) {
3685
+ h[key] = xhr.responseHeaders[key];
3686
+ }
3687
+ }
3664
3688
  }catch(e){
3665
3689
  $error("Error Parsing XML - ",e);
3666
3690
  _this.loadXML(
@@ -4077,6 +4101,7 @@ try{
4077
4101
  this._parentWindow.parseHtmlDocument(xmlString, this, null, null);
4078
4102
  }catch(e){
4079
4103
  print("oopsd",e);
4104
+ throw e;
4080
4105
  }
4081
4106
  // print("end parse");
4082
4107
  // print("parse time: "+(Date.now() - now)/1000.);
@@ -4598,7 +4623,8 @@ var __eval__ = function(script,node){
4598
4623
  // $master.first_script_window = original_script_window;
4599
4624
  return result;
4600
4625
  }catch(e){
4601
- $error(e);
4626
+ $warn("Exception during on* event eval: "+e);
4627
+ throw e;
4602
4628
  }
4603
4629
  };
4604
4630
 
@@ -6336,6 +6362,12 @@ __extend__(HTMLInputElement.prototype, {
6336
6362
 
6337
6363
  // $w.HTMLInputElement = HTMLInputElement;
6338
6364
 
6365
+ // Local Variables:
6366
+ // espresso-indent-level:4
6367
+ // c-basic-offset:4
6368
+ // tab-width:4
6369
+ // mode:auto-revert
6370
+ // End:
6339
6371
 
6340
6372
  $debug("Defining HTMLLabelElement");
6341
6373
  /*
@@ -22309,7 +22341,6 @@ $debug("Defining document.cookie");
22309
22341
  * - requires env
22310
22342
  */
22311
22343
 
22312
- /*
22313
22344
  var $cookies = {
22314
22345
  persistent:{
22315
22346
  //domain - key on domain name {
@@ -22327,7 +22358,6 @@ var $cookies = {
22327
22358
  //like above
22328
22359
  }
22329
22360
  };
22330
- */
22331
22361
 
22332
22362
  //HTMLDocument cookie
22333
22363
  __extend__(HTMLDocument.prototype, {
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 6
9
- version: 0.1.6
8
+ - 7
9
+ version: 0.1.7
10
10
  platform: ruby
11
11
  authors:
12
12
  - John Resig
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-02-25 00:00:00 -08:00
19
+ date: 2010-03-02 00:00:00 -08:00
20
20
  default_executable: envjsrb
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -30,8 +30,8 @@ dependencies:
30
30
  - 2
31
31
  - 0
32
32
  - 0
33
- - pre2
34
- version: 2.0.0.pre2
33
+ - pre3
34
+ version: 2.0.0.pre3
35
35
  type: :runtime
36
36
  version_requirements: *id001
37
37
  description: Browser environment for javascript interpreters