social_stream 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. data/Gemfile.lock +4 -1
  2. data/README.rdoc +13 -8
  3. data/app/views/activities/_activities.html.erb +1 -1
  4. data/app/views/activities/_jquery.html.erb +13 -7
  5. data/app/views/activities/_new.html.erb +9 -2
  6. data/app/views/layouts/_footer.html.erb +1 -1
  7. data/app/views/layouts/application.html.erb +5 -3
  8. data/lib/generators/social_stream/templates/migration.rb +69 -19
  9. data/lib/generators/social_stream/templates/public/images/btn/btn_bookmark.png +0 -0
  10. data/lib/generators/social_stream/templates/public/images/btn/btn_close.png +0 -0
  11. data/lib/generators/social_stream/templates/public/images/btn/btn_comment.png +0 -0
  12. data/lib/generators/social_stream/templates/public/images/btn/btn_comment_add.png +0 -0
  13. data/lib/generators/social_stream/templates/public/images/btn/btn_down.png +0 -0
  14. data/lib/generators/social_stream/templates/public/images/btn/btn_edit.png +0 -0
  15. data/lib/generators/social_stream/templates/public/images/btn/btn_page_link.png +0 -0
  16. data/lib/generators/social_stream/templates/public/images/btn/btn_printer.png +0 -0
  17. data/lib/generators/social_stream/templates/public/images/btn/btn_security.png +0 -0
  18. data/lib/generators/social_stream/templates/public/images/btn/btn_star.png +0 -0
  19. data/lib/generators/social_stream/templates/public/images/btn/date.png +0 -0
  20. data/lib/generators/social_stream/templates/public/images/btn/flag.png +0 -0
  21. data/lib/generators/social_stream/templates/public/images/btn/group_left.png +0 -0
  22. data/lib/generators/social_stream/templates/public/images/btn/group_right.png +0 -0
  23. data/lib/generators/social_stream/templates/public/images/btn/share.png +0 -0
  24. data/lib/generators/social_stream/templates/public/images/btn/uno.png +0 -0
  25. data/lib/generators/social_stream/templates/public/images/left.png +0 -0
  26. data/lib/generators/social_stream/templates/public/images/logos/original/group.png +0 -0
  27. data/lib/generators/social_stream/templates/public/images/logos/original/user.png +0 -0
  28. data/lib/generators/social_stream/templates/public/images/right.png +0 -0
  29. data/lib/generators/social_stream/templates/public/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  30. data/lib/generators/social_stream/templates/public/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  31. data/lib/generators/social_stream/templates/public/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  32. data/lib/generators/social_stream/templates/public/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  33. data/lib/generators/social_stream/templates/public/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  34. data/lib/generators/social_stream/templates/public/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  35. data/lib/generators/social_stream/templates/public/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  36. data/lib/generators/social_stream/templates/public/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  37. data/lib/generators/social_stream/templates/public/images/ui-icons_222222_256x240.png +0 -0
  38. data/lib/generators/social_stream/templates/public/images/ui-icons_2e83ff_256x240.png +0 -0
  39. data/lib/generators/social_stream/templates/public/images/ui-icons_454545_256x240.png +0 -0
  40. data/lib/generators/social_stream/templates/public/images/ui-icons_888888_256x240.png +0 -0
  41. data/lib/generators/social_stream/templates/public/images/ui-icons_cd0a0a_256x240.png +0 -0
  42. data/lib/generators/social_stream/templates/public/javascripts/jquery-ui-1.8.4.custom.min.js +763 -0
  43. data/lib/generators/social_stream/templates/public/javascripts/ui.dropdownchecklist.js +787 -0
  44. data/lib/generators/social_stream/templates/public/stylesheets/activities.css +5 -0
  45. data/lib/generators/social_stream/templates/public/stylesheets/index.css +0 -19
  46. data/lib/generators/social_stream/templates/public/stylesheets/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  47. data/lib/generators/social_stream/templates/public/stylesheets/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  48. data/lib/generators/social_stream/templates/public/stylesheets/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  49. data/lib/generators/social_stream/templates/public/stylesheets/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  50. data/lib/generators/social_stream/templates/public/stylesheets/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  51. data/lib/generators/social_stream/templates/public/stylesheets/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  52. data/lib/generators/social_stream/templates/public/stylesheets/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  53. data/lib/generators/social_stream/templates/public/stylesheets/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  54. data/lib/generators/social_stream/templates/public/stylesheets/smoothness/images/ui-icons_222222_256x240.png +0 -0
  55. data/lib/generators/social_stream/templates/public/stylesheets/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  56. data/lib/generators/social_stream/templates/public/stylesheets/smoothness/images/ui-icons_454545_256x240.png +0 -0
  57. data/lib/generators/social_stream/templates/public/stylesheets/smoothness/images/ui-icons_888888_256x240.png +0 -0
  58. data/lib/generators/social_stream/templates/public/stylesheets/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  59. data/lib/generators/social_stream/templates/public/stylesheets/smoothness/jquery-ui-1.7.3.custom.css +405 -0
  60. data/lib/generators/social_stream/templates/public/stylesheets/smoothness/jquery-ui-1.8.4.custom.css +572 -0
  61. data/lib/generators/social_stream/templates/public/stylesheets/ui.dropdownchecklist.css +21 -0
  62. data/lib/social_stream/models/actor.rb +1 -1
  63. data/lib/social_stream/version.rb +1 -1
  64. data/lib/tasks/db/populate.rake +34 -15
  65. data/social_stream.gemspec +2 -1
  66. metadata +80 -17
@@ -0,0 +1,787 @@
1
+ ;(function($) {
2
+ /*
3
+ * ui.dropdownchecklist
4
+ *
5
+ * Copyright (c) 2008-2010 Adrian Tosca, Copyright (c) 2010 Ittrium LLC
6
+ * Dual licensed under the MIT (MIT-LICENSE.txt)
7
+ * and GPL (GPL-LICENSE.txt) licenses.
8
+ *
9
+ */
10
+ // The dropdown check list jQuery plugin transforms a regular select html element into a dropdown check list.
11
+ $.widget("ui.dropdownchecklist", {
12
+ // Some globlals
13
+ // $.ui.dropdownchecklist.gLastOpened - keeps track of last opened dropdowncheck list so we can close it
14
+ // $.ui.dropdownchecklist.gIDCounter - simple counter to provide a unique ID as needed
15
+ version: function() {
16
+ alert('DropDownCheckList v1.1');
17
+ },
18
+ // Creates the drop container that keeps the items and appends it to the document
19
+ _appendDropContainer: function( controlItem ) {
20
+ var wrapper = $("<div/>");
21
+ // the container is wrapped in a div
22
+ wrapper.addClass("ui-dropdownchecklist ui-dropdownchecklist-dropcontainer-wrapper");
23
+ wrapper.addClass("ui-widget");
24
+ // assign an id
25
+ wrapper.attr("id",controlItem.attr("id") + '-ddw');
26
+ // initially hidden
27
+ wrapper.css({ position: 'absolute', left: "-33000px", top: "-33000px" });
28
+
29
+ var container = $("<div/>"); // the actual container
30
+ container.addClass("ui-dropdownchecklist-dropcontainer ui-widget-content");
31
+ container.css("overflow-y", "auto");
32
+ wrapper.append(container);
33
+
34
+ // insert the dropdown after the master control to try to keep the tab order intact
35
+ // if you just add it to the end, tabbing out of the drop down takes focus off the page
36
+ // @todo 22Sept2010 - check if size calculation is thrown off if the parent of the
37
+ // selector is hidden. We may need to add it to the end of the document here,
38
+ // calculate the size, and then move it back into proper position???
39
+ //$(document.body).append(wrapper);
40
+ wrapper.insertAfter(controlItem);
41
+
42
+ // flag that tells if the drop container is shown or not
43
+ wrapper.isOpen = false;
44
+ return wrapper;
45
+ },
46
+ // Look for browser standard 'open' on a closed selector
47
+ _isDropDownKeyShortcut: function(e,keycode) {
48
+ return e.altKey && ($.ui.keyCode.DOWN == keycode);// Alt + Down Arrow
49
+ },
50
+ // Look for key that will tell us to close the open dropdown
51
+ _isDropDownCloseKey: function(e,keycode) {
52
+ return ($.ui.keyCode.ESCAPE == keycode) || ($.ui.keyCode.ENTER == keycode);
53
+ },
54
+ // Handler to change the active focus based on a keystroke, moving some count of
55
+ // items from the element that has the current focus
56
+ _keyFocusChange: function(target,delta,limitToItems) {
57
+ // Find item with current focus
58
+ var focusables = $(":focusable");
59
+ var index = focusables.index(target);
60
+ if ( index >= 0 ) {
61
+ index += delta;
62
+ if ( limitToItems ) {
63
+ // Bound change to list of input elements
64
+ var allCheckboxes = this.dropWrapper.find("input:not([disabled])");
65
+ var firstIndex = focusables.index(allCheckboxes.get(0));
66
+ var lastIndex = focusables.index(allCheckboxes.get(allCheckboxes.length-1));
67
+ if ( index < firstIndex ) {
68
+ index = lastIndex;
69
+ } else if ( index > lastIndex ) {
70
+ index = firstIndex;
71
+ }
72
+ }
73
+ focusables.get(index).focus();
74
+ }
75
+ },
76
+ // Look for navigation, open, close (wired to keyup)
77
+ _handleKeyboard: function(e) {
78
+ var self = this;
79
+ var keyCode = (e.keyCode || e.which);
80
+ if (!self.dropWrapper.isOpen && self._isDropDownKeyShortcut(e, keyCode)) {
81
+ // Key command to open the dropdown
82
+ e.stopImmediatePropagation();
83
+ self._toggleDropContainer(true);
84
+ } else if (self.dropWrapper.isOpen && self._isDropDownCloseKey(e, keyCode)) {
85
+ // Key command to close the dropdown (but we retain focus in the control)
86
+ e.stopImmediatePropagation();
87
+ self._toggleDropContainer(false);
88
+ self.controlSelector.focus();
89
+ } else if (self.dropWrapper.isOpen
90
+ && (e.target.type == 'checkbox')
91
+ && ((keyCode == $.ui.keyCode.DOWN) || (keyCode == $.ui.keyCode.UP)) ) {
92
+ // Up/Down to cycle throught the open items
93
+ e.stopImmediatePropagation();
94
+ self._keyFocusChange(e.target, (keyCode == $.ui.keyCode.DOWN) ? 1 : -1, true);
95
+ } else if (self.dropWrapper.isOpen && (keyCode == $.ui.keyCode.TAB) ) {
96
+ // I wanted to adjust normal 'tab' processing here, but research indicates
97
+ // that TAB key processing is NOT a cancelable event. You have to use a timer
98
+ // hack to pull the focus back to where you want it after browser tab
99
+ // processing completes. Not going to work for us.
100
+ //e.stopImmediatePropagation();
101
+ //self._keyFocusChange(e.target, (e.shiftKey) ? -1 : 1, true);
102
+ }
103
+ },
104
+ // Look for change of focus
105
+ _handleFocus: function(e,focusIn,forDropdown) {
106
+ var self = this;
107
+ if (forDropdown && !self.dropWrapper.isOpen) {
108
+ // if the focus changes when the control is NOT open, mark it to show where the focus is/is not
109
+ e.stopImmediatePropagation();
110
+ if (focusIn) {
111
+ self.controlSelector.addClass("ui-state-hover");
112
+ if ($.ui.dropdownchecklist.gLastOpened != null) {
113
+ $.ui.dropdownchecklist.gLastOpened._toggleDropContainer( false );
114
+ }
115
+ } else {
116
+ self.controlSelector.removeClass("ui-state-hover");
117
+ }
118
+ } else if (!forDropdown && !focusIn) {
119
+ // The dropdown is open, and an item (NOT the dropdown) has just lost the focus.
120
+ // we really need a reliable method to see who has the focus as we process the blur,
121
+ // but that mechanism does not seem to exist. Instead we rely on a delay before
122
+ // posting the blur, with a focus event cancelling it before the delay expires.
123
+ if ( e != null ) { e.stopImmediatePropagation(); }
124
+ self.controlSelector.removeClass("ui-state-hover");
125
+ self._toggleDropContainer( false );
126
+ }
127
+ },
128
+ // Clear the pending change of focus, which keeps us 'in' the control
129
+ _cancelBlur: function(e) {
130
+ var self = this;
131
+ if (self.blurringItem != null) {
132
+ clearTimeout(self.blurringItem);
133
+ self.blurringItem = null;
134
+ }
135
+ },
136
+ // Creates the control that will replace the source select and appends it to the document
137
+ // The control resembles a regular select with single selection
138
+ _appendControl: function() {
139
+ var self = this, sourceSelect = this.sourceSelect, options = this.options;
140
+
141
+ // the control is wrapped in a basic container
142
+ var wrapper = $("<span/>");
143
+ wrapper.addClass("ui-dropdownchecklist ui-dropdownchecklist-selector-wrapper ui-widget");
144
+ wrapper.css({ cursor: "default", overflow: "hidden" });
145
+
146
+ // assign an ID
147
+ var baseID = sourceSelect.attr("id");
148
+ if ((baseID == null) || (baseID == "")) {
149
+ baseID = "ddcl-" + $.ui.dropdownchecklist.gIDCounter++;
150
+ } else {
151
+ baseID = "ddcl-" + baseID;
152
+ }
153
+ wrapper.attr("id",baseID);
154
+
155
+ // the actual control which you can style
156
+ // inline-block needed to enable 'width' but has interesting problems cross browser
157
+ var control = $("<span/>");
158
+ control.addClass("ui-dropdownchecklist-selector ui-state-default");
159
+ control.css( { display: "inline-block", overflow: "hidden", 'white-space': 'nowrap'} );
160
+ // Setting a tab index means we are interested in the tab sequence
161
+ var tabIndex = sourceSelect.attr("tabIndex");
162
+ if ( tabIndex == null ) {
163
+ tabIndex = 0;
164
+ } else {
165
+ tabIndex = parseInt(tabIndex);
166
+ if ( tabIndex < 0 ) {
167
+ tabIndex = 0;
168
+ }
169
+ }
170
+ control.attr("tabIndex", tabIndex);
171
+ control.keyup(function(e) {self._handleKeyboard(e);});
172
+ control.focus(function(e) {self._handleFocus(e,true,true);});
173
+ control.blur(function(e) {self._handleFocus(e,false,true);});
174
+ wrapper.append(control);
175
+
176
+ // the optional icon (which is inherently a block)
177
+ if (options.icon != null) {
178
+ var iconPlacement = (options.icon.placement == null) ? "left" : options.icon.placement;
179
+ var anIcon = $("<div/>");
180
+ anIcon.addClass("ui-icon");
181
+ anIcon.addClass( (options.icon.toOpen != null) ? options.icon.toOpen : "ui-icon-triangle-1-e");
182
+ anIcon.css({ 'float': iconPlacement });
183
+ control.append(anIcon);
184
+ }
185
+ // the text container keeps the control text that is built from the selected (checked) items
186
+ // inline-block needed to enable 'width' but has interesting problems cross browser
187
+ var textContainer = $("<span/>");
188
+ textContainer.addClass("ui-dropdownchecklist-text");
189
+ textContainer.css( { display: "inline-block", 'white-space': "nowrap", overflow: "hidden" } );
190
+ control.append(textContainer);
191
+
192
+ // add the hover styles to the control
193
+ wrapper.hover(
194
+ function() {
195
+ if (!self.disabled) {
196
+ control.addClass("ui-state-hover");
197
+ }
198
+ }
199
+ , function() {
200
+ if (!self.disabled) {
201
+ control.removeClass("ui-state-hover");
202
+ }
203
+ }
204
+ );
205
+ // clicking on the control toggles the drop container
206
+ wrapper.click(function(event) {
207
+ if (!self.disabled) {
208
+ event.stopImmediatePropagation();
209
+ self._toggleDropContainer( !self.dropWrapper.isOpen );
210
+ }
211
+ });
212
+ wrapper.insertAfter(sourceSelect);
213
+
214
+ // Watch for a window resize and adjust the control if open
215
+ $(window).resize(function() {
216
+ if (!self.disabled && self.dropWrapper.isOpen) {
217
+ // Reopen yourself to get the position right
218
+ self._toggleDropContainer(true);
219
+ }
220
+ });
221
+ return wrapper;
222
+ },
223
+ // Creates a drop item that coresponds to an option element in the source select
224
+ _createDropItem: function(index, tabIndex, value, text, checked, disabled, indent) {
225
+ var self = this, options = this.options, sourceSelect = this.sourceSelect, controlWrapper = this.controlWrapper;
226
+ // the item contains a div that contains a checkbox input and a lable for the text
227
+ // the div
228
+ var item = $("<div/>");
229
+ item.addClass("ui-dropdownchecklist-item");
230
+ item.css({'white-space': "nowrap"});
231
+ var checkedString = checked ? ' checked="checked"' : '';
232
+ var classString = disabled ? ' class="inactive"' : ' class="active"';
233
+
234
+ // generated id must be a bit unique to keep from colliding
235
+ var idBase = controlWrapper.attr("id");
236
+ var id = idBase + '-i' + index;
237
+ var checkBox;
238
+
239
+ // all items start out disabled to keep them out of the tab order
240
+ if (self.isMultiple) { // the checkbox
241
+ checkBox = $('<input disabled type="checkbox" id="' + id + '"' + checkedString + classString + ' tabindex="' + tabIndex + '" />');
242
+ } else { // the radiobutton
243
+ checkBox = $('<input disabled type="radio" id="' + id + '" name="' + idBase + '"' + checkedString + classString + ' tabindex="' + tabIndex + '" />');
244
+ }
245
+ checkBox = checkBox.attr("index", index).val(value);
246
+ item.append(checkBox);
247
+
248
+ // the text
249
+ var label = $("<label for=" + id + "/>");
250
+ label.addClass("ui-dropdownchecklist-text");
251
+ label.css({ cursor: "default" });
252
+ label.text(text);
253
+ if (indent) {
254
+ item.addClass("ui-dropdownchecklist-indent");
255
+ }
256
+ item.addClass("ui-state-default");
257
+ if (disabled) {
258
+ item.addClass("ui-state-disabled");
259
+ }
260
+ label.click(function(e) {e.stopImmediatePropagation();});
261
+ item.append(label);
262
+
263
+ // active items display themselves with hover
264
+ item.hover(
265
+ function(e) {
266
+ var anItem = $(this);
267
+ if (!anItem.hasClass("ui-state-disabled")) { anItem.addClass("ui-state-hover"); }
268
+ }
269
+ , function(e) {
270
+ var anItem = $(this);
271
+ anItem.removeClass("ui-state-hover");
272
+ }
273
+ );
274
+ // clicking on the checkbox synchronizes the source select
275
+ checkBox.click(function(e) {
276
+ var aCheckBox = $(this);
277
+ e.stopImmediatePropagation();
278
+ if (aCheckBox.hasClass("active") ) {
279
+ // Active checkboxes take active action
280
+ self._syncSelected(aCheckBox);
281
+ self.sourceSelect.trigger("change", 'ddcl_internal');
282
+ if (!self.isMultiple && options.closeRadioOnClick) {
283
+ self._toggleDropContainer(false);
284
+ }
285
+ }
286
+ });
287
+ // we are interested in the focus leaving the check box
288
+ // but we need to detect the focus leaving one check box but
289
+ // entering another. There is no reliable way to detect who
290
+ // received the focus on a blur, so post the blur in the future,
291
+ // knowing we will cancel it if we capture the focus in a timely manner
292
+ // 23Sept2010 - unfortunately, IE 7+ and Chrome like to post a blur
293
+ // event to the current item with focus when the user
294
+ // clicks in the scroll bar. So if you have a scrollable
295
+ // dropdown with focus on an item, clicking in the scroll
296
+ // will close the drop down.
297
+ // I have no solution for blur processing at this time.
298
+ /*********
299
+ var timerFunction = function(){
300
+ // I had a hell of a time getting setTimeout to fire this, do not try to
301
+ // define it within the blur function
302
+ try { self._handleFocus(null,false,false); } catch(ex){ alert('timer failed: '+ex);}
303
+ };
304
+ checkBox.blur(function(e) {
305
+ self.blurringItem = setTimeout( timerFunction, 200 );
306
+ });
307
+ checkBox.focus(function(e) {self._cancelBlur();});
308
+ **********/
309
+ // check/uncheck the item on clicks on the entire item div
310
+ item.click(function(e) {
311
+ var anItem = $(this);
312
+ e.stopImmediatePropagation();
313
+ if (!anItem.hasClass("ui-state-disabled") ) {
314
+ // check/uncheck the underlying control
315
+ var aCheckBox = anItem.find("input");
316
+ var checked = aCheckBox.attr("checked");
317
+ aCheckBox.attr("checked", !checked);
318
+ self._syncSelected(aCheckBox);
319
+ self.sourceSelect.trigger("change", 'ddcl_internal');
320
+ if (!checked && !self.isMultiple && options.closeRadioOnClick) {
321
+ self._toggleDropContainer(false);
322
+ }
323
+ } else {
324
+ // retain the focus even if disabled
325
+ anItem.focus();
326
+ self._cancelBlur();
327
+ }
328
+ });
329
+ // do not let the focus wander around
330
+ item.focus(function(e) {
331
+ var anItem = $(this);
332
+ e.stopImmediatePropagation();
333
+ });
334
+ item.keyup(function(e) {self._handleKeyboard(e);});
335
+ return item;
336
+ },
337
+ _createGroupItem: function(text,disabled) {
338
+ var self = this;
339
+ var group = $("<div />");
340
+ group.addClass("ui-dropdownchecklist-group ui-widget-header");
341
+ if (disabled) {
342
+ group.addClass("ui-state-disabled");
343
+ }
344
+ group.css({'white-space': "nowrap"});
345
+
346
+ var label = $("<span/>");
347
+ label.addClass("ui-dropdownchecklist-text");
348
+ label.css( { cursor: "default" });
349
+ label.text(text);
350
+ group.append(label);
351
+
352
+ // anything interesting when you click the group???
353
+ group.click(function(e) {
354
+ var aGroup= $(this);
355
+ e.stopImmediatePropagation();
356
+ // retain the focus even if no action is taken
357
+ aGroup.focus();
358
+ self._cancelBlur();
359
+ });
360
+ // do not let the focus wander around
361
+ group.focus(function(e) {
362
+ var aGroup = $(this);
363
+ e.stopImmediatePropagation();
364
+ });
365
+ return group;
366
+ },
367
+ // Creates the drop items and appends them to the drop container
368
+ // Also calculates the size needed by the drop container and returns it
369
+ _appendItems: function() {
370
+ var self = this, sourceSelect = this.sourceSelect, dropWrapper = this.dropWrapper;
371
+ var dropContainerDiv = dropWrapper.find(".ui-dropdownchecklist-dropcontainer");
372
+ sourceSelect.children().each(function(index) { // when the select has groups
373
+ var opt = $(this);
374
+ if (opt.is("option")) {
375
+ self._appendOption(opt, dropContainerDiv, index, false, false);
376
+ } else if (opt.is("optgroup")) {
377
+ var disabled = opt.attr("disabled");
378
+ var text = opt.attr("label");
379
+ if (text != "") {
380
+ var group = self._createGroupItem(text,disabled);
381
+ dropContainerDiv.append(group);
382
+ }
383
+ self._appendOptions(opt, dropContainerDiv, index, true, disabled);
384
+ }
385
+ });
386
+ var divWidth = dropContainerDiv.outerWidth();
387
+ var divHeight = dropContainerDiv.outerHeight();
388
+ return { width: divWidth, height: divHeight };
389
+ },
390
+ _appendOptions: function(parent, container, parentIndex, indent, forceDisabled) {
391
+ var self = this;
392
+ parent.children("option").each(function(index) {
393
+ var option = $(this);
394
+ var childIndex = (parentIndex + "." + index);
395
+ self._appendOption(option, container, childIndex, indent, forceDisabled);
396
+ });
397
+ },
398
+ _appendOption: function(option, container, index, indent, forceDisabled) {
399
+ var self = this;
400
+ var text = option.text();
401
+ var value = option.val();
402
+ var selected = option.attr("selected");
403
+ var disabled = (forceDisabled || option.attr("disabled"));
404
+ // Use the same tab index as the selector replacement
405
+ var tabIndex = self.controlSelector.attr("tabindex");
406
+ var item = self._createDropItem(index, tabIndex, value, text, selected, disabled, indent);
407
+ container.append(item);
408
+ },
409
+ // Synchronizes the items checked and the source select
410
+ // When firstItemChecksAll option is active also synchronizes the checked items
411
+ // senderCheckbox parameters is the checkbox input that generated the synchronization
412
+ _syncSelected: function(senderCheckbox) {
413
+ var self = this, options = this.options, sourceSelect = this.sourceSelect, dropWrapper = this.dropWrapper;
414
+ var allCheckboxes = dropWrapper.find("input.active");
415
+ if (options.firstItemChecksAll) {
416
+ // if firstItemChecksAll is true, check all checkboxes if the first one is checked
417
+ if ((senderCheckbox != null) && (senderCheckbox.attr("index") == 0)) {
418
+ allCheckboxes.attr("checked", senderCheckbox.attr("checked"));
419
+ } else {
420
+ // check the first checkbox if all the other checkboxes are checked
421
+ var allChecked = true;
422
+ var firstCheckbox = null;
423
+ allCheckboxes.each(function(index) {
424
+ if (index > 0) {
425
+ var checked = $(this).attr("checked");
426
+ if (!checked) { allChecked = false; }
427
+ } else {
428
+ firstCheckbox = $(this);
429
+ }
430
+ });
431
+ if ( firstCheckbox != null ) {
432
+ firstCheckbox.attr("checked", allChecked );
433
+ }
434
+ }
435
+ }
436
+ // do the actual synch with the source select
437
+ allCheckboxes = dropWrapper.find("input");
438
+ var selectOptions = sourceSelect.get(0).options;
439
+ allCheckboxes.each(function(index) {
440
+ $(selectOptions[index]).attr("selected", $(this).attr("checked"));
441
+ });
442
+ // update the text shown in the control
443
+ self._updateControlText();
444
+
445
+ // Ensure the focus stays pointing where the user is working
446
+ if ( senderCheckbox != null) { senderCheckbox.focus(); }
447
+ },
448
+ _sourceSelectChangeHandler: function(event) {
449
+ var self = this, dropWrapper = this.dropWrapper;
450
+ dropWrapper.find("input").val(self.sourceSelect.val());
451
+
452
+ // update the text shown in the control
453
+ self._updateControlText();
454
+ },
455
+ // Updates the text shown in the control depending on the checked (selected) items
456
+ _updateControlText: function() {
457
+ var self = this, sourceSelect = this.sourceSelect, options = this.options, controlWrapper = this.controlWrapper;
458
+ var firstOption = sourceSelect.find("option:first");
459
+ var selectOptions = sourceSelect.find("option");
460
+ var text = self._formatText(selectOptions, options.firstItemChecksAll, firstOption);
461
+ var controlLabel = controlWrapper.find(".ui-dropdownchecklist-text");
462
+
463
+ var image = $("<img>");
464
+ image.attr("src", "/images/btn/btn_security.png");
465
+ image.attr('alt', 'security');
466
+ image.attr('id','security_image');
467
+
468
+ var down = $("<img>");
469
+ down.attr("src","/images/btn/btn_down.png")
470
+
471
+
472
+
473
+ //controlLabel.html(text);
474
+ controlLabel.html(image);
475
+ controlLabel.append(" ");
476
+ controlLabel.append(down);
477
+ //controlLabel.attr("title", text);
478
+ controlLabel.attr("title", "security");
479
+
480
+ },
481
+ // Formats the text that is shown in the control
482
+ _formatText: function(selectOptions, firstItemChecksAll, firstOption) {
483
+ var text;
484
+ if ( $.isFunction(this.options.textFormatFunction) ) {
485
+ // let the callback do the formatting, but do not allow it to fail
486
+ try {
487
+ text = this.options.textFormatFunction(selectOptions);
488
+ } catch(ex) {
489
+ alert( 'textFormatFunction failed: ' + ex );
490
+ }
491
+ } else if (firstItemChecksAll && (firstOption != null) && firstOption.attr("selected")) {
492
+ // just set the text from the first item
493
+ text = firstOption.text();
494
+ } else {
495
+ // concatenate the text from the checked items
496
+ text = "";
497
+ selectOptions.each(function() {
498
+ if ($(this).attr("selected")) {
499
+ if ( text != "" ) { text += ", "; }
500
+ text += $(this).text();
501
+ }
502
+ });
503
+ if ( text == "" ) {
504
+ text = (this.options.emptyText != null) ? this.options.emptyText : "&nbsp;";
505
+ }
506
+ }
507
+ return text;
508
+ },
509
+ // Shows and hides the drop container
510
+ _toggleDropContainer: function( makeOpen ) {
511
+ var self = this;
512
+ // hides the last shown drop container
513
+ var hide = function(instance) {
514
+ if ((instance != null) && instance.dropWrapper.isOpen ){
515
+ instance.dropWrapper.isOpen = false;
516
+ $.ui.dropdownchecklist.gLastOpened = null;
517
+
518
+ var config = instance.options;
519
+ instance.dropWrapper.css({
520
+ top: "-33000px",
521
+ left: "-33000px"
522
+ });
523
+ var aControl = instance.controlSelector;
524
+ aControl.removeClass("ui-state-active");
525
+ aControl.removeClass("ui-state-hover");
526
+
527
+ var anIcon = instance.controlWrapper.find(".ui-icon");
528
+ if ( anIcon.length > 0 ) {
529
+ anIcon.removeClass( (config.icon.toClose != null) ? config.icon.toClose : "ui-icon-triangle-1-s");
530
+ anIcon.addClass( (config.icon.toOpen != null) ? config.icon.toOpen : "ui-icon-triangle-1-e");
531
+ }
532
+ $(document).unbind("click", hide);
533
+
534
+ // keep the items out of the tab order by disabling them
535
+ instance.dropWrapper.find("input.active").attr("disabled","disabled");
536
+
537
+ // the following blur just does not fire??? because it is hidden??? because it does not have focus???
538
+ //instance.sourceSelect.trigger("blur");
539
+ //instance.sourceSelect.triggerHandler("blur");
540
+ if($.isFunction(config.onComplete)) { try {
541
+ config.onComplete.call(instance,instance.sourceSelect.get(0));
542
+ } catch(ex) {
543
+ alert( 'callback failed: ' + ex );
544
+ }}
545
+ }
546
+ };
547
+ // shows the given drop container instance
548
+ var show = function(instance) {
549
+ if ( !instance.dropWrapper.isOpen ) {
550
+ instance.dropWrapper.isOpen = true;
551
+ $.ui.dropdownchecklist.gLastOpened = instance;
552
+
553
+ var config = instance.options;
554
+ instance.dropWrapper.css({
555
+ top: instance.controlWrapper.offset().top + instance.controlWrapper.outerHeight() + "px",
556
+ left: instance.controlWrapper.offset().left + "px"
557
+ });
558
+ var ancestorsZIndexes = instance.controlWrapper.parents().map(
559
+ function() {
560
+ var zIndex = $(this).css("z-index");
561
+ return isNaN(zIndex) ? 0 : zIndex; }
562
+ ).get();
563
+ var parentZIndex = Math.max.apply(Math, ancestorsZIndexes);
564
+ if (parentZIndex > 0) {
565
+ instance.dropWrapper.css({
566
+ zIndex: (parentZIndex+1)
567
+ });
568
+ }
569
+ var aControl = instance.controlSelector;
570
+ aControl.addClass("ui-state-active");
571
+ aControl.removeClass("ui-state-hover");
572
+
573
+ var anIcon = instance.controlWrapper.find(".ui-icon");
574
+ if ( anIcon.length > 0 ) {
575
+ anIcon.removeClass( (config.icon.toOpen != null) ? config.icon.toOpen : "ui-icon-triangle-1-e");
576
+ anIcon.addClass( (config.icon.toClose != null) ? config.icon.toClose : "ui-icon-triangle-1-s");
577
+ }
578
+ $(document).bind("click", function(e) {hide(instance);} );
579
+
580
+ // insert the items back into the tab order by enabling all active ones
581
+ var activeItems = instance.dropWrapper.find("input.active");
582
+ activeItems.removeAttr("disabled");
583
+
584
+ // we want the focus on the first active input item
585
+ var firstActiveItem = activeItems.get(0);
586
+ if ( firstActiveItem != null ) {
587
+ firstActiveItem.focus();
588
+ }
589
+ }
590
+ };
591
+ if ( makeOpen ) {
592
+ hide($.ui.dropdownchecklist.gLastOpened);
593
+ show(self);
594
+ } else {
595
+ hide(self);
596
+ }
597
+ },
598
+ // Set the size of the control and of the drop container
599
+ _setSize: function(dropCalculatedSize) {
600
+ var options = this.options, dropWrapper = this.dropWrapper, controlWrapper = this.controlWrapper;
601
+
602
+ // use the width from config options if set, otherwise set the same width as the drop container
603
+ var controlWidth = dropCalculatedSize.width;
604
+ if (options.width != null) {
605
+ controlWidth = parseInt(options.width);
606
+ } else if (options.minWidth != null) {
607
+ var minWidth = parseInt(options.minWidth);
608
+ // if the width is too small (usually when there are no items) set a minimum width
609
+ if (controlWidth < minWidth) {
610
+ controlWidth = minWidth;
611
+ }
612
+ }
613
+ var control = this.controlSelector;
614
+ control.css({ width: controlWidth + "px" });
615
+
616
+ // if we size the text, then Firefox places icons to the right properly
617
+ // and we do not wrap on long lines
618
+ var controlText = control.find(".ui-dropdownchecklist-text");
619
+ var controlIcon = control.find(".ui-icon");
620
+ if ( controlIcon != null ) {
621
+ // Must be an inner/outer/border problem, but IE6 needs an extra bit of space
622
+ controlWidth -= (controlIcon.outerWidth() + 6);
623
+ controlText.css( { width: controlWidth + "px" } );
624
+ }
625
+ // Account for padding, borders, etc
626
+ controlWidth = controlWrapper.outerWidth();
627
+
628
+ // the drop container height can be set from options
629
+ var maxDropHeight = (options.maxDropHeight != null)
630
+ ? parseInt(options.maxDropHeight)
631
+ : -1;
632
+ var dropHeight = ((maxDropHeight > 0) && (dropCalculatedSize.height > maxDropHeight))
633
+ ? maxDropHeight
634
+ : dropCalculatedSize.height;
635
+ // ensure the drop container is not less than the control width (would be ugly)
636
+ var dropWidth = dropCalculatedSize.width < controlWidth ? controlWidth : dropCalculatedSize.width;
637
+
638
+ $(dropWrapper).css({
639
+ height: dropHeight + "px",
640
+ width: dropWidth + "px"
641
+ });
642
+ dropWrapper.find(".ui-dropdownchecklist-dropcontainer").css({
643
+ height: dropHeight + "px"
644
+ });
645
+ },
646
+ // Initializes the plugin
647
+ _init: function() {
648
+ var self = this, options = this.options;
649
+ if ( $.ui.dropdownchecklist.gIDCounter == null) {
650
+ $.ui.dropdownchecklist.gIDCounter = 1;
651
+ }
652
+ // item blurring relies on a cancelable timer
653
+ self.blurringItem = null;
654
+
655
+ // sourceSelect is the select on which the plugin is applied
656
+ var sourceSelect = self.element;
657
+ self.initialDisplay = sourceSelect.css("display");
658
+ sourceSelect.css("display", "none");
659
+ self.initialMultiple = sourceSelect.attr("multiple");
660
+ self.isMultiple = self.initialMultiple;
661
+ if (options.forceMultiple != null) { self.isMultiple = options.forceMultiple; }
662
+ sourceSelect.attr("multiple", true);
663
+ self.sourceSelect = sourceSelect;
664
+
665
+ // append the control that resembles a single selection select
666
+ var controlWrapper = self._appendControl();
667
+ self.controlWrapper = controlWrapper;
668
+ self.controlSelector = controlWrapper.find(".ui-dropdownchecklist-selector");
669
+
670
+ // create the drop container where the items are shown
671
+ var dropWrapper = self._appendDropContainer(controlWrapper);
672
+ self.dropWrapper = dropWrapper;
673
+
674
+ // append the items from the source select element
675
+ var dropCalculatedSize = self._appendItems();
676
+
677
+ // updates the text shown in the control
678
+ self._updateControlText(controlWrapper, dropWrapper, sourceSelect);
679
+
680
+ // set the sizes of control and drop container
681
+ self._setSize(dropCalculatedSize);
682
+
683
+ // look for possible auto-check needed on first item
684
+ if ( options.firstItemChecksAll ) {
685
+ self._syncSelected(null);
686
+ }
687
+ // BGIFrame for IE6
688
+ if (options.bgiframe && typeof self.dropWrapper.bgiframe == "function") {
689
+ self.dropWrapper.bgiframe();
690
+ }
691
+ // listen for change events on the source select element
692
+ // ensure we avoid processing internally triggered changes
693
+ self.sourceSelect.change(function(event, eventName) {
694
+ if (eventName != 'ddcl_internal') {
695
+ self._sourceSelectChangeHandler(event);
696
+ }
697
+ });
698
+ },
699
+ // Refresh the disable and check state from the underlying control
700
+ _refreshOption: function(item,disabled,selected) {
701
+ var aParent = item.parent();
702
+ // account for enabled/disabled
703
+ if ( disabled ) {
704
+ item.attr("disabled","disabled");
705
+ item.removeClass("active");
706
+ item.addClass("inactive");
707
+ aParent.addClass("ui-state-disabled");
708
+ } else {
709
+ item.removeAttr("disabled");
710
+ item.removeClass("inactive");
711
+ item.addClass("active");
712
+ aParent.removeClass("ui-state-disabled");
713
+ }
714
+ // adjust the checkbox state
715
+ item.attr("checked",selected);
716
+ },
717
+ _refreshGroup: function(group,disabled) {
718
+ if ( disabled ) {
719
+ group.addClass("ui-state-disabled");
720
+ } else {
721
+ group.removeClass("ui-state-disabled");
722
+ }
723
+ },
724
+ refresh: function() {
725
+ var self = this, sourceSelect = this.sourceSelect, dropWrapper = this.dropWrapper;
726
+
727
+ var allCheckBoxes = dropWrapper.find("input");
728
+ var allGroups = dropWrapper.find(".ui-dropdownchecklist-group");
729
+
730
+ var groupCount = 0;
731
+ var optionCount = 0;
732
+ sourceSelect.children().each(function(index) {
733
+ var opt = $(this);
734
+ var disabled = opt.attr("disabled");
735
+ if (opt.is("option")) {
736
+ var selected = opt.attr("selected");
737
+ var anItem = $(allCheckBoxes[optionCount]);
738
+ self._refreshOption(anItem, disabled, selected);
739
+ optionCount += 1;
740
+ } else if (opt.is("optgroup")) {
741
+ var text = opt.attr("label");
742
+ if (text != "") {
743
+ var aGroup = $(allGroups[groupCount]);
744
+ self._refreshGroup(aGroup, disabled);
745
+ groupCount += 1;
746
+ }
747
+ opt.children("option").each(function(subindex) {
748
+ var subopt = $(this);
749
+ var subdisabled = (disabled || subopt.attr("disabled"));
750
+ var selected = subopt.attr("selected");
751
+ var subItem = $(allCheckBoxes[optionCount + subindex]);
752
+ self._refreshOption(subItem, subdisabled, selected );
753
+ });
754
+ }
755
+ });
756
+ // update the text shown in the control
757
+ self._updateControlText();
758
+ },
759
+ enable: function() {
760
+ this.controlSelector.removeClass("ui-state-disabled");
761
+ this.disabled = false;
762
+ },
763
+ disable: function() {
764
+ this.controlSelector.addClass("ui-state-disabled");
765
+ this.disabled = true;
766
+ },
767
+ destroy: function() {
768
+ $.Widget.prototype.destroy.apply(this, arguments);
769
+ this.sourceSelect.css("display", this.initialDisplay);
770
+ this.sourceSelect.attr("multiple", this.initialMultiple);
771
+ this.controlWrapper.unbind().remove();
772
+ this.dropWrapper.remove();
773
+ }
774
+ });
775
+
776
+ $.extend($.ui.dropdownchecklist, {
777
+ defaults: {
778
+ width: null,
779
+ maxDropHeight: null,
780
+ firstItemChecksAll: false,
781
+ closeRadioOnClick: false,
782
+ minWidth: 50,
783
+ bgiframe: false
784
+ }
785
+ });
786
+
787
+ })(jQuery);