sunrise-cms 0.6.3 → 0.6.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/CHANGELOG.rdoc +5 -0
  2. data/app/assets/javascripts/sunrise/application.js +6 -4
  3. data/{vendor/assets/javascripts → app/assets/javascripts/sunrise}/chosen.jquery.js +254 -113
  4. data/app/assets/javascripts/sunrise/chosen.overflow.fix.js +66 -0
  5. data/{vendor/assets/javascripts → app/assets/javascripts/sunrise}/jquery-ui-timepicker-addon.js +0 -0
  6. data/{vendor/assets/javascripts → app/assets/javascripts/sunrise}/jquery.cookie.js +0 -0
  7. data/{vendor/assets/javascripts → app/assets/javascripts/sunrise}/jquery.tmpl.min.js +0 -0
  8. data/app/assets/javascripts/sunrise/manage.js.coffee +5 -1
  9. data/app/assets/stylesheets/sunrise/application.css +3 -1
  10. data/{vendor/assets/stylesheets → app/assets/stylesheets/sunrise}/chosen.css +3 -3
  11. data/app/assets/stylesheets/sunrise/customize.css +41 -0
  12. data/app/assets/stylesheets/sunrise/pagination.css +145 -0
  13. data/app/assets/stylesheets/sunrise/plugins.css +0 -0
  14. data/app/views/kaminari/sunrise/_first_page.html.erb +2 -0
  15. data/app/views/kaminari/sunrise/_gap.html.erb +2 -0
  16. data/app/views/kaminari/sunrise/_last_page.html.erb +2 -0
  17. data/app/views/kaminari/sunrise/_next_page.html.erb +3 -1
  18. data/app/views/kaminari/sunrise/_page.html.erb +7 -3
  19. data/app/views/kaminari/sunrise/_paginator.html.erb +12 -10
  20. data/app/views/kaminari/sunrise/_prev_page.html.erb +4 -1
  21. data/app/views/sunrise/manager/table/index.html.erb +1 -1
  22. data/app/views/sunrise/manager/thumbs/index.html.erb +1 -1
  23. data/lib/sunrise/version.rb +1 -1
  24. data/spec/dummy/log/test.log +3027 -0
  25. data/spec/dummy/public/uploads/avatar/content_rails.png +0 -0
  26. data/spec/dummy/public/uploads/avatar/rails.png +0 -0
  27. data/spec/dummy/public/uploads/avatar/thumb_rails.png +0 -0
  28. data/spec/dummy/public/uploads/tmp/20130329-1713-12193-1429/rails.png +0 -0
  29. data/spec/dummy/public/uploads/tmp/20130329-1713-12193-1429/small_rails.png +0 -0
  30. data/spec/dummy/public/uploads/tmp/20130329-1713-12193-1429/thumb_rails.png +0 -0
  31. data/spec/dummy/public/uploads/tmp/20130329-1713-12193-2911/silicon_valley.jpg +0 -0
  32. data/spec/dummy/public/uploads/tmp/20130329-1713-12193-2911/small_silicon_valley.jpg +0 -0
  33. data/spec/dummy/public/uploads/tmp/20130329-1713-12193-2911/thumb_silicon_valley.jpg +0 -0
  34. data/spec/dummy/public/uploads/tmp/20130329-1713-12193-3054/rails.png +0 -0
  35. data/spec/dummy/public/uploads/tmp/20130329-1713-12193-3369/rails.png +0 -0
  36. data/spec/dummy/public/uploads/tmp/20130329-1713-12193-4170/rails.png +0 -0
  37. data/spec/dummy/public/uploads/tmp/20130329-1713-12193-4170/small_rails.png +0 -0
  38. data/spec/dummy/public/uploads/tmp/20130329-1713-12193-4170/thumb_rails.png +0 -0
  39. data/spec/dummy/public/uploads/tmp/20130329-1713-12193-7130/rails.png +0 -0
  40. data/spec/dummy/public/uploads/tmp/20130329-1713-12193-7130/small_rails.png +0 -0
  41. data/spec/dummy/public/uploads/tmp/20130329-1713-12193-7130/thumb_rails.png +0 -0
  42. data/spec/dummy/public/uploads/tmp/20130329-1714-12193-2865/rails.png +0 -0
  43. data/spec/dummy/public/uploads/tmp/20130329-1714-12193-3844/rails.png +0 -0
  44. data/spec/dummy/public/uploads/tmp/20130329-1714-12193-6957/rails.png +0 -0
  45. data/vendor/assets/images/sunrise/chosen-sprite.png +0 -0
  46. data/vendor/assets/images/sunrise/chosen-sprite@2x.png +0 -0
  47. metadata +45 -7
@@ -1,3 +1,8 @@
1
+ == 0.6.4
2
+ * Pagination style via twitter bootstrap
3
+ * Use chosen for all selects
4
+ * Fix datetime select
5
+
1
6
  == 0.6.3
2
7
  * Special layout for devise login page
3
8
  * Add controls buttons for record
@@ -2,12 +2,14 @@
2
2
  //= require jquery_ujs
3
3
  //= require jquery-ui
4
4
 
