ajax 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/VERSION +1 -1
  2. data/public/javascripts/ajax.js +65 -46
  3. metadata +4 -4
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.3
1
+ 1.0.4
@@ -57,7 +57,7 @@ LazyLoader.load = function(url, callback) {
57
57
  } catch (e) {
58
58
  alert(e);
59
59
  }
60
- }
60
+ };
61
61
 
62
62
  /**
63
63
  * AjaxAssets
@@ -140,7 +140,7 @@ var AjaxAssets = function(array, type) {
140
140
  var head = document.getElementsByTagName("head")[0];
141
141
  var script = document.createElement("script");
142
142
  script.src = url;
143
- script.type = 'text/javascript'
143
+ script.type = 'text/javascript';
144
144
  head.appendChild(script);
145
145
  // Handle Script loading
146
146
  if (callback) {
@@ -202,8 +202,13 @@ var AjaxAssets = function(array, type) {
202
202
  * image. Used to append an image tag to the body element
203
203
  * if an existing image is not found. Default: /images/ajax-loading.gif
204
204
  *
205
- * To customize image handling, override the <tt>showLoadingImage</tt> and
206
- * <tt>hideLoadingImage</tt> methods.
205
+ * <tt>show_loading_image_callback</tt> (optional) a method to call to show
206
+ * the loading image. Useful if you have more specific requirements as
207
+ * to what you want to show and how you want to show it.
208
+ *
209
+ * <tt>hide_loading_image_callback</tt> (requird if you use show_loading_image_callback) a method to call to hide
210
+ * the loading image. Useful if you have more specific requirements as
211
+ * to what you want to show and how you want to show it.
207
212
  *
208
213
  * Callbacks:
209
214
  *
@@ -245,6 +250,8 @@ var Ajax = function(options) {
245
250
  disable_next_address_intercept: false,
246
251
  loading_image: 'img#ajax-loading',
247
252
  loading_image_path: '/images/ajax-loading.gif',
253
+ show_loading_image_callback: undefined, // called to show the loading image
254
+ hide_loading_image_callback: undefined, // called to hide the loading image
248
255
  javascripts: undefined,
249
256
  stylesheets: new AjaxAssets([], 'css'),
250
257
  callbacks: [],
@@ -260,7 +267,7 @@ var Ajax = function(options) {
260
267
  jQuery.extend(self, self.options);
261
268
 
262
269
  // Initialize on DOM ready
263
- $(function() { self.init() });
270
+ $(function() { self.init(); });
264
271
 
265
272
  /**
266
273
  * Initializations run on DOM ready.
@@ -293,7 +300,7 @@ var Ajax = function(options) {
293
300
  var params = src.split('?')[1].split('&');
294
301
  jQuery.each(params, function(idx, param) {
295
302
  param = param.split('=');
296
- if (param.length == 1) { return true; }
303
+ if (param.length == 1) { return true; } // continue
297
304
 
298
305
  switch(param[0]) {
299
306
  case 'enabled':
@@ -305,6 +312,7 @@ var Ajax = function(options) {
305
312
  console.log('[ajax] set param default_container=', self.default_container);
306
313
  break;
307
314
  }
315
+ return undefined; // avoid lint warning
308
316
  });
309
317
  }
310
318
 
@@ -330,7 +338,7 @@ var Ajax = function(options) {
330
338
  self.addressChanged = function() {
331
339
  if (document.location.pathname != '/') { return false; }
332
340
  if (self.disable_next_address_intercept) {
333
- console.log('skipping address intercept & resetting disable_next_address_intercept')
341
+ console.log('skipping address intercept & resetting disable_next_address_intercept');
334
342
  self.disable_next_address_intercept = false;
335
343
  return false;
336
344
  }
@@ -423,6 +431,7 @@ var Ajax = function(options) {
423
431
  self.responseHandler(responseText, textStatus, XMLHttpRequest);
424
432
  }
425
433
  });
434
+ return true;
426
435
  };
427
436
 
428
437
 
@@ -518,7 +527,7 @@ var Ajax = function(options) {
518
527
  *
519
528
  */
