From 3ab298c322efb699634e6123f237f8adcf79f6ba Mon Sep 17 00:00:00 2001 From: Igor Vaynberg Date: Tue, 14 May 2013 08:50:02 -0700 Subject: [PATCH] catch up to master --- index.html | 225 +++++++++++++++++++++++++++++++++++--------- select2-latest.html | 18 ++-- select2-master | 2 +- 3 files changed, 191 insertions(+), 54 deletions(-) diff --git a/index.html b/index.html index 3b80fe09..5be33e7b 100644 --- a/index.html +++ b/index.html @@ -1,12 +1,12 @@ --- layout: main -title: Select2 3.3.2 +title: Select2 group: navigation -version: 3.3.2 +version: 3.4.0 --- - - + + @@ -223,26 +228,27 @@ $("#e10_3").select2({ -
-

Changelog

-
-
    -
  • Loading...
  • - -
-
-
+ $("#changelog .details").on("click", function() { $("#changelog ul").toggle(); }); + }); + + + +

Browser Compatibility

@@ -525,6 +532,11 @@ $("#e19").select2({ maximumSelectionSize: 3 });

+

data can also itself be a function that returns a results object:

+

+ +

+

Example Code

@@ -574,7 +586,7 @@ $("#e8_get2").click(function () { var data = $("#e8").select2("data"); delete da $("#e8_set2").click(function () { $("#e8").select2("data", {id: "CA", text: "California"}); }); $("#e8_open").click(function () { $("#e8").select2("open"); }); $("#e8_close").click(function () { $("#e8").select2("close"); }); -$("#e8_2").select2(); +$("#e8_2").select2({placeholder: "Select a state"}); $("#e8_2_get").click(function () { alert("Selected value is: "+$("#e8_2").select2("val"));}); $("#e8_2_set").click(function () { $("#e8_2").select2("val", ["CA","MA"]); }); $("#e8_2_get2").click(function () { alert("Selected value is: "+JSON.stringify($("#e8_2").select2("data")));}); @@ -609,7 +621,7 @@ $("#e8_2_close").click(function () { $("#e8_2").select2("close"); });

-
+

@@ -637,11 +649,27 @@ function log(e) { e.animate({opacity:1}, 10000, 'linear', function() { e.animate({opacity:0}, 2000, 'linear', function() {e.remove(); }); }); } $("#e11") - .on("change", function(e) { log(JSON.stringify({val:e.val, added:e.added, removed:e.removed})); }) - .on("open", function() { log("open"); }); + .on("change", function(e) { log("change "+JSON.stringify({val:e.val, added:e.added, removed:e.removed})); }) + .on("select2-opening", function() { log("opening"); }) + .on("select2-open", function() { log("open"); }) + .on("select2-close", function() { log("close"); }) + .on("select2-highlight", function(e) { log ("highlighted val="+ e.val+" choice="+ JSON.stringify(e.choice));}) + .on("select2-selecting", function(e) { log ("selecting val="+ e.val+" choice="+ JSON.stringify(e.choice));}) + .on("select2-removed", function(e) { log ("removed val="+ e.val+" choice="+ JSON.stringify(e.choice));}) + .on("select2-loaded", function(e) { log ("loaded (data property omitted for brevitiy)");}) + .on("select2-focus", function(e) { log ("focus");}) + .on("select2-blur", function(e) { log ("blur");}); $("#e11_2") - .on("change", function(e) { log(JSON.stringify({val:e.val, added:e.added, removed:e.removed})); }) - .on("open", function() { log("open"); }); + .on("change", function(e) { log("change "+JSON.stringify({val:e.val, added:e.added, removed:e.removed})); }) + .on("select2-opening", function() { log("opening"); }) + .on("select2-open", function() { log("open"); }) + .on("select2-close", function() { log("close"); }) + .on("select2-highlight", function(e) { log ("highlighted val="+ e.val+" choice="+ JSON.stringify(e.choice));}) + .on("select2-selecting", function(e) { log ("selecting val="+ e.val+" choice="+ JSON.stringify(e.choice));}) + .on("select2-removed", function(e) { log ("removed val="+ e.val+" choice="+ JSON.stringify(e.choice));}) + .on("select2-loaded", function(e) { log ("loaded (data property omitted for brevitiy)");}) + .on("select2-focus", function(e) { log ("focus");}) + .on("select2-blur", function(e) { log ("blur");}); });
@@ -819,8 +847,11 @@ $("#e15").select2("container").find("ul.select2-choices").sortable({ $(document).ready(function () { $("#e16").select2(); $("#e16_2").select2(); -$("#e16_enable").click(function() { $("#e16,#e16_2").select2("enable"); }); -$("#e16_disable").click(function() { $("#e16,#e16_2").select2("disable"); }); +$("#e16_enable").click(function() { $("#e16,#e16_2").select2("enable", true); }); +$("#e16_disable").click(function() { $("#e16,#e16_2").select2("enable", false); }); +$("#e16_readonly").click(function() { $("#e16,#e16_2").select2("readonly", true); }); +$("#e16_writable").click(function() { $("#e16,#e16_2").select2("readonly", false); }); + });
@@ -828,6 +859,7 @@ $("#e16_disable").click(function() { $("#e16,#e16_2").select2("disable"); });



+

Example Code

@@ -1015,6 +1047,7 @@ $(document).ready(function () { is useful for cases where local data is used with just a few results, in which case the search box is not very useful and wastes screen space.

+

The option can be set to a negative value to permanently hide the search field

Only applies to single-value select boxes

@@ -1082,7 +1115,7 @@ $(document).ready(function () { boolean

- If set to false the dropdown is not closed after a selection is made, allowing for rapid selection of multiple items. By default this option is set to true. + If set to false the dropdown is not closed after a selection is made, allowing for rapid selection of multiple items. By default this option is set to true.

@@ -1321,6 +1354,7 @@ $("#select").select2({

query(options)
+ @@ -1376,6 +1410,8 @@ $("#select").select2({ + +
ParameterTypeDescription
options.elementjquery objectThe element Select2 is attached to
options.termstringSearch string entered by user
options.pageint1-based page number tracked by Select2 for use with infinite scrolling of results
options.contextobjectAn object that persists across the lifecycle of queries for the same search term (the query to retrieve the initial results, and subsequent queries to retrieve more result pages for the same search term). When this function is first called for a new search term this object will be null. The user may choose to set any object in the results.context field - this object will then be used as the context parameter for all calls to the query method that will load more search results for the initial search term. The object will be reset back to null when a new search term is queried. This feature is useful when a page number is not easily mapped against the server side paging mechanism. For example, some server side paging mechanism may return a "continuation token" that needs to be passed back to them in order to retrieve the next page of search results.
urlstring/functionString containing the ajax url or a function that returns such a string.
dataTypestringData type for the request. ajax, jsonp, other formats supported by jquery
quietMillisintNumber of milliseconds to wait for the user to stop typing before issuing the ajax request
cachebooleanIf set to false, it will force requested pages not to be cached by the browser. Default is false
jsonpCallbackstring/functionThe callback function name for a JSONP request. This value will be used instead of the random name automatically generated by jQuery. It is preferable to let jQuery generate a unique name as it'll make it easier to manage the requests and provide callbacks and error handling. You may want to specify the callback when you want to enable better browser caching of GET requests.
datafunction Function to generate query parameters for the ajax request.
data(term, page)
@@ -1398,8 +1434,11 @@ $("#select").select2({
<returns>objectResults object. See "options.callback" in the "query" function for format.
+ paramsobject/functionAn object or a function that returns an object that contains extra parameters that will be passed to the transport. For example it can be used to set the content type: {contentType: "application/json;charset=utf-8"} +

In order for this function to work Select2 should be attached to a input type='hidden' tag instead of a select.

+

For documentation of the data format see the query function

dataarray/object Options for the built in query function that works with arrays. @@ -1425,6 +1464,29 @@ $("#select").select2({ dropdownCssClassfunction/string Css class that will be added to select2's dropdown container + dropdownAutoWidthboolean + When set to true attempts to automatically size the width of the dropdown based on content inside. + + adaptContainerCssClassfunction + Function that filters/renames css classes as they are copied from the source tag to the select2 container tag. +
adaptContainerCssClass(clazz)
+ + + + +
ParameterTypeDescription
clazzstringCss class being copied
<returns>stringCss class to be applied or null/undefined/'' to not apply it
+ The default implementation applies all classes without modification. + + adaptDropdownCssClassfunction + Function that filters/renames css classes as they are copied from the source tag to the select2 dropdown tag. +
adaptDropdownCssClass(clazz)
+ + + + +
ParameterTypeDescription
clazzstringCss class being copied
<returns>stringCss class to be applied or null/undefined/'' to not apply it
+ The default implementation always returns null thereby filtering out all classes. + escapeMarkupfunction String escapeMarkup(String markup)

Function used to post-process markup returned from formatter functions. By default this function escapes html entities to prevent javascript injection.

@@ -1477,6 +1539,8 @@ $("#select").select2({

Gets or sets the selection. Analogous to val method, but works with objects instead of ids.

data method invoked on a single-select with an unset value will return null, while a data method invoked on an empty multi-select will return []

+ +

destroy

@@ -1491,13 +1555,13 @@ $("#select").select2({

Closes the dropdown

-

disable

+

enable(boolean)

-

Disables Select2. During this mode the user is not allowed to manipulate the selection.

+

Enables or disables Select2 and its underlying form component based on the boolean parameter.

-

enable

+

readonly(boolean)

-

Enables Select2.

+

Toggles readonly mode on Select2 and its underlying form component based on the boolean parameter.

container

@@ -1525,7 +1589,6 @@ $("#select").select2({

change

Fired when selection is changed.

-

This event is not fired when the selection is changed using Select2's val() method.

The event object contains the following custom properties:

val
the current selection (taking into account the result of the change) - id or array of ids
@@ -1537,18 +1600,90 @@ $("#select").select2({
-

open

-

Fired when the dropdown is shown.

+

select2-opening

+

Fired before the dropdown is shown.

The event listener can prevent the opening by calling preventDefault() on the supplied event object.

- +
+
+

select2-open

+

Fired after the dropdown is shown.

+

+
+
+
+
+

select2-highlight

+

Fired when a choice is highlighted in the dropdown.

+

+

The event object contains the following custom properties: +

+
val
the id of the highlighted choice object
+
object
the highlighted choice object
+
+

+
+
+
+
+

select2-selecting

+

Fired when a choice is being selected in the dropdown, but before any modification has been made to the selection. + This event is used to allow the user to reject selection by calling event.preventDefault()

+

+

The event object contains the following custom properties: +

+
val
the id of the highlighted choice object
+
object
the choice object about to be selected
+
+

+
+
+
+
+

select2-removed

+

Fired when a choice is removed or cleared

+

+

The event object contains the following custom properties: +

+
val
the id of the highlighted choice object
+
object
the highlighted choice object
+
+

+
+
+
+
+

select2-loaded

+

Fired when query function is done loading the data and the results list has been updated

+

+

The event object contains the following custom properties: +

+
data
data that was used to populate the results
+
+

+
+
+
+
+

select2-focus

+

Fired when the control is focussed +

+
+
+
+
+

select2-blur

+

Fired when the control is blurred +

+
+
-

Configuring Defaults

+

Configuring Defaults

Select2 exposes its default options via the $.fn.select2.defaults object. Properties changed in this object (same properties configurable through the constructor) will take effect for every instance created after the change
diff --git a/select2-latest.html b/select2-latest.html index 33357ddf..13453ca7 100644 --- a/select2-latest.html +++ b/select2-latest.html @@ -2,7 +2,7 @@ layout: main title: Select2 Latest group: navigation -version: 3.4 +version: 4.0 --- @@ -241,13 +241,14 @@ $("#e10_4").select2({
-

Changelog

+

Changelog (Loading...)

-
    + +
    • Loading...
-

Browser Compatibility

    -
  • IE 7+
  • +
  • IE 8+
  • Chrome 8+
  • -
  • Firefox 3.5+
  • +
  • Firefox 10++
  • Safari 3+
  • Opera 10.6+
@@ -1448,6 +1449,7 @@ $("#select").select2({

In order for this function to work Select2 should be attached to a input type='hidden' tag instead of a select.

+

For documentation of the data format see the query function

dataarray/object Options for the built in query function that works with arrays. diff --git a/select2-master b/select2-master index 828d7a50..95d3728b 160000 --- a/select2-master +++ b/select2-master @@ -1 +1 @@ -Subproject commit 828d7a5052954e6a73584153e750b39ee5a1f4c9 +Subproject commit 95d3728b77c0e3adcbeaab0b9e5a6b77b67e23c0