Project

General

Profile

« Previous | Next » 

Revision 5678

include busy spinner when loading search results

View differences:

lib/style/skins/semtools/jquery/jquery.busy.js
1
/*
2
 * jQuery-busy v1.0.3
3
 * Copyright 2010 Tomasz Szymczyszyn
4
 *
5
 * Examples available at:
6
 * http://kammerer.boo.pl/code/jquery-busy
7
 *
8
 * This plug-in is dual licensed under the MIT and GPL licenses:
9
 * http://www.opensource.org/licenses/mit-license.php
10
 * http://www.gnu.org/licenses/gpl.html
11
 */
12
(function($) {
13
  // Helper object factory 
14
  function Busy(options) {
15
    this.options = $.extend({}, Busy.defaults, options);
16
  };
17

  
18
  // Remembers currently "busied" targets along with options
19
  Busy.instances = [];
20

  
21
  Busy.repositionAll = function() {
22
    for (var i = 0; i < Busy.instances.length; i++) {
23
      if (! Busy.instances[i])
24
        continue;
25

  
26
      var options = Busy.instances[i].options;
27
      new Busy(options).positionImg($(Busy.instances[i].target), $.data(Busy.instances[i].target, "busy"), options.position);
28
    }
29
  };
30

  
31
  Busy.prototype.hide = function(targets) {
32
    targets.each(function() {
33
      var busyImg = $.data(this, "busy");
34
      if (busyImg)
35
        busyImg.remove();
36

  
37
      $(this).css("visibility", "");
38

  
39
      $.data(this, "busy", null);
40
      for (var i = 0; i < Busy.instances.length; i++)
41
        if (Busy.instances[i] != null && Busy.instances[i].target == this)
42
          Busy.instances[i] = null;
43
    });
44
  };
45

  
46
  Busy.prototype.show = function(targets) {
47
    var that = this;
48

  
49
    targets.each(function() {
50
      if ($.data(this, "busy"))
51
        return;
52

  
53
      var target = $(this);
54

  
55
      var busyImg = that.buildImg();
56
      busyImg.css("visibility", "hidden");
57
      busyImg.load(function() { 
58
        that.positionImg(target, busyImg, that.options.position);
59
        busyImg.css("visibility", "");
60
      });
61

  
62
      $("body").append(busyImg);
63

  
64
      if (that.options.hide)
65
        target.css("visibility", "hidden");
66

  
67
      $.data(this, "busy", busyImg);
68
      Busy.instances.push({ target : this, options : that.options });
69
    });
70
  };
71

  
72
  Busy.prototype.preload = function() {
73
    var busyImg = this.buildImg();
74
    busyImg.css("visibility", "hidden");
75
      busyImg.load(function() {
76
        $(this).remove();
77
      });
78

  
79
      $("body").append(busyImg);
80
  };
81

  
82
  // Creates image node, wraps it in $ object and returns.
83
  Busy.prototype.buildImg = function() {
84
    var html = "<img src='" + this.options.img + "' alt='" + this.options.alt + "' title='" + this.options.title + "'";
85

  
86
    if (this.options.width)
87
      html += " width='" + this.options.width + "'";
88
   
89
    if (this.options.height)
90
      html += " height='" + this.options.height + "'";
91

  
92
    html += " />";
93

  
94
    return $(html);
95
  };
96

  
97
  Busy.prototype.positionImg = function(target, busyImg, position) {
98
    var targetPosition = target.offset();
99
    var targetWidth = target.outerWidth();
100
    var targetHeight = target.outerHeight();
101

  
102
    var busyWidth = busyImg.outerWidth();
103
    var busyHeight = busyImg.outerHeight();
104

  
105
    if (position == "left") {
106
      var busyLeft = targetPosition.left - busyWidth - this.options.offset;
107
    }
108
    else if (position == "right") {
109
      var busyLeft = targetPosition.left + targetWidth + this.options.offset;
110
    }
111
    else {
112
      var busyLeft = targetPosition.left + (targetWidth - busyWidth) / 2.0;
113
    }
114

  
115
    var busyTop = targetPosition.top + (targetHeight - busyHeight) / 2.0;
116

  
117
    busyImg.css("position", "absolute");
118
    busyImg.css("left", busyLeft + "px");
119
    busyImg.css("top", busyTop + "px");
120
  };
121

  
122
  Busy.defaults = {
123
    img : 'busy.gif',
124
    alt : 'Please wait...',
125
    title : 'Please wait...',
126
    hide : true,
127
    position : 'center',
128
    zIndex : 1001,
129
    width : null,
130
    height : null,
131
    offset : 10
132
  };
133

  
134
  $.fn.busy = function(options, defaults) {
135
    if ($.inArray(options, ["clear", "hide", "remove"]) != -1) {
136
      // Hide busy image(s)
137
      new Busy(options).hide($(this));     
138
    }
139
    else if (options == "defaults") {
140
      // Overwrite defaults
141
      $.extend(Busy.defaults, defaults || {});
142
    }
143
    else if (options == "preload") {
144
      // Preload busy image
145
      new Busy(options).preload();
146
    }
147
    else if (options == "reposition") {
148
      // Update positions of all existing busy images
149
      Busy.repositionAll();
150
    }
151
    else {
152
      // Show busy image(s)
153
      new Busy(options).show($(this));
154
      return $(this);
155
    }
156
  };
157
})(jQuery);
lib/style/skins/semtools/index.jsp
51 51
<!-- jquery ui -->
52 52
<script language="javascript" type="text/javascript" src="<%=STYLE_SKINS_URL%>/semtools/jqueryui/js/jquery-ui-1.8.6.custom.min.js"></script>
53 53

  
54
<script language="javascript" type="text/javascript" src="<%=STYLE_SKINS_URL%>/semtools/jquery/jquery.busy.js"></script>
55

  
54 56
<script language="javascript" type="text/javascript" src="<%=STYLE_SKINS_URL%>/semtools/semtools.js"></script>
55 57
<script language="javascript" type="text/javascript" src="<%=STYLE_COMMON_URL%>/branding.js"></script>
56 58

  
......
123 125
			$("#" + divId + "Search").keyup(
124 126
				function () {
125 127
					if ($("#" + divId + "Search").val().length >= 3) {
128
						// search
126 129
						$("#" + divId).jstree("search", $("#" + divId + "Search").val());
127 130
						// now prune
128 131
						prune(divId, "jstree-search");
......
252 255
	// set the hidden parameters based on the current state of the form
253 256
	checkSearch(formObj);
254 257
	
258
	// start the busy indicator
259
	$("#searchResults").busy({ position : 'left', offset: -30, hide : true, img : "images/busy.gif" });
260
	
255 261
	//load the results
256 262
	$("#searchResults").load(
257 263
		"<%=SERVLET_URL%>" + " #content_wrapper",
......
270 276
				}).next().hide();
271 277
			});
272 278
			
279
			// stop the busy indicator
280
			$("#searchResults").busy("hide");
273 281
		});
274 282
		
275 283
	return false;

Also available in: Unified diff