520
529
  self.responseHandler = function(responseText, textStatus, XMLHttpRequest) {
521
-
530
+
522
531
  self.last_request_object = XMLHttpRequest;
523
532
  console.log("[AJAX] in response handler! status: " + self.last_request_object.status);
524
533
  if(self.last_request_object.status == 0) {
@@ -528,9 +537,9 @@ var Ajax = function(options) {
528
537
  var data = self.processResponseHeaders(XMLHttpRequest);
529
538
 
530
539
  if (data.soft_redirect !== undefined) {
531
- console.log('**** data.soft_redirect is ' + data.soft_redirect)
540
+ console.log('**** data.soft_redirect is ' + data.soft_redirect);
532
541
  $.address.value(data.soft_redirect);
533
- return false;
542
+ return;
534
543
  };
535
544
 
536
545
  var container = data.container === undefined ? $(self.default_container) : $(data.container);
@@ -577,10 +586,11 @@ var Ajax = function(options) {
577
586
  jQuery.each(jQuery.makeArray(data.assets.stylesheets), function(idx, url) {
578
587
  if (self.stylesheets.loadedAsset(url)) {
579
588
  console.log('[ajax] skipping css', url);
580
- return true;
589
+ return true; // continue
581
590
  } else {
582
591
  self.stylesheets.loadAsset(url);
583
592
  }
593
+ return undefined;
584
594
  });
585
595
  }
586
596
 
@@ -589,7 +599,7 @@ var Ajax = function(options) {
589
599
  */
590
600
  console.log('Using container ',container.selector);
591
601
  console.log('Set data ',data);
592
- container.data('ajax-info', data)
602
+ container.data('ajax-info', data);
593
603
  container.html(responseText);
594
604
 
595
605
  /**
@@ -610,12 +620,13 @@ var Ajax = function(options) {
610
620
  jQuery.each(jQuery.makeArray(data.assets.javascripts), function(idx, url) {
611
621
  if (self.javascripts.loadedAsset(url)) {
612
622
  console.log('[ajax] skipping js', url);
613
- return true;
623
+ return true; // continue
614
624
  }
615
625
 
616
626
  // Execute callbacks once the last asset has loaded
617
627
  callback = (idx == count - 1) ? undefined : self.executeCallbacks;
618
628
  self.javascripts.loadAsset(url, callback);
629
+ return undefined;
619
630
  });
620
631
  } else {
621
632
  // Execute callbacks immediately
@@ -663,13 +674,17 @@ var Ajax = function(options) {
663
674
  */
664
675
  self.hideLoadingImage = function() {
665
676
  // check if a new request has already started
666
- if (self.current_request.status == 0) {
667
- console.log("[AJAX] aborting hideLoadingImage.. ")
668
- return
677
+ if (self.current_request && self.current_request.status == 0) {
678
+ console.log("[AJAX] aborting hideLoadingImage.. ");
679
+ return;
669
680
  }
670
681
  if (!self.show_loading_image) { return; }
671
- $(document).unbind('mousemove', self.updateImagePosition);
672
- $(self.loading_image).hide();
682
+ if (!self.hide_loading_image_callback) {
683
+ $(document).unbind('mousemove', self.updateImagePosition);
684
+ $(self.loading_image).hide();
685
+ } else {
686
+ self.hide_loading_image_callback();
687
+ }
673
688
  };
674
689
 
675
690
  /**
@@ -677,39 +692,43 @@ var Ajax = function(options) {
677
692
  */
678
693
  self.showLoadingImage = function() {
679
694
  if (!self.show_loading_image) { return; }
695
+ if (!self.show_loading_image_callback) {
696
+ var icon = $(self.loading_image);
680
697
 
681
- var icon = $(self.loading_image);
698
+ // Create the image if it doesn't exist
699
+ if (icon.size() == 0) {
700
+ $('<img src="'+ self.loading_image_path +'" id="ajax-loading" alt="Loading..." />').hide().appendTo($('body'));
701
+ icon = $(self.loading_image);
702
+ }
682
703
 
683
- // Create the image if it doesn't exist
684
- if (icon.size() == 0) {
685
- $('<img src="'+ self.loading_image_path +'" id="ajax-loading" alt="Loading..." />').hide().appendTo($('body'));
686
- icon = $(self.loading_image);
687
- }
704
+ // Follow the mouse pointer
705
+ $(document).bind('mousemove', self.updateImagePosition);
688
706
 
689
- // Follow the mouse pointer
690
- $(document).bind('mousemove', self.updateImagePosition);
707
+ // Display at last click coords initially
708
+ if (self.last_click_coords !== undefined) {
709
+ self.updateImagePosition(self.last_click_coords);
691
710
 
692
- // Display at last click coords initially
693
- if (self.last_click_coords !== undefined) {
694
- self.updateImagePosition(self.last_click_coords);
711
+ // Center it
712
+ } else {
713
+ var marginTop = parseInt(icon.css('marginTop'), 10);
714
+ var marginLeft = parseInt(icon.css('marginLeft'), 10);
715
+ marginTop = isNaN(marginTop) ? 0 : marginTop;
716
+ marginLeft = isNaN(marginLeft) ? 0 : marginLeft;
717
+
718
+ icon.css({
719
+ position: 'absolute',
720
+ left: '50%',
721
+ top: '50%',
722
+ zIndex: '99',
723
+ marginTop: marginTop + jQuery(window).scrollTop(),
724
+ marginLeft: marginLeft + jQuery(window).scrollLeft()
725
+ });
726
+ }
727
+ icon.show();
695
728
 
696
- // Center it
697
729
  } else {
698
- var marginTop = parseInt(icon.css('marginTop'), 10);
699
- var marginLeft = parseInt(icon.css('marginLeft'), 10);
700
- marginTop = isNaN(marginTop) ? 0 : marginTop;
701
- marginLeft = isNaN(marginLeft) ? 0 : marginLeft;
702
-
703
- icon.css({
704
- position: 'absolute',
705
- left: '50%',
706
- top: '50%',
707
- zIndex: '99',
708
- marginTop: marginTop + jQuery(window).scrollTop(),
709
- marginLeft: marginLeft + jQuery(window).scrollLeft()
710
- });
730
+ self.show_loading_image_callback();
711
731
  }
712
- icon.show();
713
732
  };
714
733
 
715
734
  /**
@@ -782,7 +801,7 @@ var Ajax = function(options) {
782
801
  if (dom_ready !== undefined && dom_ready) {
783
802
  $(function() {
784
803
  self.executeCallback(callback);
785
- })
804
+ });
786
805
  } else {
787
806
  console.log('[ajax] executing callback', self.teaser(callback));
788
807
  try {
@@ -820,6 +839,6 @@ var Ajax = function(options) {
820
839
 
821
840
  return function(selector) {
822
841
  return selector.replace(sRE, '\\$1');
823
- }
842
+ };
824
843
  })();
825
844
  };
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ajax
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 3
10
- version: 1.0.3
9
+ - 4
10
+ version: 1.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Karl Varga
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-28 00:00:00 -07:00
18
+ date: 2010-12-02 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency