Permalink
Browse files

Merge with harvestq master

  • Loading branch information...
Goutet committed Nov 7, 2012
2 parents 620d1f9 + c481fed commit da3538478f96d2f579c09e82aa973a20b330e668
View
@@ -161,10 +161,14 @@ Copyright (c) 2011 by Harvest
AbstractChosen.prototype.input_focus = function(evt) {
var _this = this;
- if (!this.active_field) {
- return setTimeout((function() {
- return _this.container_mousedown();
- }), 50);
+ if (this.is_multiple) {
+ if (!this.active_field) {
+ return setTimeout((function() {
+ return _this.container_mousedown();
+ }), 50);
+ }
+ } else {
+ if (!this.active_field) return this.activate_field();
}
};
@@ -343,7 +347,7 @@ Copyright (c) 2011 by Harvest
if (this.is_multiple) {
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>');
} else {
- container_div.html('<a href="javascript:void(0)" class="chzn-single chzn-default"><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>');
+ 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>');
}
this.form_field_jq.hide().after(container_div);
this.container = $('#' + this.container_id);
@@ -418,13 +422,13 @@ Copyright (c) 2011 by Harvest
this.search_field.keydown(function(evt) {
return _this.keydown_checker(evt);
});
+ this.search_field.focus(function(evt) {
+ return _this.input_focus(evt);
+ });
if (this.is_multiple) {
- this.search_choices.click(function(evt) {
+ return this.search_choices.click(function(evt) {
return _this.choices_click(evt);
});
- return this.search_field.focus(function(evt) {
- return _this.input_focus(evt);
- });
} else {
return this.container.click(function(evt) {
return evt.preventDefault();
@@ -489,10 +493,6 @@ Copyright (c) 2011 by Harvest
Chosen.prototype.close_field = function() {
$(document).unbind("click", this.click_test_action);
- if (!this.is_multiple) {
- this.selected_item.attr("tabindex", this.search_field.attr("tabindex"));
- this.search_field.attr("tabindex", -1);
- }
this.active_field = false;
this.results_hide();
this.container.removeClass("chzn-container-active");
@@ -503,10 +503,6 @@ Copyright (c) 2011 by Harvest
};
Chosen.prototype.activate_field = function() {
- if (!this.is_multiple && !this.active_field) {
- this.search_field.attr("tabindex", this.selected_item.attr("tabindex"));
- this.selected_item.attr("tabindex", -1);
- }
this.container.addClass("chzn-container-active");
this.active_field = true;
this.search_field.val(this.search_field.val());
@@ -642,12 +638,7 @@ Copyright (c) 2011 by Harvest
if (this.form_field_jq.attr("tabindex")) {
ti = this.form_field_jq.attr("tabindex");
this.form_field_jq.attr("tabindex", -1);
- if (this.is_multiple) {
- return this.search_field.attr("tabindex", ti);
- } else {
- this.selected_item.attr("tabindex", ti);
- return this.search_field.attr("tabindex", -1);
- }
+ return this.search_field.attr("tabindex", ti);
}
};
@@ -666,7 +657,8 @@ Copyright (c) 2011 by Harvest
target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
if (target.length) {
this.result_highlight = target;
- return this.result_select(evt);
+ this.result_select(evt);
+ return this.search_field.focus();
}
};

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -161,10 +161,14 @@ Copyright (c) 2011 by Harvest
AbstractChosen.prototype.input_focus = function(evt) {
var _this = this;
- if (!this.active_field) {
- return setTimeout((function() {
- return _this.container_mousedown();
- }), 50);
+ if (this.is_multiple) {
+ if (!this.active_field) {
+ return setTimeout((function() {
+ return _this.container_mousedown();
+ }), 50);
+ }
+ } else {
+ if (!this.active_field) return this.activate_field();
}
};
@@ -314,7 +318,7 @@ Copyright (c) 2011 by Harvest
Chosen.prototype.set_default_values = function() {
Chosen.__super__.set_default_values.call(this);
- this.single_temp = new Template('<a href="javascript:void(0)" class="chzn-single chzn-default"><span>#{default}</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>');
+ this.single_temp = new Template('<a href="javascript:void(0)" class="chzn-single chzn-default" tabindex="-1"><span>#{default}</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>');
this.multi_temp = new Template('<ul class="chzn-choices"><li class="search-field"><input type="text" value="#{default}" class="default" autocomplete="off" style="width:25px;" /></li></ul><div class="chzn-drop" style="left:-9000px;"><ul class="chzn-results"></ul></div>');
this.choice_temp = new Template('<li class="search-choice" id="#{id}"><span>#{choice}</span><a href="javascript:void(0)" class="search-choice-close" rel="#{position}"></a></li>');
this.choice_noclose_temp = new Template('<li class="search-choice search-choice-disabled" id="#{id}"><span>#{choice}</span></li>');
@@ -410,13 +414,13 @@ Copyright (c) 2011 by Harvest
this.search_field.observe("keydown", function(evt) {
return _this.keydown_checker(evt);
});
+ this.search_field.observe("focus", function(evt) {
+ return _this.input_focus(evt);
+ });
if (this.is_multiple) {
- this.search_choices.observe("click", function(evt) {
+ return this.search_choices.observe("click", function(evt) {
return _this.choices_click(evt);
});
- return this.search_field.observe("focus", function(evt) {
- return _this.input_focus(evt);
- });
} else {
return this.container.observe("click", function(evt) {
return evt.preventDefault();
@@ -480,10 +484,6 @@ Copyright (c) 2011 by Harvest
Chosen.prototype.close_field = function() {
document.stopObserving("click", this.click_test_action);
- if (!this.is_multiple) {
- this.selected_item.tabIndex = this.search_field.tabIndex;
- this.search_field.tabIndex = -1;
- }
this.active_field = false;
this.results_hide();
this.container.removeClassName("chzn-container-active");
@@ -494,10 +494,6 @@ Copyright (c) 2011 by Harvest
};
Chosen.prototype.activate_field = function() {
- if (!this.is_multiple && !this.active_field) {
- this.search_field.tabIndex = this.selected_item.tabIndex;
- this.selected_item.tabIndex = -1;
- }
this.container.addClassName("chzn-container-active");
this.active_field = true;
this.search_field.value = this.search_field.value;
@@ -631,12 +627,7 @@ Copyright (c) 2011 by Harvest
if (this.form_field.tabIndex) {
ti = this.form_field.tabIndex;
this.form_field.tabIndex = -1;
- if (this.is_multiple) {
- return this.search_field.tabIndex = ti;
- } else {
- this.selected_item.tabIndex = ti;
- return this.search_field.tabIndex = -1;
- }
+ return this.search_field.tabIndex = ti;
}
};
@@ -655,7 +646,8 @@ Copyright (c) 2011 by Harvest
target = evt.target.hasClassName("active-result") ? evt.target : evt.target.up(".active-result");
if (target) {
this.result_highlight = target;
- return this.result_select(evt);
+ this.result_select(evt);
+ return this.search_field.focus();
}
};

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -41,7 +41,7 @@ class Chosen extends AbstractChosen
if @is_multiple
container_div.html '<ul class="chzn-choices"><li class="search-field"><input type="text" value="' + @default_text + '" class="default" autocomplete="off" style="width:25px;" /></li></ul><div class="chzn-drop" style="left:-9000px;"><ul class="chzn-results"></ul></div>'
else
- container_div.html '<a href="javascript:void(0)" class="chzn-single chzn-default"><span>' + @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>'
+ container_div.html '<a href="javascript:void(0)" class="chzn-single chzn-default" tabindex="-1"><span>' + @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>'
@form_field_jq.hide().after container_div
@container = ($ '#' + @container_id)
@@ -89,12 +89,13 @@ class Chosen extends AbstractChosen
@search_field.blur (evt) => this.input_blur(evt)
@search_field.keyup (evt) => this.keyup_checker(evt)
@search_field.keydown (evt) => this.keydown_checker(evt)
+ @search_field.focus (evt) => this.input_focus(evt)
if @is_multiple
@search_choices.click (evt) => this.choices_click(evt)
- @search_field.focus (evt) => this.input_focus(evt)
else
@container.click (evt) => evt.preventDefault() # gobble click of anchor
+
search_field_disabled: ->
@is_disabled = @form_field_jq[0].disabled
@@ -135,10 +136,6 @@ class Chosen extends AbstractChosen
close_field: ->
$(document).unbind "click", @click_test_action
- if not @is_multiple
- @selected_item.attr "tabindex", @search_field.attr("tabindex")
- @search_field.attr "tabindex", -1
-
@active_field = false
this.results_hide()
@@ -150,10 +147,6 @@ class Chosen extends AbstractChosen
this.search_field_scale()
activate_field: ->
- if not @is_multiple and not @active_field
- @search_field.attr "tabindex", (@selected_item.attr "tabindex")
- @selected_item.attr "tabindex", -1
-
@container.addClass "chzn-container-active"
@active_field = true
@@ -262,12 +255,7 @@ class Chosen extends AbstractChosen
if @form_field_jq.attr "tabindex"
ti = @form_field_jq.attr "tabindex"
@form_field_jq.attr "tabindex", -1
-
- if @is_multiple
- @search_field.attr "tabindex", ti
- else
- @selected_item.attr "tabindex", ti
- @search_field.attr "tabindex", -1
+ @search_field.attr "tabindex", ti
show_search_field_default: ->
if @is_multiple and @choices < 1 and not @active_field
@@ -282,6 +270,7 @@ class Chosen extends AbstractChosen
if target.length
@result_highlight = target
this.result_select(evt)
+ @search_field.focus()
search_results_mouseover: (evt) ->
target = if $(evt.target).hasClass "active-result" then $(evt.target) else $(evt.target).parents(".active-result").first()
View
@@ -17,7 +17,7 @@ class Chosen extends AbstractChosen
super()
# HTML Templates
- @single_temp = new Template('<a href="javascript:void(0)" class="chzn-single chzn-default"><span>#{default}</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>')
+ @single_temp = new Template('<a href="javascript:void(0)" class="chzn-single chzn-default" tabindex="-1"><span>#{default}</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>')
@multi_temp = new Template('<ul class="chzn-choices"><li class="search-field"><input type="text" value="#{default}" class="default" autocomplete="off" style="width:25px;" /></li></ul><div class="chzn-drop" style="left:-9000px;"><ul class="chzn-results"></ul></div>')
@choice_temp = new Template('<li class="search-choice" id="#{id}"><span>#{choice}</span><a href="javascript:void(0)" class="search-choice-close" rel="#{position}"></a></li>')
@choice_noclose_temp = new Template('<li class="search-choice search-choice-disabled" id="#{id}"><span>#{choice}</span></li>')
@@ -81,10 +81,10 @@ class Chosen extends AbstractChosen
@search_field.observe "blur", (evt) => this.input_blur(evt)
@search_field.observe "keyup", (evt) => this.keyup_checker(evt)
@search_field.observe "keydown", (evt) => this.keydown_checker(evt)
+ @search_field.observe "focus", (evt) => this.input_focus(evt)
if @is_multiple
@search_choices.observe "click", (evt) => this.choices_click(evt)
- @search_field.observe "focus", (evt) => this.input_focus(evt)
else
@container.observe "click", (evt) => evt.preventDefault() # gobble click of anchor
@@ -126,10 +126,6 @@ class Chosen extends AbstractChosen
close_field: ->
document.stopObserving "click", @click_test_action
- if not @is_multiple
- @selected_item.tabIndex = @search_field.tabIndex
- @search_field.tabIndex = -1
-
@active_field = false
this.results_hide()
@@ -141,17 +137,12 @@ class Chosen extends AbstractChosen
this.search_field_scale()
activate_field: ->
- if not @is_multiple and not @active_field
- @search_field.tabIndex = @selected_item.tabIndex
- @selected_item.tabIndex = -1
-
@container.addClassName "chzn-container-active"
@active_field = true
@search_field.value = @search_field.value
@search_field.focus()
-
test_active_click: (evt) ->
if evt.target.up('#' + @container_id)
@active_field = true
@@ -252,12 +243,7 @@ class Chosen extends AbstractChosen
if @form_field.tabIndex
ti = @form_field.tabIndex
@form_field.tabIndex = -1
-
- if @is_multiple
- @search_field.tabIndex = ti
- else
- @selected_item.tabIndex = ti
- @search_field.tabIndex = -1
+ @search_field.tabIndex = ti
show_search_field_default: ->
if @is_multiple and @choices < 1 and not @active_field
@@ -272,6 +258,7 @@ class Chosen extends AbstractChosen
if target
@result_highlight = target
this.result_select(evt)
+ @search_field.focus()
search_results_mouseover: (evt) ->
target = if evt.target.hasClassName("active-result") then evt.target else evt.target.up(".active-result")
Oops, something went wrong.

0 comments on commit da35384

Please sign in to comment.