5
- //= require jquery.tmpl.min
6
- //= require jquery.cookie
7
- //= require jquery-ui-timepicker-addon
5
+ //= require sunrise/jquery.tmpl.min
6
+ //= require sunrise/jquery.cookie
7
+ //= require sunrise/jquery-ui-timepicker-addon
8
+ //= require sunrise/chosen.jquery
9
+ //= require sunrise/chosen.overflow.fix
10
+
8
11
  //= require datepicker/jquery.ui.datepicker-uk
9
12
  //= require datepicker/jquery.ui.datepicker-ru
10
- //= require chosen.jquery
11
13
 
12
14
  //= require sunrise/jquery.editable
13
15
  //= require sunrise/jquery.dialog
@@ -1,7 +1,7 @@
1
1
  // Chosen, a Select Box Enhancer for jQuery and Protoype
2
2
  // by Patrick Filler for Harvest, http://getharvest.com
3
3
  //
4
- // Version 0.9.7
4
+ // Version 0.9.12
5
5
  // Full source at https://github.com/harvesthq/chosen
6
6
  // Copyright (c) 2011 Harvest http://getharvest.com
7
7
 
@@ -18,7 +18,7 @@
18
18
  }
19
19
 
20
20
  SelectParser.prototype.add_node = function(child) {
21
- if (child.nodeName === "OPTGROUP") {
21
+ if (child.nodeName.toUpperCase() === "OPTGROUP") {
22
22
  return this.add_group(child);
23
23
  } else {
24
24
  return this.add_option(child);
@@ -45,9 +45,11 @@
45
45
  };
46
46
 
47
47
  SelectParser.prototype.add_option = function(option, group_position, group_disabled) {
48
- if (option.nodeName === "OPTION") {
48
+ if (option.nodeName.toUpperCase() === "OPTION") {
49
49
  if (option.text !== "") {
50
- if (group_position != null) this.parsed[group_position].children += 1;
50
+ if (group_position != null) {
51
+ this.parsed[group_position].children += 1;
52
+ }
51
53
  this.parsed.push({
52
54
  array_index: this.parsed.length,
53
55
  options_index: this.options_index,
@@ -95,6 +97,7 @@ Chosen source: generate output using 'cake build'
95
97
  Copyright (c) 2011 by Harvest
96
98
  */
97
99
 
100
+
98
101
  (function() {
99
102
  var AbstractChosen, root;
100
103
 
@@ -105,9 +108,9 @@ Copyright (c) 2011 by Harvest
105
108
  function AbstractChosen(form_field, options) {
106
109
  this.form_field = form_field;
107
110
  this.options = options != null ? options : {};
108
- this.set_default_values();
109
111
  this.is_multiple = this.form_field.multiple;
110
- this.default_text_default = this.is_multiple ? "Select Some Options" : "Select an Option";
112
+ this.set_default_text();
113
+ this.set_default_values();
111
114
  this.setup();
112
115
  this.set_up_html();
113
116
  this.register_observers();
@@ -129,8 +132,24 @@ Copyright (c) 2011 by Harvest
129
132
  this.result_single_selected = null;
130
133
  this.allow_single_deselect = (this.options.allow_single_deselect != null) && (this.form_field.options[0] != null) && this.form_field.options[0].text === "" ? this.options.allow_single_deselect : false;
131
134
  this.disable_search_threshold = this.options.disable_search_threshold || 0;
135
+ this.disable_search = this.options.disable_search || false;
136
+ this.enable_split_word_search = this.options.enable_split_word_search != null ? this.options.enable_split_word_search : true;
137
+ this.search_contains = this.options.search_contains || false;
132
138
  this.choices = 0;
133
- return this.results_none_found = this.options.no_results_text || "No results match";
139
+ this.single_backstroke_delete = this.options.single_backstroke_delete || false;
140
+ this.max_selected_options = this.options.max_selected_options || Infinity;
141
+ return this.inherit_select_classes = this.options.inherit_select_classes || false;
142
+ };
143
+
144
+ AbstractChosen.prototype.set_default_text = function() {
145
+ if (this.form_field.getAttribute("data-placeholder")) {
146
+ this.default_text = this.form_field.getAttribute("data-placeholder");
147
+ } else if (this.is_multiple) {
148
+ this.default_text = this.options.placeholder_text_multiple || this.options.placeholder_text || "Select Some Options";
149
+ } else {
150
+ this.default_text = this.options.placeholder_text_single || this.options.placeholder_text || "Select an Option";
151
+ }
152
+ return this.results_none_found = this.form_field.getAttribute("data-no_results_text") || this.options.no_results_text || "No results match";
134
153
  };
135
154
 
136
155
  AbstractChosen.prototype.mouse_enter = function() {
@@ -143,10 +162,16 @@ Copyright (c) 2011 by Harvest
143
162
 
144
163
  AbstractChosen.prototype.input_focus = function(evt) {
145
164
  var _this = this;
146
- if (!this.active_field) {
147
- return setTimeout((function() {
148
- return _this.container_mousedown();
149
- }), 50);
165
+ if (this.is_multiple) {
166
+ if (!this.active_field) {
167
+ return setTimeout((function() {
168
+ return _this.container_mousedown();
169
+ }), 50);
170
+ }
171
+ } else {
172
+ if (!this.active_field) {
173
+ return this.activate_field();
174
+ }
150
175
  }
151
176
  };
152
177
 
@@ -165,9 +190,15 @@ Copyright (c) 2011 by Harvest
165
190
  if (!option.disabled) {
166
191
  option.dom_id = this.container_id + "_o_" + option.array_index;
167
192
  classes = option.selected && this.is_multiple ? [] : ["active-result"];
168
- if (option.selected) classes.push("result-selected");
169
- if (option.group_array_index != null) classes.push("group-option");
170
- if (option.classes !== "") classes.push(option.classes);
193
+ if (option.selected) {
194
+ classes.push("result-selected");
195
+ }
196
+ if (option.group_array_index != null) {
197
+ classes.push("group-option");
198
+ }
199
+ if (option.classes !== "") {
200
+ classes.push(option.classes);
201
+ }
171
202
  style = option.style.cssText !== "" ? " style=\"" + option.style + "\"" : "";
172
203
  return '<li id="' + option.dom_id + '" class="' + classes.join(' ') + '"' + style + '>' + option.html + '</li>';
173
204
  } else {
@@ -176,6 +207,10 @@ Copyright (c) 2011 by Harvest
176
207
  };
177
208
 
178
209
  AbstractChosen.prototype.results_update_field = function() {
210
+ this.set_default_text();
211
+ if (!this.is_multiple) {
212
+ this.results_reset_cleanup();
213
+ }
179
214
  this.result_clear_highlight();
180
215
  this.result_single_selected = null;
181
216
  return this.results_build();
@@ -212,10 +247,14 @@ Copyright (c) 2011 by Harvest
212
247
  break;
213
248
  case 13:
214
249
  evt.preventDefault();
215
- if (this.results_showing) return this.result_select(evt);
250
+ if (this.results_showing) {
251
+ return this.result_select(evt);
252
+ }
216
253
  break;
217
254
  case 27:
218
- if (this.results_showing) this.results_hide();
255
+ if (this.results_showing) {
256
+ this.results_hide();
257
+ }
219
258
  return true;
220
259
  case 9:
221
260
  case 38:
@@ -238,7 +277,7 @@ Copyright (c) 2011 by Harvest
238
277
 
239
278
  AbstractChosen.prototype.generate_random_char = function() {
240
279
  var chars, newchar, rand;
241
- chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZ";
280
+ chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
242
281
  rand = Math.floor(Math.random() * chars.length);
243
282
  return newchar = chars.substring(rand, rand + 1);
244
283
  };
@@ -256,10 +295,11 @@ Chosen source: generate output using 'cake build'
256
295
  Copyright (c) 2011 by Harvest
257
296
  */
258
297
 
298
+
259
299
  (function() {
260
300
  var $, Chosen, get_side_border_padding, root,
261
- __hasProp = Object.prototype.hasOwnProperty,
262
- __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
301
+ __hasProp = {}.hasOwnProperty,
302
+ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
263
303
 
264
304
  root = this;
265
305
 
@@ -267,11 +307,22 @@ Copyright (c) 2011 by Harvest
267
307
 
268
308
  $.fn.extend({
269
309
  chosen: function(options) {
270
- if ($.browser.msie && ($.browser.version === "6.0" || $.browser.version === "7.0")) {
310
+ var browser, match, ua;
311
+ ua = navigator.userAgent.toLowerCase();
312
+ match = /(msie) ([\w.]+)/.exec(ua) || [];
313
+ browser = {
314
+ name: match[1] || "",
315
+ version: match[2] || "0"
316
+ };
317
+ if (browser.name === "msie" && (browser.version === "6.0" || (browser.version === "7.0" && document.documentMode === 7))) {
271
318
  return this;
272
319
  }
273
- return $(this).each(function(input_field) {
274
- if (!($(this)).hasClass("chzn-done")) return new Chosen(this, options);
320
+ return this.each(function(input_field) {
321
+ var $this;
322
+ $this = $(this);
323
+ if (!$this.hasClass("chzn-done")) {
324
+ return $this.data('chosen', new Chosen(this, options));
325
+ }
275
326
  });
276
327
  }
277
328
  });
@@ -281,11 +332,12 @@ Copyright (c) 2011 by Harvest
281
332
  __extends(Chosen, _super);
282
333
 
283
334
  function Chosen() {
284
- Chosen.__super__.constructor.apply(this, arguments);
335
+ return Chosen.__super__.constructor.apply(this, arguments);
285
336
  }
286
337
 
287
338
  Chosen.prototype.setup = function() {
288
339
  this.form_field_jq = $(this.form_field);
340
+ this.current_value = this.form_field_jq.val();
289
341
  return this.is_rtl = this.form_field_jq.hasClass("chzn-rtl");
290
342
  };
291
343
 
@@ -294,27 +346,32 @@ Copyright (c) 2011 by Harvest
294
346
  };
295
347
 
296
348
  Chosen.prototype.set_up_html = function() {
297
- var container_div, dd_top, dd_width, sf_width;
298
- this.container_id = this.form_field.id.length ? this.form_field.id.replace(/(:|\.)/g, '_') : this.generate_field_id();
349
+ var container_classes, container_div, container_props, dd_top, dd_width, sf_width;
350
+ this.container_id = this.form_field.id.length ? this.form_field.id.replace(/[^\w]/g, '_') : this.generate_field_id();
299
351
  this.container_id += "_chzn";
352
+ container_classes = ["chzn-container"];
353
+ container_classes.push("chzn-container-" + (this.is_multiple ? "multi" : "single"));
354
+ if (this.inherit_select_classes && this.form_field.className) {
355
+ container_classes.push(this.form_field.className);
356
+ }
357
+ if (this.is_rtl) {
358
+ container_classes.push("chzn-rtl");
359
+ }
300
360
  this.f_width = this.form_field_jq.outerWidth();
301
- this.default_text = this.form_field_jq.data('placeholder') ? this.form_field_jq.data('placeholder') : this.default_text_default;
302
- container_div = $("<div />", {
361
+ container_props = {
303
362
  id: this.container_id,
304
- "class": "chzn-container" + (this.is_rtl ? ' chzn-rtl' : ''),
305
- style: 'width: ' + this.f_width + 'px;'
306
- });
363
+ "class": container_classes.join(' '),
364
+ style: 'width: ' + this.f_width + 'px;',
365
+ title: this.form_field.title
366
+ };
367
+ container_div = $("<div />", container_props);
307
368
  if (this.is_multiple) {
308
369
  container_div.html('<ul class="chzn-choices"><li class="search-field"><input type="text" value="' + this.default_text + '" class="default" autocomplete="off" style="width:25px;" /></li></ul><div class="chzn-drop" style="left:-9000px;"><ul class="chzn-results"></ul></div>');
309
370
  } else {
310
- container_div.html('<a href="javascript:void(0)" class="chzn-single"><span>' + this.default_text + '</span><div><b></b></div></a><div class="chzn-drop" style="left:-9000px;"><div class="chzn-search"><input type="text" autocomplete="off" /></div><ul class="chzn-results"></ul></div>');
371
+ container_div.html('<a href="javascript:void(0)" class="chzn-single chzn-default" tabindex="-1"><span>' + this.default_text + '</span><div><b></b></div></a><div class="chzn-drop" style="left:-9000px;"><div class="chzn-search"><input type="text" autocomplete="off" /></div><ul class="chzn-results"></ul></div>');
311
372
  }
312
373
  this.form_field_jq.hide().after(container_div);
313
- //this.form_field_jq.hide();
314
- //$('body').append(container_div);
315
-
316
374
  this.container = $('#' + this.container_id);
317
- this.container.addClass("chzn-container-" + (this.is_multiple ? "multi" : "single"));
318
375
  this.dropdown = this.container.find('div.chzn-drop').first();
319
376
  dd_top = this.container.height();
320
377
  dd_width = this.f_width - get_side_border_padding(this.dropdown);
@@ -347,48 +404,54 @@ Copyright (c) 2011 by Harvest
347
404
  Chosen.prototype.register_observers = function() {
348
405
  var _this = this;
349
406
  this.container.mousedown(function(evt) {
350
- return _this.container_mousedown(evt);
407
+ _this.container_mousedown(evt);
351
408
  });
352
409
  this.container.mouseup(function(evt) {
353
- return _this.container_mouseup(evt);
410
+ _this.container_mouseup(evt);
354
411
  });
355
412
  this.container.mouseenter(function(evt) {
356
- return _this.mouse_enter(evt);
413
+ _this.mouse_enter(evt);
357
414
  });
358
415
  this.container.mouseleave(function(evt) {
359
- return _this.mouse_leave(evt);
416
+ _this.mouse_leave(evt);
360
417
  });
361
418
  this.search_results.mouseup(function(evt) {
362
- return _this.search_results_mouseup(evt);
419
+ _this.search_results_mouseup(evt);
363
420
  });
364
421
  this.search_results.mouseover(function(evt) {
365
- return _this.search_results_mouseover(evt);
422
+ _this.search_results_mouseover(evt);
366
423
  });
367
424
  this.search_results.mouseout(function(evt) {
368
- return _this.search_results_mouseout(evt);
425
+ _this.search_results_mouseout(evt);
369
426
  });
370
427
  this.form_field_jq.bind("liszt:updated", function(evt) {
371
- return _this.results_update_field(evt);
428
+ _this.results_update_field(evt);
429
+ });
430
+ this.form_field_jq.bind("liszt:activate", function(evt) {
431
+ _this.activate_field(evt);
432
+ });
433
+ this.form_field_jq.bind("liszt:open", function(evt) {
434
+ _this.container_mousedown(evt);
372
435
  });
373
436
  this.search_field.blur(function(evt) {
374
- return _this.input_blur(evt);
437
+ _this.input_blur(evt);
375
438
  });
376
439
  this.search_field.keyup(function(evt) {
377
- return _this.keyup_checker(evt);
440
+ _this.keyup_checker(evt);
378
441
  });
379
442
  this.search_field.keydown(function(evt) {
380
- return _this.keydown_checker(evt);
443
+ _this.keydown_checker(evt);
444
+ });
445
+ this.search_field.focus(function(evt) {
446
+ _this.input_focus(evt);
381
447
  });
382
448
  if (this.is_multiple) {
383
- this.search_choices.click(function(evt) {
384
- return _this.choices_click(evt);
385
- });
386
- return this.search_field.focus(function(evt) {
387
- return _this.input_focus(evt);
449
+ return this.search_choices.click(function(evt) {
450
+ _this.choices_click(evt);
388
451
  });
389
452
  } else {
390
453
  return this.container.click(function(evt) {
391
- return evt.preventDefault();
454
+ evt.preventDefault();
392
455
  });
393
456
  }
394
457
  };
@@ -415,10 +478,14 @@ Copyright (c) 2011 by Harvest
415
478
  var target_closelink;
416
479
  if (!this.is_disabled) {
417
480
  target_closelink = evt != null ? ($(evt.target)).hasClass("search-choice-close") : false;
418
- if (evt && evt.type === "mousedown") evt.stopPropagation();
481
+ if (evt && evt.type === "mousedown" && !this.results_showing) {
482
+ evt.preventDefault();
483
+ }
419
484
  if (!this.pending_destroy_click && !target_closelink) {
420
485
  if (!this.active_field) {
421
- if (this.is_multiple) this.search_field.val("");
486
+ if (this.is_multiple) {
487
+ this.search_field.val("");
488
+ }
422
489
  $(document).click(this.click_test_action);
423
490
  this.results_show();
424
491
  } else if (!this.is_multiple && evt && (($(evt.target)[0] === this.selected_item[0]) || $(evt.target).parents("a.chzn-single").length)) {
@@ -433,7 +500,9 @@ Copyright (c) 2011 by Harvest
433
500
  };
434
501
 
435
502
  Chosen.prototype.container_mouseup = function(evt) {
436
- if (evt.target.nodeName === "ABBR") return this.results_reset(evt);
503
+ if (evt.target.nodeName === "ABBR" && !this.is_disabled) {
504
+ return this.results_reset(evt);
505
+ }
437
506
  };
438
507
 
439
508
  Chosen.prototype.blur_test = function(evt) {
@@ -444,10 +513,6 @@ Copyright (c) 2011 by Harvest
444
513
 
445
514
  Chosen.prototype.close_field = function() {
446
515
  $(document).unbind("click", this.click_test_action);
447
- if (!this.is_multiple) {
448
- this.selected_item.attr("tabindex", this.search_field.attr("tabindex"));
449
- this.search_field.attr("tabindex", -1);
450
- }
451
516
  this.active_field = false;
452
517
  this.results_hide();
453
518
  this.container.removeClass("chzn-container-active");
@@ -458,10 +523,6 @@ Copyright (c) 2011 by Harvest
458
523
  };
459
524
 
460
525
  Chosen.prototype.activate_field = function() {
461
- if (!this.is_multiple && !this.active_field) {
462
- this.search_field.attr("tabindex", this.selected_item.attr("tabindex"));
463
- this.selected_item.attr("tabindex", -1);
464
- }
465
526
  this.container.addClass("chzn-container-active");
466
527
  this.active_field = true;
467
528
  this.search_field.val(this.search_field.val());
@@ -484,8 +545,8 @@ Copyright (c) 2011 by Harvest
484
545
  this.search_choices.find("li.search-choice").remove();
485
546
  this.choices = 0;
486
547
  } else if (!this.is_multiple) {
487
- this.selected_item.find("span").text(this.default_text);
488
- if (this.form_field.options.length <= this.disable_search_threshold) {
548
+ this.selected_item.addClass("chzn-default").find("span").text(this.default_text);
549
+ if (this.disable_search || this.form_field.options.length <= this.disable_search_threshold) {
489
550
  this.container.addClass("chzn-container-single-nosearch");
490
551
  } else {
491
552
  this.container.removeClass("chzn-container-single-nosearch");
@@ -502,8 +563,10 @@ Copyright (c) 2011 by Harvest
502
563
  if (data.selected && this.is_multiple) {
503
564
  this.choice_build(data);
504
565
  } else if (data.selected && !this.is_multiple) {
505
- this.selected_item.find("span").text(data.text);
506
- if (this.allow_single_deselect) this.single_deselect_control_build();
566
+ this.selected_item.removeClass("chzn-default").find("span").text(data.text);
567
+ if (this.allow_single_deselect) {
568
+ this.single_deselect_control_build();
569
+ }
507
570
  }
508
571
  }
509
572
  }
@@ -543,7 +606,9 @@ Copyright (c) 2011 by Harvest
543
606
  };
544
607
 
545
608
  Chosen.prototype.result_clear_highlight = function() {
546
- if (this.result_highlight) this.result_highlight.removeClass("highlighted");
609
+ if (this.result_highlight) {
610
+ this.result_highlight.removeClass("highlighted");
611
+ }
547
612
  return this.result_highlight = null;
548
613
  };
549
614
 
@@ -554,8 +619,16 @@ Copyright (c) 2011 by Harvest
554
619
  if (this.result_single_selected) {
555
620
  this.result_do_highlight(this.result_single_selected);
556
621
  }
622
+ } else if (this.max_selected_options <= this.choices) {
623
+ this.form_field_jq.trigger("liszt:maxselected", {
624
+ chosen: this
625
+ });
626
+ return false;
557
627
  }
558
628
  dd_top = this.is_multiple ? this.container.height() : this.container.height() - 1;
629
+ this.form_field_jq.trigger("liszt:showing_dropdown", {
630
+ chosen: this
631
+ });
559
632
  this.dropdown.css({
560
633
  "top": dd_top + "px",
561
634
  "left": 0
@@ -571,6 +644,9 @@ Copyright (c) 2011 by Harvest
571
644
  this.selected_item.removeClass("chzn-single-with-drop");
572
645
  }
573
646
  this.result_clear_highlight();
647
+ this.form_field_jq.trigger("liszt:hiding_dropdown", {
648
+ chosen: this
649
+ });
574
650
  this.dropdown.css({
575
651
  "left": "-9000px"
576
652
  });
@@ -582,12 +658,7 @@ Copyright (c) 2011 by Harvest
582
658
  if (this.form_field_jq.attr("tabindex")) {
583
659
  ti = this.form_field_jq.attr("tabindex");
584
660
  this.form_field_jq.attr("tabindex", -1);
585
- if (this.is_multiple) {
586
- return this.search_field.attr("tabindex", ti);
587
- } else {
588
- this.selected_item.attr("tabindex", ti);
589
- return this.search_field.attr("tabindex", -1);
590
- }
661
+ return this.search_field.attr("tabindex", ti);
591
662
  }
592
663
  };
593
664
 
@@ -606,14 +677,17 @@ Copyright (c) 2011 by Harvest
606
677
  target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
607
678
  if (target.length) {
608
679
  this.result_highlight = target;
609
- return this.result_select(evt);
680
+ this.result_select(evt);
681
+ return this.search_field.focus();
610
682
  }
611
683
  };
612
684
 
613
685
  Chosen.prototype.search_results_mouseover = function(evt) {
614
686
  var target;
615
687
  target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
616
- if (target) return this.result_do_highlight(target);
688
+ if (target) {
689
+ return this.result_do_highlight(target);
690
+ }
617
691
  };
618
692
 
619
693
  Chosen.prototype.search_results_mouseout = function(evt) {
@@ -630,11 +704,22 @@ Copyright (c) 2011 by Harvest
630
704
  };
631
705
 
632
706
  Chosen.prototype.choice_build = function(item) {
633
- var choice_id, link,
707
+ var choice_id, html, link,
634
708
  _this = this;
709
+ if (this.is_multiple && this.max_selected_options <= this.choices) {
710
+ this.form_field_jq.trigger("liszt:maxselected", {
711
+ chosen: this
712
+ });
713
+ return false;
714
+ }
635
715
  choice_id = this.container_id + "_c_" + item.array_index;
636
716
  this.choices += 1;
637
- this.search_container.before('<li class="search-choice" id="' + choice_id + '"><span>' + item.html + '</span><a href="javascript:void(0)" class="search-choice-close" rel="' + item.array_index + '"></a></li>');
717
+ if (item.disabled) {
718
+ html = '<li class="search-choice search-choice-disabled" id="' + choice_id + '"><span>' + item.html + '</span></li>';
719
+ } else {
720
+ html = '<li class="search-choice" id="' + choice_id + '"><span>' + item.html + '</span><a href="javascript:void(0)" class="search-choice-close" rel="' + item.array_index + '"></a></li>';
721
+ }
722
+ this.search_container.before(html);
638
723
  link = $('#' + choice_id).find("a").first();
639
724
  return link.click(function(evt) {
640
725
  return _this.choice_destroy_link_click(evt);
@@ -652,22 +737,34 @@ Copyright (c) 2011 by Harvest
652
737
  };
653
738
 
654
739
  Chosen.prototype.choice_destroy = function(link) {
655
- this.choices -= 1;
656
- this.show_search_field_default();
657
- if (this.is_multiple && this.choices > 0 && this.search_field.val().length < 1) {
658
- this.results_hide();
740
+ if (this.result_deselect(link.attr("rel"))) {
741
+ this.choices -= 1;
742
+ this.show_search_field_default();
743
+ if (this.is_multiple && this.choices > 0 && this.search_field.val().length < 1) {
744
+ this.results_hide();
745
+ }
746
+ link.parents('li').first().remove();
747
+ return this.search_field_scale();
659
748
  }
660
- this.result_deselect(link.attr("rel"));
661
- return link.parents('li').first().remove();
662
749
  };
663
750
 
664
- Chosen.prototype.results_reset = function(evt) {
751
+ Chosen.prototype.results_reset = function() {
665
752
  this.form_field.options[0].selected = true;
666
753
  this.selected_item.find("span").text(this.default_text);
754
+ if (!this.is_multiple) {
755
+ this.selected_item.addClass("chzn-default");
756
+ }
667
757
  this.show_search_field_default();
668
- $(evt.target).remove();
758
+ this.results_reset_cleanup();
669
759
  this.form_field_jq.trigger("change");
670
- if (this.active_field) return this.results_hide();
760
+ if (this.active_field) {
761
+ return this.results_hide();
762
+ }
763
+ };
764
+
765
+ Chosen.prototype.results_reset_cleanup = function() {
766
+ this.current_value = this.form_field_jq.val();
767
+ return this.selected_item.find("abbr").remove();
671
768
  };
672
769
 
673
770
  Chosen.prototype.result_select = function(evt) {
@@ -681,6 +778,7 @@ Copyright (c) 2011 by Harvest
681
778
  } else {
682
779
  this.search_results.find(".result-selected").removeClass("result-selected");
683
780
  this.result_single_selected = high;
781
+ this.selected_item.removeClass("chzn-default");
684
782
  }
685
783
  high.addClass("result-selected");
686
784
  position = high_id.substr(high_id.lastIndexOf("_") + 1);
@@ -691,11 +789,20 @@ Copyright (c) 2011 by Harvest
691
789
  this.choice_build(item);
692
790
  } else {
693
791
  this.selected_item.find("span").first().text(item.text);
694
- if (this.allow_single_deselect) this.single_deselect_control_build();
792
+ if (this.allow_single_deselect) {
793
+ this.single_deselect_control_build();
794
+ }
795
+ }
796
+ if (!((evt.metaKey || evt.ctrlKey) && this.is_multiple)) {
797
+ this.results_hide();
695
798
  }
696
- if (!(evt.metaKey && this.is_multiple)) this.results_hide();
697
799
  this.search_field.val("");
698
- this.form_field_jq.trigger("change");
800
+ if (this.is_multiple || this.form_field_jq.val() !== this.current_value) {
801
+ this.form_field_jq.trigger("change", {
802
+ 'selected': this.form_field.options[item.options_index].value
803
+ });
804
+ }
805
+ this.current_value = this.form_field_jq.val();
699
806
  return this.search_field_scale();
700
807
  }
701
808
  };
@@ -711,14 +818,21 @@ Copyright (c) 2011 by Harvest
711
818
  Chosen.prototype.result_deselect = function(pos) {
712
819
  var result, result_data;
713
820
  result_data = this.results_data[pos];
714
- result_data.selected = false;
715
- this.form_field.options[result_data.options_index].selected = false;
716
- result = $("#" + this.container_id + "_o_" + pos);
717
- result.removeClass("result-selected").addClass("active-result").show();
718
- this.result_clear_highlight();
719
- this.winnow_results();
720
- this.form_field_jq.trigger("change");
721
- return this.search_field_scale();
821
+ if (!this.form_field.options[result_data.options_index].disabled) {
822
+ result_data.selected = false;
823
+ this.form_field.options[result_data.options_index].selected = false;
824
+ result = $("#" + this.container_id + "_o_" + pos);
825
+ result.removeClass("result-selected").addClass("active-result").show();
826
+ this.result_clear_highlight();
827
+ this.winnow_results();
828
+ this.form_field_jq.trigger("change", {
829
+ deselected: this.form_field.options[result_data.options_index].value
830
+ });
831
+ this.search_field_scale();
832
+ return true;
833
+ } else {
834
+ return false;
835
+ }
722
836
  };
723
837
 
724
838
  Chosen.prototype.single_deselect_control_build = function() {
@@ -728,11 +842,12 @@ Copyright (c) 2011 by Harvest
728
842
  };
729
843
 
730
844
  Chosen.prototype.winnow_results = function() {
731
- var found, option, part, parts, regex, result, result_id, results, searchText, startpos, text, zregex, _i, _j, _len, _len2, _ref;
845
+ var found, option, part, parts, regex, regexAnchor, result, result_id, results, searchText, startpos, text, zregex, _i, _j, _len, _len1, _ref;
732
846
  this.no_results_clear();
733
847
  results = 0;
734
848
  searchText = this.search_field.val() === this.default_text ? "" : $('<div/>').text($.trim(this.search_field.val())).html();
735
- regex = new RegExp('^' + searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
849
+ regexAnchor = this.search_contains ? "" : "^";
850
+ regex = new RegExp(regexAnchor + searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
736
851
  zregex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
737
852
  _ref = this.results_data;
738
853
  for (_i = 0, _len = _ref.length; _i < _len; _i++) {
@@ -747,10 +862,10 @@ Copyright (c) 2011 by Harvest
747
862
  if (regex.test(option.html)) {
748
863
  found = true;
749
864
  results += 1;
750
- } else if (option.html.indexOf(" ") >= 0 || option.html.indexOf("[") === 0) {
865
+ } else if (this.enable_split_word_search && (option.html.indexOf(" ") >= 0 || option.html.indexOf("[") === 0)) {
751
866
  parts = option.html.replace(/\[|\]/g, "").split(" ");
752
867
  if (parts.length) {
753
- for (_j = 0, _len2 = parts.length; _j < _len2; _j++) {
868
+ for (_j = 0, _len1 = parts.length; _j < _len1; _j++) {
754
869
  part = parts[_j];
755
870
  if (regex.test(part)) {
756
871
  found = true;
@@ -812,7 +927,9 @@ Copyright (c) 2011 by Harvest
812
927
  if (!this.result_highlight) {
813
928
  selected_results = !this.is_multiple ? this.search_results.find(".result-selected.active-result") : [];
814
929
  do_high = selected_results.length ? selected_results.first() : this.search_results.find(".active-result").first();
815
- if (do_high != null) return this.result_do_highlight(do_high);
930
+ if (do_high != null) {
931
+ return this.result_do_highlight(do_high);
932
+ }
816
933
  }
817
934
  };
818
935
 
@@ -831,12 +948,18 @@ Copyright (c) 2011 by Harvest
831
948
  var first_active, next_sib;
832
949
  if (!this.result_highlight) {
833
950
  first_active = this.search_results.find("li.active-result").first();
834
- if (first_active) this.result_do_highlight($(first_active));
951
+ if (first_active) {
952
+ this.result_do_highlight($(first_active));
953
+ }
835
954
  } else if (this.results_showing) {
836
955
  next_sib = this.result_highlight.nextAll("li.active-result").first();
837
- if (next_sib) this.result_do_highlight(next_sib);
956
+ if (next_sib) {
957
+ this.result_do_highlight(next_sib);
958
+ }
959
+ }
960
+ if (!this.results_showing) {
961
+ return this.results_show();
838
962
  }
839
- if (!this.results_showing) return this.results_show();
840
963
  };
841
964
 
842
965
  Chosen.prototype.keyup_arrow = function() {
@@ -848,19 +971,29 @@ Copyright (c) 2011 by Harvest
848
971
  if (prev_sibs.length) {
849
972
  return this.result_do_highlight(prev_sibs.first());
850
973
  } else {
851
- if (this.choices > 0) this.results_hide();
974
+ if (this.choices > 0) {
975
+ this.results_hide();
976
+ }
852
977
  return this.result_clear_highlight();
853
978
  }
854
979
  }
855
980
  };
856
981
 
857
982
  Chosen.prototype.keydown_backstroke = function() {
983
+ var next_available_destroy;
858
984
  if (this.pending_backstroke) {
859
985
  this.choice_destroy(this.pending_backstroke.find("a").first());
860
986
  return this.clear_backstroke();
861
987
  } else {
862
- this.pending_backstroke = this.search_container.siblings("li.search-choice").last();
863
- return this.pending_backstroke.addClass("search-choice-focus");
988
+ next_available_destroy = this.search_container.siblings("li.search-choice").last();
989
+ if (next_available_destroy.length && !next_available_destroy.hasClass("search-choice-disabled")) {
990
+ this.pending_backstroke = next_available_destroy;
991
+ if (this.single_backstroke_delete) {
992
+ return this.keydown_backstroke();
993
+ } else {
994
+ return this.pending_backstroke.addClass("search-choice-focus");
995
+ }
996
+ }
864
997
  }
865
998
  };
866
999
 
@@ -875,13 +1008,17 @@ Copyright (c) 2011 by Harvest
875
1008
  var stroke, _ref;
876
1009
  stroke = (_ref = evt.which) != null ? _ref : evt.keyCode;
877
1010
  this.search_field_scale();
878
- if (stroke !== 8 && this.pending_backstroke) this.clear_backstroke();
1011
+ if (stroke !== 8 && this.pending_backstroke) {
1012
+ this.clear_backstroke();
1013
+ }
879
1014
  switch (stroke) {
880
1015
  case 8:
881
1016
  this.backstroke_length = this.search_field.val().length;
882
1017
  break;
883
1018
  case 9:
884
- if (this.results_showing && !this.is_multiple) this.result_select(evt);
1019
+ if (this.results_showing && !this.is_multiple) {
1020
+ this.result_select(evt);
1021
+ }
885
1022
  this.mouse_on_container = false;
886
1023
  break;
887
1024
  case 13:
@@ -915,7 +1052,9 @@ Copyright (c) 2011 by Harvest
915
1052
  $('body').append(div);
916
1053
  w = div.width() + 25;
917
1054
  div.remove();
918
- if (w > this.f_width - 10) w = this.f_width - 10;
1055
+ if (w > this.f_width - 10) {
1056
+ w = this.f_width - 10;
1057
+ }
919
1058
  this.search_field.css({
920
1059
  'width': w + 'px'
921
1060
  });
@@ -939,6 +1078,8 @@ Copyright (c) 2011 by Harvest
939
1078
 
940
1079
  })(AbstractChosen);
941
1080
 
1081
+ root.Chosen = Chosen;
1082
+
942
1083
  get_side_border_padding = function(elmt) {
943
1084
  var side_border_padding;
944
1085
  return side_border_padding = elmt.outerWidth() - elmt.width();
@@ -946,4 +1087,4 @@ Copyright (c) 2011 by Harvest
946
1087
 
947
1088
  root.get_side_border_padding = get_side_border_padding;
948
1089
 
949
- }).call(this);
1090
+ }).call(this);