Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added a new plugin ($.tmpl) instead of overloading the String prototy…

…pe (corss-library compatibility)

Modified the localisation strings to work with $.tmpl
Added getters/setters + added a new error message (option readonly)
Modified the demo page to display API and make it more dynamic (fixed some links also)
Added some styles (needs to be cleaned)
Added form.php to catch form actions and return feedback
  • Loading branch information...
commit e63317f265bd2f226d8743065a3d132829a94969 1 parent 46ec432
Yanick Rochon authored
View
187 css/common.css
@@ -1,55 +1,134 @@
- /*
- Copyright (c) 2007, Yahoo! Inc. All rights reserved.
- Code licensed under the BSD License:
- http://developer.yahoo.net/yui/license.txt
- version: 2.2.0
- */
- body {font:13px 'Helvetica',arial,clean,sans-serif;*font-size:small;*font:x-small;}table {font-size:inherit;font:100%;}select, input, textarea {font:99% arial,helvetica,clean,sans-serif;}pre, code {font:115% monospace;*font-size:100%;}body * {line-height:1.22em;}
- body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,p,blockquote,th,td{margin:0;padding:0;}table{border-collapse:collapse;border-spacing:0;}fieldset,img{border:0;}address,caption,cite,code,dfn,em,strong,th,var{font-style:normal;font-weight:normal;}/*ol,ul {list-style:none;}*/caption,th {text-align:left;}h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal;}q:before,q:after{content:'';}abbr,acronym {border:0;}
-
- /* end of yahoo reset and fonts */
-
- body {color:#333; background: #232f2e; line-height:1.3;}
- p {margin:0 0 20px;}
- a {color:#636363;}
- a:hover {text-decoration:none;}
- strong {font-weight:bold;}
- em {font-style: italic;}
- h1,h2,h3,h4,h5,h6 {font-weight:bold;}
- h1 {font-size:197%; margin:30px 0; color: #4f6f6c;}
- h2 {font-size:174%; margin:20px 0; color:#4f6f6c;}
- h3 {font-size:152%; margin:10px 0;}
- h4 {font-size:129%; margin:10px 0;}
- pre {background:#eee; margin:0 0 20px; padding:20px; border:1px solid #ccc; font-size:100%; overflow:auto;}
- code {font-size:100%; margin:0; padding:0;}
- ul, ol {margin:10px 0 10px 25px;}
- ol li {margin:0 0 10px;}
-
- div#wrapper {background:#fff; width:560px; margin:0 auto; padding:20px; border:10px solid #0f1616; border-width:0 10px 10px 10px;}
- div#header {position:relative; border-bottom:1px dotted; margin:0 0 10px; padding:0 0 10px;}
- div#header p {margin:0; padding:0;}
- div#header h1 {margin:0; padding:0;}
- ul#nav {position:absolute; top:0; right:0; list-style:none; margin:0; padding:0;}
- ul#nav li {display:inline; padding:0 0 0 5px;}
- ul#nav li a {}
- div#content {}
- div#footer {margin:40px 0 0; border-top:1px dotted; padding:10px 0 0;}
- .left {float:left;}
- .right {float:right;}
- .clear {clear:both;}
-
- dt { font-weight: bold; font-size: 110%; padding-bottom: 10px; }
- dd { margin-left: 20px; padding-bottom: 20px; }
-
- /* multiselect styles */
- .multiselect {
- width: 460px;
- height: 150px;
- }
-
- #switcher {
- margin-top: 20px;
- }
-
- form {margin: 0; padding: 0;}
+/*
+Copyright (c) 2007, Yahoo! Inc. All rights reserved.
+Code licensed under the BSD License:
+http://developer.yahoo.net/yui/license.txt
+version: 2.2.0
+*/
+body {font:13px 'Helvetica',arial,clean,sans-serif;*font-size:small;*font:x-small;}
+table {font-size:inherit;font:100%;}
+select,input,textarea {font:99% arial,helvetica,clean,sans-serif;}
+pre,code {font:115% monospace;*font-size:100%;}
+body * {line-height:1.22em;}
+body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,p,blockquote,th,td {margin:0;padding:0;}
+table {border-collapse:collapse;border-spacing:0;}
+fieldset,img {border:0;}
+address,caption,cite,code,dfn,em,strong,th,var {font-style:normal;font-weight:normal;}
+/*ol,ul {list-style:none;}*/
+caption,th {text-align:left;}
+h1,h2,h3,h4,h5,h6 {font-size:100%;font-weight:normal;}
+q:before,q:after {content:'';}
+abbr,acronym {border:0;}
+
+/* end of yahoo reset and fonts */
+
+body {color:#333; background: #232f2e; line-height:1.3;}
+p {margin:0 0 20px;}
+a {color:#636363;}
+a:hover {text-decoration:none;}
+strong {font-weight:bold;}
+em {font-style: italic;}
+h1,h2,h3,h4,h5,h6 {font-weight:bold;}
+h1 {font-size:197%; margin:30px 0; color: #4f6f6c;}
+h2 {font-size:174%; margin:20px 0; color:#4f6f6c;}
+h3 {font-size:152%; margin:10px 0;}
+h4 {font-size:129%; margin:10px 0;}
+pre {background:#eee; margin:0 0 20px; padding:20px; border:1px solid #ccc; font-size:100%; overflow:auto;}
+code {font-size:100%; margin:0; padding:0;}
+ul, ol {margin:10px 0 10px 25px;}
+ol li {margin:0 0 10px;}
+
+iframe {width:100%; height: 200px; background: #eef; color: black;}
+
+div#wrapper {background:#fff; width:640px; margin:0 auto; padding:20px; border:10px solid #0f1616; border-width:0 10px 10px 10px;}
+div#header {position:relative; border-bottom:1px dotted; margin:0 0 10px; padding:0 0 10px;}
+div#header p {margin:0; padding:0;}
+div#header h1 {margin:0; padding:0;}
+ul#nav {position:absolute; top:0; right:0; list-style:none; margin:0; padding:0;}
+ul#nav li {display:inline; padding:0 0 0 5px;}
+ul#nav li a {}
+div#content {}
+div#footer {margin:40px 0 0; border-top:1px dotted; padding:10px 0 0;}
+.left {float:left;}
+.right {float:right;}
+.clear {clear:both;}
+
+dt {font-weight: bold; font-size: 110%; padding-bottom: 10px;}
+dd {margin-left: 20px; padding-bottom: 20px;}
+
+/* multiselect styles */
+.multiselect {width: 460px; height: 150px;}
+
+#switcher {margin-top: 20px;}
+
+form {margin: 0; padding: 0;}
+
+.externalControlsWrapper {margin-top: 10px; margin-bottom: 20px;}
+.externalControlsWrapper .optionWrapper {vertical-align: middle; overflow: auto; width: 100%; margin-bottom: 10px;}
+.externalControlsWrapper a {font-size: 90%;}
+.externalControls {margin-top: 10px; border: 1px solid #bbb; background: #eee;}
+.externalControls .optionLabel {width: 160px;}
+.externalControls .optionInput {float: right; width: 280px;}
+
+/* JQuery API CSS */
+
+
+h2.top-header { color: #FFFFFF; margin: 0 0 20px 0 !important; padding: 5px 10px !important; background: #0F67A1; font-size: 15px; -moz-border-radius: 2px; text-transform: none; }
+ul.options-list a,
+ul.methods-list a {
+ font-size: 14px;
+ color: #0f67a1;
+ text-decoration: underline;
+}
+ul.options-list a:hover,
+ul.methods-list a:hover {
+ color: #176092;
+ text-decoration: underline;
+}
+
+
+.UIAPIPlugin #options h2,
+.UIAPIPlugin #events h2,
+.UIAPIPlugin #methods h2,
+.UIAPIPlugin #theming h2 { color: #FFFFFF; margin: 0 0 20px 0 !important; padding: 5px 10px !important; background: #0F67A1; font-size: 15px; -moz-border-radius: 2px; text-transform: none; }
+
+ul.options-list,
+ul.options-list li.option { margin: 0; padding: 0; list-style-type: none; list-style-image: none; }
+ul.options-list { margin-left: 6px; }
+ul.options-list li.option { padding-bottom: 10px !important; }
+ul.options-list li.option dl,
+ul.options-list li.option dt,
+ul.options-list li.option dd { margin: 0; padding: 0; }
+ul.options-list li.option .option-header { width: 100%; float: left; background-color: #E2EDF4 !important; }
+ul.options-list li.option .option-header .option-name { margin: 0 !important; padding: 0 !important; width: 35%; float: left; background-color: #E2EDF4 !important; }
+ul.options-list li.option .option-header dt,
+ul.options-list li.option .option-header dd { margin: 0; padding: 0; float: left; width: 18%; }
+ul.options-list li.option .option-header dt.option-type-label { display: none; }
+ul.options-list li.option .option-header dt.option-default-label { text-align: right; padding-right: 0.4em; color: #666666; }
+ul.options-list li.option .option-description { clear: left; padding: 5px 10px 0 10px; }
+ul.options-list li.option .option-examples-list dt p { line-height: 1.5 !important; margin: 0 !important; padding: 5px 0 !important; color: #666666; }
+ul.options-list li.option .option-examples-list dd pre { margin: 0 !important; }
+ul.options-list li.option .option-examples-list { padding: 0 10px; }
+ul.options-list li.option .option-examples-list dd { margin-left: 10px; }
+ul.options-list li.option .option-examples-list dd pre code { background: none; }
+
+ul.events-list,
+ul.events-list li.events { margin: 0; padding: 0; list-style-type: none; list-style-image: none; }
+ul.events-list { margin-left: 6px; }
+ul.events-list li.event { padding-bottom: 10px !important; }
+ul.events-list li.event dl,
+ul.events-list li.event dt,
+ul.events-list li.event dd { margin: 0; padding: 0; }
+ul.events-list li.event .event-header { width: 100%; float: left; background-color: #E2EDF4 !important; }
+ul.events-list li.event .event-header .event-name { margin: 0 !important; padding: 0 !important; width: 25%; float: left; background-color: #E2EDF4 !important; }
+ul.events-list li.event .event-header dt,
+ul.events-list li.event .event-header dd { margin: 0; padding: 0; float: left; width: 23%; }
+ul.events-list li.event .event-header dt.event-type-label { width: 10%; }
+ul.events-list li.event .event-header dt.event-default-label { text-align: right; padding-right: 0.5em; color: #666666; }
+ul.events-list li.event .event-description { clear: left; padding: 5px 10px 0 10px; }
+ul.events-list li.event .event-examples-list dt p { line-height: 1.5 !important; margin: 0 !important; padding: 5px 0 !important; color: #666666; }
+ul.events-list li.event .event-examples-list dd pre { margin: 0 !important; }
+ul.events-list li.event .event-examples-list { padding: 0 10px; }
+ul.events-list li.event .event-examples-list dd { margin-left: 10px; }
+ul.events-list li.event .event-examples-list dd pre code { background: none; }
+
View
40 form.php
@@ -0,0 +1,40 @@
+<?php
+@session_start();
+
+header('Content-type: text/plain; charset:utf-8');
+
+// ignore these fields in the $_REQUEST
+$ignoredKeys = array('PHPSESSID', 'jquery-ui-theme', 'reset');
+$formData = array();
+foreach ($_REQUEST as $key => $value) {
+ if (!in_array($key, $ignoredKeys) ) {
+ $formData[$key] = $value;
+ }
+}
+
+if (empty($formData) || isset($_REQUEST['reset'])) {
+
+ echo "Waiting form submission...";
+
+} else {
+
+ echo date('Y-m-d g:i:s', time()) . ' - '
+ . "The form has submitted the following values :\n\n";
+
+ foreach ($formData as $fieldName => $value) {
+ if (is_array($value)) {
+ $valueData = $value;
+ $value = '';
+ foreach ($valueData as $data) {
+ $value .= (!empty($value) ? ', ' : '') . $data;
+ }
+ }
+
+ echo "Field : " . $fieldName . "\n"
+ . "Value : " . $value . "\n\n";
+ }
+
+ echo "\n"
+ . "Done.";
+
+}
View
795 index.html
@@ -1,4 +1,4 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
@@ -9,26 +9,25 @@
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.7.1.custom.min.js"></script>
<script type="text/javascript" src="js/plugins/localisation/jquery.localisation-min.js"></script>
+ <script type="text/javascript" src="js/plugins/tmpl/jquery.tmpl.1.1.1.js"></script>
<script type="text/javascript" src="js/plugins/blockUI/jquery.blockUI.js"></script>
<script type="text/javascript" src="js/ui.multiselect.js"></script>
- <script type="text/javascript" src="js/page.js"></script>
<script type="text/javascript">
$(function(){
$.localise('ui.multiselect', {/*language: 'es',/* */ path: 'js/locale/'});
// local
$("#countries").multiselect();
-
// remote
$("#languages").multiselect({
remoteUrl: "ajax.php"
});
-
- $('#switcher').themeswitcher();
- $('#tabs').tabs();
+ $('#switcher').themeswitcher();
});
- </script>
+ </script>
+ <script type="text/javascript" src="js/page.js"></script>
+
</head>
<body>
<a href="http://github.com/michael/multiselect"><img style="position: absolute; top: 0; right: 0; border: 0;" src="http://s3.amazonaws.com/github/ribbons/forkme_right_white_ffffff.png" alt="Fork me on GitHub" /></a>
@@ -41,13 +40,14 @@ <h4 style="background: #ffffcd; border: 1px solid red; padding: 4px; text-align:
See <a href="http://michael.github.com/multiselect/">here</a> for the official project page.
</h4>
<p>
- Another attempt of a <em>sortable</em>, <em>searchable</em> multiple select widget
+ Another attempt of a <em>sortable</em>, <em>searchable</em> multiple select widget.<br />
+ <em><strong>IMPORTANT:</strong> This version is under development</em>
</p>
<ul id="nav">
<li><a href="http://quasipartikel.at/2009/05/10/jqueryui-multiselect/">Blogpost</a></li>
- <li><a href="http://github.com/michael/multiselect">Source</a></li>
- <li><a href="http://github.com/michael/multiselect/issues">Bugs</a></li>
+ <li><a href="http://github.com/yanickrochon/multiselect">Source</a></li>
+ <li><a href="http://github.com/yanickrochon/multiselect/issues">Bugs</a></li>
</ul>
</div>
@@ -64,20 +64,19 @@ <h4 style="background: #ffffcd; border: 1px solid red; padding: 4px; text-align:
<ul>
<li>For installation instructions please have a look at the corresponding <a href="http://www.quasipartikel.at/2009/05/10/jqueryui-multiselect/">blogpost</a></li>
- <li>Source code is available at <a href="http://github.com/michael/multiselect/" title="Social Coding">Github</a></li>
+ <li>Source code is available at <a href="http://github.com/yanickrochon/multiselect/" title="Social Coding">Github</a></li>
<li>In case you are looking for the original version, it has been moved <a href="http://quasipartikel.at/multiselect_original/">here</a></li>
- <li>Bleeding Edge Demo is always available <a href="http://michael.github.com/multiselect">here</a> (thanks to Github Pages)</li>
+ <li>Official Bleeding Edge Demo is always available <a href="http://michael.github.com/multiselect">here</a> (thanks to Github Pages)</li>
</ul><br/>
- <div id="debug">---</div>
-
+ <h2>Demo</h2>
<div id="tabs">
<ul>
<li><a href="#tabs-1">Local</a></li>
<li><a href="#tabs-2">Remote</a></li>
</ul>
<div id="tabs-1">
- <form action="index.html" style="border: none;">
+ <form action="form.php" target="submitFrame" style="border: none;">
<dl>
<dt>Multiselect with local content :</dt>
<dd>
@@ -189,50 +188,84 @@ <h4 style="background: #ffffcd; border: 1px solid red; padding: 4px; text-align:
</select>
</dd>
- <dt>Controls :</dt>
+ <dt>
+ Test submit <span style="font-size: smaller; font-style: italic; color: #777;">(will not reload the page)</span>
+ </dt>
<dd>
- <div>
- <div class="optionLabel">Enable multiselect : </div>
- <input id="checkLocalEnabled" type="checkbox" checked="checked" />
- </div>
- <div>
- <div class="optionLabel">Get selected values : </div>
- <input id="checkLocalValues" type="button" value="Get selected values" />
- </div>
- <div>
- <div class="optionLabel">Select values : </div>
- <input id="buttonLocalSelectAll" type="button" value="Select All" />
- <input id="buttonLocalSelectNone" type="button" value="Select none" />
- </div>
- <div>
- <div class="optionLabel">Search : </div>
- <input id="inputLocalSearch" type="input" value="" />
- <input id="buttonLocalSearch" type="button" value="Search" />
- </div>
- <div>
- <div class="optionLabel">Manual selection : </div>
- <input id="inputLocalItem" type="input" value="" />
- <input id="buttonLocalItemAdd" type="button" value="Select" />
- <input id="buttonLocalItemRemove" type="button" value="Deselect" />
- </div>
+ <input type="submit" id="localSubmit" name="localSubmit" value="Send selection" />
</dd>
</dl>
</form>
</div>
<div id="tabs-2">
- <form action="index.html" style="border: none;">
+ <form action="form.php" target="submitFrame" style="border: none;">
<dl>
<dt>Multiselect with remote content :</dt>
<dd>
<select id="languages" class="multiselect" multiple="multiple" name="languages[]">
</select>
</dd>
+ <dt>
+ Test submit <span style="font-size: smaller; font-style: italic; color: #777;">(will not reload the page)</span>
+ </dt>
+ <dd>
+ <input type="submit" id="localSubmit" name="localSubmit" value="Send selection" />
+ </dd>
</dl>
</form>
</div>
</div>
-
+
+ <!-- Dialog contents -->
+ <div id="debug"></div>
+ <div id="submitResult">
+ <iframe id="submitFrame" name="submitFrame" src="form.php?reset"></iframe>
+ </div>
+
+ <div class="externalControlsWrapper">
+ <a class="externalControlsToggle" href="#localExtCtrl">Toggle external controls</a>
+ <div id="localExtCtrl" class="externalControls">
+ <dt>Controls :</dt>
+ <dd>
+ <div class="optionWrapper">
+ <div class="optionInput">
+ <input id="ec_toggleEnabled" type="button" value="Toggle enabled/disabled" />
+ </div>
+ <div class="optionLabel">Enable multiselect : </div>
+ </div>
+ <div class="optionWrapper">
+ <div class="optionInput">
+ <input id="ec_checkValues" type="button" value="Get selected values" />
+ </div>
+ <div class="optionLabel">Get selected values : </div>
+ </div>
+ <div class="optionWrapper">
+ <div class="optionInput">
+ <input id="ec_buttonSelectAll" type="button" value="Select All" />
+ <input id="ec_buttonSelectNone" type="button" value="Select none" />
+ </div>
+ <div class="optionLabel">Select values : </div>
+ </div>
+ <div class="optionWrapper">
+ <div class="optionInput">
+ <input id="ec_inputItem" type="input" value="" /><br />
+ <input id="ec_buttonItemAdd" type="button" value="Select" />
+ <input id="ec_buttonItemRemove" type="button" value="Deselect" />
+ </div>
+ <div class="optionLabel">Manual selection : </div>
+ </div>
+ <div class="optionWrapper">
+ <div class="optionInput">
+ <input id="ec_inputSearch" type="input" value="" />
+ <input id="ec_buttonSearch" type="button" value="Search" />
+ </div>
+ <div class="optionLabel">Search : </div>
+ </div>
+ </dd>
+ </div>
+ </div>
+
<script type="text/javascript" src="http://jqueryui.com/themeroller/themeswitchertool/"></script>
<div id="switcher"></div>
@@ -245,6 +278,18 @@ <h4 style="background: #ffffcd; border: 1px solid red; padding: 4px; text-align:
<li>Dragging items from the available list to the selected list directly</li>
<li>List sorting and node events callbacks for more customizations</li>
</ul>
+
+ <h2>Localisation</h2>
+ <ul>
+ <li>All messages are using a string template function to allow localization. To specify a locale template, copy the <code>/js/locale/ui.multiselect-en.js</code> template, rename the file (ie: for french, <code>ui.multiselect-fr.js</code>), open it, and translate the strings, save. Then add the script between <code>ui.multiselect.js</code> and your widget initialization script.</li>
+ <li>For more information about the string template format, read <a href="http://andrew.hedges.name/blog/2008/09/03/introducing-jquery-simple-templates">Andrew Hedges' blog</a>.
+ </ul>
+
+ <h2>Known bugs</h2>
+ <ul>
+ <li>The draggables may act weird in IE. This bug is under inverstigation.</li>
+ <li>...</li>
+ </ul>
<h2>Contributors</h2>
<ul>
@@ -259,6 +304,672 @@ <h4 style="background: #ffffcd; border: 1px solid red; padding: 4px; text-align:
</p>
</div>
+ <!-- Options -->
+ <div id="optionTabs" class="UIAPIPlugin">
+ <ul>
+ <li><a href="#optionTabs-1">Options</a></li>
+ <li><a href="#optionTabs-2">Methods</a></li>
+ <li><a href="#optionTabs-3">Events</a></li>
+ </ul>
+
+
+ <div id="optionTabs-1">
+ <ul class="options-list">
+
+ <!-- option - animated -->
+ <li class="option" id="option-animated">
+ <div class="option-header">
+ <h3 class="option-name"><a href="#option-animated">animated</a></h3>
+
+ <dl>
+ <dt class="option-type-label">Type:</dt>
+ <dd class="option-type">String, null</dd>
+
+ <dt class="option-default-label">Default:</dt>
+ <dd class="option-default">'fast'</dd>
+ </dl>
+ </div>
+
+ <div class="option-description">
+ <p>When <i>animated</i> is specified, the multiselect UI will use transition effects between interactions. The possible values are 'fast', 'slow' and null (no animation).</p>
+ </div>
+ <div class="option-examples">
+ <h4>Code examples</h4>
+ <dl class="option-examples-list">
+ <dt>
+ Initialize a multiselect with the <code>animated</code> option specified.
+ </dt>
+ <dd>
+ <pre><code>$('.selector').multiselect({ animated: 'fast' });</code></pre>
+ </dd>
+ <dt>
+ Get or set the <code>animated</code> option, after init.
+ </dt>
+ <dd>
+ <pre><code>//getter
+var animated = $('.selector').dialog('option', 'animated');
+//setter
+$('.selector').dialog('option', 'animated', 'slow');</code></pre>
+ </dd>
+ </dl>
+ </div>
+ </li>
+
+ <li class="option" id="option-dataParser">
+ <div class="option-header">
+ <h3 class="option-name"><a href="#option-dataParser">dataParser</a></h3>
+ <dl>
+ <dt class="option-type-label">Type:</dt>
+ <dd class="option-type">Function</dd>
+
+ <dt class="option-default-label">Default:</dt>
+ <dd class="option-default"><i>defaultDataParser</i></dd>
+ </dl>
+ </div>
+ <div class="option-description">
+ <p>Used with remote search, this function is called to parse the data received and return the data in the expected format.</p>
+ <p>The function takes the raw received data from the request and should return a JSON object corresponding to the new available options to add. The returned object should have the following structure :</p>
+ <pre><code>{
+ "key1": {
+ selected: boolean,
+ value: string
+ }[,
+ "key2": {
+ selected: boolean,
+ value: string
+ }[,
+ ...]]
+}</code></pre>
+ <p>If the data should be discarded, the function may return false or null.</p>
+ </div>
+ <div class="option-examples">
+ <h4>Code examples</h4>
+ <dl class="option-examples-list">
+ <dt>
+ Initialize a multiselect with the a pass-through dataParser<br />
+ <span style="font-weight: normal; font-style: italic;">(expects to receive the correct raw data format from the server)</span>
+ </dt>
+ <dd>
+ <pre><code>$('.selector').multiselect({ dataParser: function(data) { return data; } });</code></pre>
+ </dd>
+ <dt>
+ Get or set the <code>dataParser</code> option, after init.
+ </dt>
+ <dd>
+ <pre><code>//getter
+var dataParser = $('.selector').dialog('option', 'dataParser');
+//setter
+$('.selector').dialog('option', 'dataParser', newDataParser);</code></pre>
+ </dd>
+ </dl>
+ </div>
+ </li>
+
+ <li class="option" id="option-dividerLocation">
+ <div class="option-header">
+ <h3 class="option-name"><a href="#option-dividerLocation">dividerLocation</a></h3>
+ <dl>
+ <dt class="option-type-label">Type:</dt>
+ <dd class="option-type">float</dd>
+
+ <dt class="option-default-label">Default:</dt>
+ <dd class="option-default">0.6</dd>
+ </dl>
+ </div>
+ <div class="option-description">
+ <p>Specify the portion of the selected (left side) area of the multiselect. To have an even split multiselect, set <i>dividerLocation</i> to 0.5. The value should be between 0 and 1.</p>
+ </div>
+ <div class="option-examples">
+ <h4>Code examples</h4>
+ <dl class="option-examples-list">
+ <dt>
+ Initialize a multiselect with the <code>dividerLocation</code> option specified.
+ </dt>
+ <dd>
+ <pre><code>$('.selector').multiselect({ dividerLocation: 0.55 });</code></pre>
+ </dd>
+ <dt>
+ Get or set the <code>dividerLocation</code> option, after init.
+ </dt>
+ <dd>
+ <pre><code>//getter
+var dividerLocation = $('.selector').dialog('option', 'dividerLocation');
+//setter
+$('.selector').dialog('option', 'dividerLocation', 0.55);</code></pre>
+ </dd>
+ </dl>
+ </div>
+ </li>
+
+ <li class="option" id="option-droppable">
+ <div class="option-header">
+ <h3 class="option-name"><a href="#option-droppable">droppable</a></h3>
+ <dl>
+ <dt class="option-type-label">Type:</dt>
+ <dd class="option-type">String</dd>
+
+ <dt class="option-default-label">Default:</dt>
+ <dd class="option-default">'both'</dd>
+ </dl>
+ </div>
+ <div class="option-description">
+ <p>Enable or disable basic drag and drop functionality between the selected list (left) and the available list (right). The possible values are 'both', 'left', 'right', 'none'. And set drop support in both lists, the selected list, the available list, or no drag and drop respectively.</p>
+ <p>This setting is readonly at run-time. Trying to set this property after initialization will display an alert message.</p>
+ </div>
+ <div class="option-examples">
+ <h4>Code examples</h4>
+ <dl class="option-examples-list">
+ <dt>
+ Initialize a multiselect with the no drag and drop functionality.
+ </dt>
+ <dd>
+ <pre><code>$('.selector').multiselect({ droppable: 'none' });</code></pre>
+ </dd>
+ <dt>
+ Get the <code>droppable</code> option, after init.
+ </dt>
+ <dd>
+ <pre><code>//getter
+var droppable = $('.selector').dialog('option', 'droppable');</code></pre>
+ </dd>
+ </dl>
+ </div>
+ </li>
+
+ <li class="option" id="option-hide">
+ <div class="option-header">
+ <h3 class="option-name"><a href="#option-hide">hide</a></h3>
+ <dl>
+ <dt class="option-type-label">Type:</dt>
+ <dd class="option-type">String</dd>
+
+ <dt class="option-default-label">Default:</dt>
+ <dd class="option-default">'slideUp'</dd>
+ </dl>
+ </div>
+ <div class="option-description">
+ <p>Specify the <i>hide</i> animation function to use. If <i>animated</i> is null, the value will be overriden to 'hide'. The possible values are any available function effects name. The default value for animated hide effect is 'slideUp'.</p>
+ </div>
+ <div class="option-examples">
+ <h4>Code examples</h4>
+ <dl class="option-examples-list">
+ <dt>
+ Initialize a multiselect with the <code>hide</code> option specified.
+ </dt>
+ <dd>
+ <pre><code>$('.selector').multiselect({ hide: 'fadeOut' });</code></pre>
+ </dd>
+ <dt>
+ Get or set the <code>hide</code> option, after init.
+ </dt>
+ <dd>
+ <pre><code>//getter
+var hide = $('.selector').dialog('option', 'hide');
+//setter
+$('.selector').dialog('option', 'hide', 'fadeOut');</code></pre>
+ </dd>
+ </dl>
+ </div>
+ </li>
+
+ <li class="option" id="option-nodeComparator">
+ <div class="option-header">
+ <h3 class="option-name"><a href="#option-nodeComparator">nodeComparator</a></h3>
+ <dl>
+ <dt class="option-type-label">Type:</dt>
+ <dd class="option-type">Function, null</dd>
+
+ <dt class="option-default-label">Default:</dt>
+ <dd class="option-default">defaultNodeComparator</dd>
+ </dl>
+ </div>
+ <div class="option-description">
+ <p>Comparator function used in ordering the list's elements during transfer. The function takes two arguments, a and b, and should return a numeric value less than 0 if a &lt; b, 0 if a == b, or greater than 0 if a &gt; b respectively.</p>
+ <p>The function is only called when using '+', '-', 'add all' and 'remove all' action controls, and is never called when using drag and drop item transfer. By default, items are sorted by content value ascending. To completely disable automatic list ordering, set <i>nodeComparator</i> to null.</p>
+ </div>
+ <div class="option-examples">
+ <h4>Code examples</h4>
+ <dl class="option-examples-list">
+ <dt>
+ Initialize a multiselect with option key ordering <code>nodeComparator</code>.
+ </dt>
+ <dd>
+ <pre><code>$('.selector').multiselect({ nodeComparator: function(a, b) {
+ var ka = node1.data('multiselect.optionLink').val(),
+ kb = node2.data('multiselect.optionLink').val();
+ return ka == kb ? 0 : (ka < kb ? -1 : 1);
+} } });</code></pre>
+ </dd>
+ <dt>
+ Get or set the <code>nodeComparator</code> option, after init.
+ </dt>
+ <dd>
+ <pre><code>//getter
+var nodeComparator = $('.selector').dialog('option', 'nodeComparator');
+//setter (will only be applied on new inserted items only!)
+$('.selector').dialog('option', 'nodeComparator', newNodeComparator);</code></pre>
+ </dd>
+ </dl>
+ </div>
+ </li>
+
+ <li class="option" id="option-nodeInserted">
+ <div class="option-header">
+ <h3 class="option-name"><a href="#option-nodeInserted">nodeInserted</a></h3>
+ <dl>
+ <dt class="option-type-label">Type:</dt>
+ <dd class="option-type">Function, null</dd>
+
+ <dt class="option-default-label">Default:</dt>
+ <dd class="option-default">null</dd>
+ </dl>
+ </div>
+ <div class="option-description">
+ <p>Callback function fired for each newly inserted items. The function takes the inserted item as a JQuery object and does not expect any return value.</p>
+ </div>
+ <div class="option-examples">
+ <h4>Code examples</h4>
+ <dl class="option-examples-list">
+ <dt>
+ Initialize a multiselect a <code>nodeInserted</code> callback.
+ </dt>
+ <dd>
+ <pre><code>$('.selector').multiselect({ nodeInserted: function(item) {
+ item.attr('title', item.text()); // set a "tooltip" to newly added items
+} } });</code></pre>
+ </dd>
+ <dt>
+ Get or set the <code>animated</code> option, after init.
+ </dt>
+ <dd>
+ <pre><code>//getter
+var nodeInserted = $('.selector').dialog('option', 'nodeInserted');
+//setter
+$('.selector').dialog('option', 'nodeInserted', newCallback);</code></pre>
+ </dd>
+ </dl>
+ </div>
+ </li>
+
+ <li class="option" id="option-searchable">
+ <div class="option-header">
+ <h3 class="option-name"><a href="#option-searchable">searchable</a></h3>
+ <dl>
+ <dt class="option-type-label">Type:</dt>
+ <dd class="option-type">boolean</dd>
+
+ <dt class="option-default-label">Default:</dt>
+ <dd class="option-default">true</dd>
+ </dl>
+ </div>
+ <div class="option-description">
+ <p>Enable or disable search capabilities for this instance of the multiselect.</p>
+ </div>
+ <div class="option-examples">
+ <h4>Code examples</h4>
+ <dl class="option-examples-list">
+ <dt>
+ Initialize a multiselect with <code>searchable</code> option disabled.
+ </dt>
+ <dd>
+ <pre><code>$('.selector').multiselect({ searchable: false });</code></pre>
+ </dd>
+ <dt>
+ Get or set the <code>searchable</code> option, after init.
+ </dt>
+ <dd>
+ <pre><code>//getter
+var searchable = $('.selector').dialog('option', 'searchable');
+//setter (reset search filter)
+$('.selector').dialog('option', 'searchable', false);</code></pre>
+ </dd>
+ </dl>
+ </div>
+ </li>
+
+ <li class="option" id="option-searchDelay">
+ <div class="option-header">
+ <h3 class="option-name"><a href="#option-searchDelay">searchDelay</a></h3>
+ <dl>
+ <dt class="option-type-label">Type:</dt>
+ <dd class="option-type">int</dd>
+
+ <dt class="option-default-label">Default:</dt>
+ <dd class="option-default">400</dd>
+ </dl>
+ </div>
+ <div class="option-description">
+ <p>Define the input search delay before a request is sent to the server. The default value is 400 milliseconds.</p>
+ </div>
+ <div class="option-examples">
+ <h4>Code examples</h4>
+ <dl class="option-examples-list">
+ <dt>
+ Initialize a multiselect with a 1 second <code>searchDelay</code>.
+ </dt>
+ <dd>
+ <pre><code>$('.selector').multiselect({ searchDelay: 1000 });</code></pre>
+ </dd>
+ <dt>
+ Get or set the <code>searchDelay</code> option, after init.
+ </dt>
+ <dd>
+ <pre><code>//getter
+var searchDelay = $('.selector').dialog('option', 'searchDelay');
+//setter
+$('.selector').dialog('option', 'searchDelay', 1000);</code></pre>
+ </dd>
+ </dl>
+ </div>
+ </li>
+
+ <li class="option" id="option-show">
+ <div class="option-header">
+ <h3 class="option-name"><a href="#option-show">show</a></h3>
+ <dl>
+ <dt class="option-type-label">Type:</dt>
+ <dd class="option-type">String</dd>
+
+ <dt class="option-default-label">Default:</dt>
+ <dd class="option-default">'slideDown'</dd>
+ </dl>
+ </div>
+ <div class="option-description">
+ <p>Specify the <i>show</i> animation function to use. If <i>animated</i> is null, the value will be overriden to 'show'. The possible values are any available function effects name. The default value for animated hide effect is 'slideDown'.</p>
+ </div>
+ <div class="option-examples">
+ <h4>Code examples</h4>
+ <dl class="option-examples-list">
+ <dt>
+ Initialize a multiselect with the <code>show</code> option specified.
+ </dt>
+ <dd>
+ <pre><code>$('.selector').multiselect({ show: 'fadeIn' });</code></pre>
+ </dd>
+ <dt>
+ Get or set the <code>show</code> option, after init.
+ </dt>
+ <dd>
+ <pre><code>//getter
+var show = $('.selector').dialog('option', 'show');
+//setter
+$('.selector').dialog('option', 'show', 'fadeIn');</code></pre>
+ </dd>
+ </dl>
+ </div>
+ </li>
+
+ <li class="option" id="option-sortable">
+ <div class="option-header">
+ <h3 class="option-name"><a href="#option-sortable">sortable</a></h3>
+ <dl>
+ <dt class="option-type-label">Type:</dt>
+ <dd class="option-type">String</dd>
+
+ <dt class="option-default-label">Default:</dt>
+ <dd class="option-default">'left'</dd>
+ </dl>
+ </div>
+ <div class="option-description">
+ <p>Enable or disable item <i>sortable</i> functionality through drag and drop for the selected list (left) and/or the available list (right). The possible values are 'both', 'left', 'right', 'none'. And set <i>sortable</i> support in both lists, the selected list only, the available list only, or none <i>sortable</i> respectively.</p>
+ <p>This setting overrides <a href="#option-droppable">droppable</a> for the specified list. This setting is readonly at run-time (like <a href="#option-droppable">droppable</a>).</p>
+ </div>
+ <div class="option-examples">
+ <h4>Code examples</h4>
+ <dl class="option-examples-list">
+ <dt>
+ Initialize a multiselect <i>sortable</i> functionality across both lists.
+ </dt>
+ <dd>
+ <pre><code>$('.selector').multiselect({ sortable: 'both' });</code></pre>
+ </dd>
+ <dt>
+ Get the <code>sortable</code> option, after init.
+ </dt>
+ <dd>
+ <pre><code>//getter
+var sortable = $('.selector').dialog('option', 'sortable');</code></pre>
+ </dd>
+ </dl>
+ </div>
+ </li>
+
+ <li class="option" id="option-remoteParams">
+ <div class="option-header">
+ <h3 class="option-name"><a href="#option-remoteParams">remoteParams</a></h3>
+ <dl>
+ <dt class="option-type-label">Type:</dt>
+ <dd class="option-type">Object</dd>
+
+ <dt class="option-default-label">Default:</dt>
+ <dd class="option-default">{ }</dd>
+ </dl>
+ </div>
+ <div class="option-description">
+ <p>Specify some extra remote parameters to send with every remote search requests. Note that the 'q' argument is reserved by multiselect and if <i>remoteParams</i> contains a key called 'q', it will be overriden with the search query.</p>
+ </div>
+ <div class="option-examples">
+ <h4>Code examples</h4>
+ <dl class="option-examples-list">
+ <dt>
+ Initialize a multiselect searchable remotely with extra params
+ </dt>
+ <dd>
+ <pre><code>// server expect to receive a public key for secure requests
+// our public key is "foo", send this key automatically with every search request
+$('.selector').multiselect({ remoteUrl: 'ajax.php', remoteParams: { publickey: 'foo' } });</code></pre>
+ </dd>
+ <dt>
+ Get or set the <code>remoteParams</code> option, after init.
+ </dt>
+ <dd>
+ <pre><code>//getter
+var remoteParams = $('.selector').dialog('option', 'remoteParams');
+//setter
+$('.selector').dialog('option', 'remoteParams', { publickey: 'bar' });</code></pre>
+ </dd>
+ </dl>
+ </div>
+ </li>
+
+ <li class="option" id="option-remoteUrl">
+ <div class="option-header">
+ <h3 class="option-name"><a href="#option-remoteUrl">remoteUrl</a></h3>
+ <dl>
+ <dt class="option-type-label">Type:</dt>
+ <dd class="option-type">String, null</dd>
+
+ <dt class="option-default-label">Default:</dt>
+ <dd class="option-default">null</dd>
+ </dl>
+ </div>
+ <div class="option-description">
+ <p></p>
+ </div>
+ <div class="option-examples">
+ <h4>Code examples</h4>
+ <dl class="option-examples-list">
+ <dt>
+ Initialize a multiselect with a given remote url.
+ </dt>
+ <dd>
+ <pre><code>$('.selector').multiselect({ remoteUrl: 'ajax.php' });</code></pre>
+ </dd>
+ <dt>
+ Get or set the <code>remoteUrl</code> option, after init.
+ </dt>
+ <dd>
+ <pre><code>//getter
+var remoteUrl = $('.selector').dialog('option', 'remoteUrl');
+//setter
+$('.selector').dialog('option', 'remoteUrl', '/path/to/script.php');</code></pre>
+ </dd>
+ </dl>
+ </div>
+ </li>
+ </ul>
+ </div>
+
+
+ <div id="optionTabs-2">
+
+ <ul class="methods-list">
+
+ <li class="method" id="method-enabled">
+ <div class="method-header">
+ <h3 class="method-name"><a href="#method-enabled">enabled</a></h3>
+ <dl>
+ <dt class="method-signature-label">Signature:</dt>
+ <dd class="method-signature">.multiselect( 'enabled', <span class="optional">[</span>state<span class="optional">]</span> )</dd>
+ </dl>
+ </div>
+ <div class="method-description">
+ <p>Get or set the state of the enabled multiselect. If no state is specified, will act as a getter.</p>
+ </div>
+ </li>
+
+ <li class="method" id="method-deselect">
+ <div class="method-header">
+ <h3 class="method-name"><a href="#method-deselect">deselect</a></h3>
+ <dl>
+ <dt class="method-signature-label">Signature:</dt>
+ <dd class="method-signature">.multiselect( 'deselect', item )</dd>
+ </dl>
+ </div>
+ <div class="method-description">
+ <p>Deselect the specified item. The value should be key of the option to deselect. If value is numeric and is &gt;= 0 and is &lt; selected item count, the item at position value will be deselected.</p>
+ </div>
+ </li>
+
+ <li class="method" id="method-destroy">
+ <div class="method-header">
+ <h3 class="method-name"><a href="#method-destroy">destroy</a></h3>
+ <dl>
+ <dt class="method-signature-label">Signature:</dt>
+ <dd class="method-signature">.multiselect( 'destroy' )</dd>
+ </dl>
+ </div>
+ <div class="method-description">
+ <p>Remove the multiselect functionality completely. This will return the element back to it's default look.</p>
+ </div>
+ </li>
+
+ <li class="method" id="method-isBusy">
+ <div class="method-header">
+ <h3 class="method-name"><a href="#method-isBusy">isBusy</a></h3>
+ <dl>
+ <dt class="method-signature-label">Signature:</dt>
+ <dd class="method-signature">.multiselect( 'isBusy' )</dd>
+ </dl>
+ </div>
+ <div class="method-description">
+ <p>Return the busy state of the multiselect. The method will return true if the multiselect is processing item selection, search, etc.</p>
+ </div>
+ </li>
+
+ <li class="method" id="method-isSelected">
+ <div class="method-header">
+ <h3 class="method-name"><a href="#method-isSelected">isSelected</a></h3>
+ <dl>
+ <dt class="method-signature-label">Signature:</dt>
+ <dd class="method-signature">.multiselect( 'isSelected', item )</dd>
+ </dl>
+ </div>
+ <div class="method-description">
+ <p>Return true if and only if item is selected. The value should be key of the option to verify. If value is numeric and is &gt;= 0 and is &lt; selected item count, the method will return true.</p>
+ </div>
+ </li>
+
+ <li class="method" id="method-option">
+ <div class="method-header">
+ <h3 class="method-name"><a href="#method-option">option</a></h3>
+ <dl>
+ <dt class="method-signature-label">Signature:</dt>
+ <dd class="method-signature">.multiselect( 'option', optionName, <span class="optional">[</span>value<span class="optional">]</span> )</dd>
+ </dl>
+ </div>
+ <div class="method-description">
+ <p>Get or set any dialog option. If no value is specified, will act as a getter.</p>
+ </div>
+ </li>
+
+ <li class="method" id="method-search">
+ <div class="method-header">
+ <h3 class="method-name"><a href="#method-search">search</a></h3>
+ <dl>
+ <dt class="method-signature-label">Signature:</dt>
+ <dd class="method-signature">.multiselect( 'search', query )</dd>
+ </dl>
+ </div>
+ <div class="method-description">
+ <p>Perform a search of all the available elements, and filter out (hide) any unmatched item. This method controls the search input fields, if the multiselect is not searchable, is busy, or not enabled, the method does nothing.</p>
+ </div>
+ </li>
+
+ <li class="method" id="method-select">
+ <div class="method-header">
+ <h3 class="method-name"><a href="#method-select">select</a></h3>
+ <dl>
+ <dt class="method-signature-label">Signature:</dt>
+ <dd class="method-signature">.multiselect( 'select', item )</dd>
+ </dl>
+ </div>
+ <div class="method-description">
+ <p>Select the specified item. The value should be key of the option to select. If value is numeric and is &gt;= 0 and is &lt; available item count, the item at position value will be selected.</p>
+ </div>
+ </li>
+
+ <li class="method" id="method-selectAll">
+ <div class="method-header">
+ <h3 class="method-name"><a href="#method-selectAll">selectAll</a></h3>
+ <dl>
+ <dt class="method-signature-label">Signature:</dt>
+ <dd class="method-signature">.multiselect( 'selectAll' )</dd>
+ </dl>
+ </div>
+ <div class="method-description">
+ <p>Select all of the available items.</p>
+ </div>
+ </li>
+
+ <li class="method" id="method-selectedValues">
+ <div class="method-header">
+ <h3 class="method-name"><a href="#method-selectedValues">selectedValues</a></h3>
+ <dl>
+ <dt class="method-signature-label">Signature:</dt>
+ <dd class="method-signature">.multiselect( 'selectedValues' )</dd>
+ </dl>
+ </div>
+ <div class="method-description">
+ <p>Return an array of the keys of all the currently selected values (equivalent to "Add all").</p>
+ </div>
+ </li>
+
+ <li class="method" id="method-selectNone">
+ <div class="method-header">
+ <h3 class="method-name"><a href="#method-selectNone">selectNone</a></h3>
+ <dl>
+ <dt class="method-signature-label">Signature:</dt>
+ <dd class="method-signature">.multiselect( 'selectNone' )</dd>
+ </dl>
+ </div>
+ <div class="method-description">
+ <p>Deselect all the selected items (equivalent to "Remove all").</p>
+ </div>
+ </li>
+
+ </ul>
+
+ </div>
+
+ <div id="optionTabs-3">
+
+ <p>Coming Soon...</p>
+
+ </div>
+
+ </div>
+
<div id="footer">
<p class="left">A <a href="http://quasipartikel.at/">Quasipartikel</a> Production</p>
<p class="right">Template adopted from <a href="http://orderedlist.com/demos/fancy-zoom-jquery/">orderedlist.com</a></p>
View
7 js/locale/ui.multiselect-en.js
@@ -7,8 +7,9 @@
$.extend($.ui.multiselect.locale, {
addAll:'Add all',
removeAll:'Remove all',
- itemsCount:'#{0} items selected',
- itemsTotal:'#{0} items total',
+ itemsCount:'#{count} items selected',
+ itemsTotal:'#{count} items total',
busy:'please wait...',
- errorInsertNode:"There was a problem trying to add the item:\n\n\t[#{0}] => #{1}\n\nThe operation was aborted."
+ errorInsertNode:"There was a problem trying to add the item:\n\n\t[#{key}] => #{value}\n\nThe operation was aborted.",
+ errorReadonly:"The option #{option} is readonly."
});
View
7 js/locale/ui.multiselect-es.js
@@ -7,8 +7,9 @@
$.extend($.ui.multiselect.locale, {
addAll:'Agregar todos',
removeAll:'Remover todos',
- itemsCount:'#{0} Objetos seleccionados',
- itemsTotal:'#{0} Objetos total',
+ itemsCount:'#{count} Objetos seleccionados',
+ itemsTotal:'#{count} Objetos total',
busy:'por favor, espere...'
- errorInsertNode:"Ha habido un problema al tratar de agregar el tema:\n\n\t[#{0}] => #{1}\n\nLa operación fue abortada."
+ errorInsertNode:"Ha habido un problema al tratar de agregar el tema:\n\n\t[#{key}] => #{value}\n\nLa operación fue abortada.",
+ errorReadonly:"La opción #{option} es de sólo lectura."
});
View
7 js/locale/ui.multiselect-fr.js
@@ -7,8 +7,9 @@
$.extend($.ui.multiselect.locale, {
addAll:'Ajouter tout',
removeAll:'Supprimer tout',
- itemsCount:'#{0} items sélectionnés',
- itemsTotal:'#{0} items total',
+ itemsCount:'#{count} items sélectionnés',
+ itemsTotal:'#{count} items total',
busy:'veuillez patienter...'
- errorInsertNode:"Un problème est survenu en tentant d'ajouter l'item:\n\n\t[#{0}] => #{1}\n\nL'opération a été annulée."
+ errorInsertNode:"Un problème est survenu en tentant d'ajouter l'item:\n\n\t[#{key}] => #{value}\n\nL'opération a été annulée.",
+ errorReadonly:"L'option #{option} est en lecture seule."
});
View
75 js/page.js
@@ -1,13 +1,54 @@
-
+/**
+ * Multiselect demo page initialisation script
+ *
+ * @author Yanick Rochon
+ */
$(function() {
- // Tab 1 : local
- $('#checkLocalEnabled').click(function(event) {
- $('#countries').multiselect('enabled', event.target.checked);
- alert( "Element is " + ($('#countries').multiselect('enabled') ? 'enabled' : 'disabled') );
+ $('#tabs, #optionTabs').tabs();
+
+ $('.externalControls').hide();
+ $('.externalControlsToggle').click(function() {
+ $($(this).attr('href')).toggle();
+ return false;
+ });
+
+ $('#submitResult').dialog({
+ autoOpen: false,
+ closeOnEscape: true,
+ draggable: true,
+ resizable: false,
+ width: $('#submitFrame').width(),
+ height: $('#submitFrame').height() + 65,
+ title: "Form submit result"
+ });
+ $('#debug').dialog({
+ autoOpen: false, // true for displaying debug information (if any)
+ closeOnEscape: true,
+ draggable: true,
+ resizable: true,
+ title: 'Debug',
+ position: ['left','top']
+ });
+
+ $('form').submit(function() {
+ if (!$('#submitResult').dialog('isOpen')) $('#submitResult').dialog('open');
+ });
+
+
+ // Multiselect controls
+ var getVisibleMultiselect = function() {
+ return $('#tabs-' + (parseInt($('#tabs').tabs('option', 'selected')) + 1)).find('select.multiselect[multiple]');
+ };
+
+ $('#ec_toggleEnabled').click(function(event) {
+ var multiselect = getVisibleMultiselect();
+ multiselect.multiselect('enabled', !multiselect.multiselect('enabled'));
+ alert( "Element is " + (multiselect.multiselect('enabled') ? 'enabled' : 'disabled') );
});
- $('#checkLocalValues').click(function() {
- var values = $('#countries').multiselect('selectedValues');
+ $('#ec_checkValues').click(function() {
+ var multiselect = getVisibleMultiselect();
+ var values = multiselect.multiselect('selectedValues');
if (0 === values.length) {
alert("There is currently no selected value");
} else if (1 === values.length) {
@@ -16,20 +57,20 @@ $(function() {
alert( "There are currently " + values.length + " selected values:\n\n" + values.join(', '));
}
});
- $('#buttonLocalSelectAll').click(function() {
- $('#countries').multiselect('selectAll');
+ $('#ec_buttonSelectAll').click(function() {
+ getVisibleMultiselect().multiselect('selectAll');
});
- $('#buttonLocalSelectNone').click(function() {
- $('#countries').multiselect('selectNone');
+ $('#ec_buttonSelectNone').click(function() {
+ getVisibleMultiselect().multiselect('selectNone');
});
- $('#buttonLocalSearch').click(function() {
- $('#countries').multiselect('search', $('#inputLocalSearch').val() );
+ $('#ec_buttonSearch').click(function() {
+ getVisibleMultiselect().multiselect('search', $('#ec_inputSearch').val() );
});
- $('#buttonLocalItemAdd').click(function() {
- $('#countries').multiselect('select', $('#inputLocalItem').val() );
+ $('#ec_buttonItemAdd').click(function() {
+ getVisibleMultiselect().multiselect('select', $('#ec_inputItem').val() );
});
- $('#buttonLocalItemRemove').click(function() {
- $('#countries').multiselect('deselect', $('#inputLocalItem').val() );
+ $('#ec_buttonItemRemove').click(function() {
+ getVisibleMultiselect().multiselect('deselect', $('#ec_inputItem').val() );
});
View
38 js/plugins/tmpl/jquery.tmpl.1.1.1.js
@@ -0,0 +1,38 @@
+/*
+ * jQuery Simple Templates plugin 1.1.1
+ *
+ * http://andrew.hedges.name/tmpl/
+ * http://docs.jquery.com/Plugins/Tmpl
+ *
+ * Copyright (c) 2008 Andrew Hedges, andrew@hedges.name
+ *
+ * Usage: $.tmpl('<div class="#{classname}">#{content}</div>', { 'classname' : 'my-class', 'content' : 'My content.' });
+ * $.tmpl('<div class="#{1}">#{0}</div>', 'My content', 'my-class'); // placeholder order not important
+ *
+ * The changes for version 1.1 were inspired by the discussion at this thread:
+ * http://groups.google.com/group/jquery-ui/browse_thread/thread/45d0f5873dad0178/0f3c684499d89ff4
+ *
+ * Dual licensed under the MIT and GPL licenses:
+ * http://www.opensource.org/licenses/mit-license.php
+ * http://www.gnu.org/licenses/gpl.html
+ */
+
+(function($) {
+ // regular expression for matching our placeholders; e.g., #{my-cLaSs_name77}
+ var regx = /#\{([^{}]*)}/g;
+
+ $.extend({
+ // public interface: $.tmpl
+ tmpl : function(tmpl) {
+ // default to doing no harm
+ tmpl = tmpl || '';
+ var vals = (2 === arguments.length && 'object' === typeof arguments[1] ? arguments[1] : Array.prototype.slice.call(arguments,1));
+ // function to making replacements
+ var repr = function (str, match) {
+ return typeof vals[match] === 'string' || typeof vals[match] === 'number' ? vals[match] : str;
+ };
+
+ return tmpl.replace(regx, repr);
+ }
+ });
+})(jQuery);
View
188 js/ui.multiselect.js
@@ -16,6 +16,7 @@
* ui.draggable.js
* ui.droppable.js
* jquery.blockUI (http://github.com/malsup/blockui/)
+ * jquery.tmpl (http://andrew.hedges.name/blog/2008/09/03/introducing-jquery-simple-templates
*
* Optional:
* localization (http://plugins.jquery.com/project/localisation)
@@ -25,39 +26,24 @@
* and allow flexibility in the messages. Read the documentation for more details.
*
* Todo:
+ * restore selected items on remote searchable multiselect upon page reload (same behavior as local mode)
+ * add sort (is it worth it??) public function to apply the nodeComparator to all items (when using nodeComparator setter)
* tests and optimizations
+ * - test getters/setters (including options from the defaults)
*/
-if (!String.prototype.template) {
- /**
- * String templates based on Prototype's templating and source based
- * on Andrew Hedges' pure Simple HTML template Javascript implementation
- * (http://andrew.hedges.name/)
- *
- * Usage: "#{greetings}, my name is #{name}".template({greetings:'Hello', name:'Bob'});
- * "#{1}, my name is #{0}".template('Bob', 'Hello');
- */
- String.prototype.template = function() {
- var vals = (1 === arguments.length && 'object' === typeof arguments[0] ? arguments[0] : arguments);
- return this.replace(String.templatePattern, function (str, match) {
- return 'string' === typeof vals[match] || 'number' === typeof vals[match] ? vals[match] : str;
- });
- };
- String.templatePattern = /#\{([^{}]*)\}/g;
-}
-
(function($) {
$.widget("ui.multiselect", {
_init: function() {
- //this.element.hide();
+ this.element.hide();
this.busy = false; // busy state
this.container = $('<div class="ui-multiselect ui-helper-clearfix ui-widget"></div>').insertAfter(this.element);
this.selectedContainer = $('<div class="ui-widget-content list-container selected"></div>').appendTo(this.container);
this.availableContainer = $('<div class="ui-widget-content list-container available"></div>').appendTo(this.container);
- this.selectedActions = $('<div class="actions ui-widget-header ui-helper-clearfix"><span class="count">'+$.ui.multiselect.locale.itemsCount.template(0)+'</span><a href="#" class="remove-all">'+$.ui.multiselect.locale.removeAll.template()+'</a></div>').appendTo(this.selectedContainer);
- this.availableActions = $('<div class="actions ui-widget-header ui-helper-clearfix"><span class="busy">'+$.ui.multiselect.locale.busy.template()+'</span><input type="text" class="search ui-widget-content ui-corner-all"/><a href="#" class="add-all">'+$.ui.multiselect.locale.addAll.template()+'</a></div>').appendTo(this.availableContainer);
+ this.selectedActions = $('<div class="actions ui-widget-header ui-helper-clearfix"><span class="count">'+$.tmpl($.ui.multiselect.locale.itemsCount,{count:0})+'</span><a href="#" class="remove-all">'+$.tmpl($.ui.multiselect.locale.removeAll)+'</a></div>').appendTo(this.selectedContainer);
+ this.availableActions = $('<div class="actions ui-widget-header ui-helper-clearfix"><span class="busy">'+$.tmpl($.ui.multiselect.locale.busy)+'</span><input type="text" class="search ui-widget-content ui-corner-all"/><a href="#" class="add-all">'+$.tmpl($.ui.multiselect.locale.addAll)+'</a></div>').appendTo(this.availableContainer);
this.selectedList = $('<ul class="list selected"><li class="ui-helper-hidden-accessible"></li></ul>').bind('selectstart', function(){return false;}).appendTo(this.selectedContainer);
this.availableList = $('<ul class="list available"><li class="ui-helper-hidden-accessible"></li></ul>').bind('selectstart', function(){return false;}).appendTo(this.availableContainer);
@@ -87,11 +73,7 @@ $.widget("ui.multiselect", {
this._prepareLists('available', 'selected', dragOptions);
// set up livesearch
- if (this.options.searchable) {
- this._registerSearchEvents(this.availableContainer.find('input.search'));
- } else {
- this.availableContainer.find('input.search').hide();
- }
+ this._registerSearchEvents(this.availableContainer.find('input.search'), true);
// make sure that we're not busy yet
this._setBusy(false);
@@ -101,8 +83,7 @@ $.widget("ui.multiselect", {
// set dimensions
this.container.width(this.element.width()+1);
- this.selectedContainer.width(Math.floor(this.element.width()*this.options.dividerLocation));
- this.availableContainer.width(Math.floor(this.element.width()*(1-this.options.dividerLocation)));
+ this._refreshDividerLocation();
// set max width of search input dynamically
this.availableActions.find('input').width(Math.max(this.availableActions.width() - this.availableActions.find('a.add-all').width() - 30, 20));
// fix list height to match <option> depending on their individual header's heights
@@ -126,6 +107,13 @@ $.widget("ui.multiselect", {
isBusy: function() {
return this.busy;
},
+ isSelected: function(item) {
+ if (this.enabled()) {
+ return this._findItem(item, this.selectedList);
+ } else {
+ return null;
+ }
+ },
// get all selected values in an array
selectedValues: function() {
var values = this.selectedList.children('li.ui-element:visible').map(function(i,item) {
@@ -173,8 +161,10 @@ $.widget("ui.multiselect", {
}
},
search: function(query) {
- if (this.enabled()) {
- this.availableActions.children('input.search').val(query).trigger('keydown.multiselect');
+ if (!this.busy && this.enabled() && this.options.searchable) {
+ var input = this.availableActions.children('input:first');
+ input.val(query);
+ input.trigger('keydown.multiselect');
}
},
// insert new <option> and _populate
@@ -185,7 +175,7 @@ $.widget("ui.multiselect", {
this._setBusy(true);
// format data
- if (data = this.options.formatData(data)) {
+ if (data = this.options.dataParser(data)) {
var option, elements = [];
for (var key in data) {
// check if the option does not exist already
@@ -210,6 +200,33 @@ $.widget("ui.multiselect", {
* Private
**************************************/
+ _setData: function(key, value) {
+ switch (key) {
+ // special treatement must be done for theses values when changed
+ case 'dividerLocation':
+ this.options.dividerLocation = value;
+ this._refreshDividerLocation();
+ break;
+ case 'searchable':
+ this.options.searchable = value;
+ this._registerSearchEvents(this.availableContainer.find('input.search'), false);
+ break;
+
+ case 'droppable':
+ case 'sortable':
+ // readonly options
+ alert($.tmpl($.ui.multiselect.locale.errorReadonly, {option: key}));
+ default:
+ // default behavior
+ this.options[key] = value;
+ break;
+ }
+ },
+
+ _refreshDividerLocation: function() {
+ this.selectedContainer.width(Math.floor(this.element.width()*this.options.dividerLocation));
+ this.availableContainer.width(Math.floor(this.element.width()*(1-this.options.dividerLocation)));
+ },
_prepareLists: function(side, otherSide, opts) {
var that = this;
var itemSelected = ('selected' == side);
@@ -352,7 +369,7 @@ $.widget("ui.multiselect", {
list.append(node);
}
// callback after node insertion
- that.options.nodeInserted(node);
+ if ('function' == typeof that.options.nodeInserted) that.options.nodeInserted(node);
that._setBusy(false);
} catch (e) {
// if this problem did not occur too many times already
@@ -360,7 +377,7 @@ $.widget("ui.multiselect", {
// try again later (let the browser cool down first)
setTimeout(function() { _addNode(); }, 1);
} else {
- alert($.ui.multiselect.locale.errorInsertNode.template(node.data('multiselect.optionLink').val(), node.text()));
+ alert($.tmpl($.ui.multiselect.locale.errorInsertNode, {key:node.data('multiselect.optionLink').val(), value:node.text()}));
that._setBusy(false);
}
}
@@ -375,8 +392,8 @@ $.widget("ui.multiselect", {
var count = this.selectedList.children('li:not(.ui-helper-hidden-accessible,.ui-sortable-placeholder):visible').size();
var total = this.availableList.children('li:not(.ui-helper-hidden-accessible,.ui-sortable-placeholder,.shadowed)').size() + count;
this.selectedContainer.find('span.count')
- .text($.ui.multiselect.locale.itemsCount.template(count))
- .attr('title', $.ui.multiselect.locale.itemsTotal.template(total));
+ .text($.tmpl($.ui.multiselect.locale.itemsCount, {count:count}))
+ .attr('title', $.tmpl($.ui.multiselect.locale.itemsTotal, {count:total}));
},
_getOptionNode: function(option) {
option = $(option);
@@ -506,21 +523,13 @@ $.widget("ui.multiselect", {
return succ;
},
_setSelected: function(item, selected) {
- var that = this;
- //try {
- // // FIXME see if item.data('multiselect.optionLink').removeAttr('selected') fix this issue (when selected == false)
- // item.data('multiselect.optionLink').attr('selected', selected);
- //} catch (e) {
- // /* HACK! ignore IE complaints */
- //}
+ var that = this, otherItem;
if (selected) {
item.data('multiselect.optionLink').attr('selected','selected');
} else {
item.data('multiselect.optionLink').removeAttr('selected');
}
- var otherItem;
-
if (selected) {
// retrieve associatd or cloned item
otherItem = this._cloneWithData(item, 'selected', true).hide();
@@ -556,7 +565,9 @@ $.widget("ui.multiselect", {
input.blur().hide();
busy.show();
} else if(!state && this.busy) {
- input.show();
+ if (this.options.searchable) {
+ input.show();
+ }
busy.hide();
if (input.data('multiselect.hadFocus')) input.focus();
}
@@ -636,7 +647,9 @@ $.widget("ui.multiselect", {
var that = this;
elements.unbind('click.multiselect').bind('click.multiselect', function() {
// ignore if busy...
- if (!this.busy) that._setSelected($(this).parent(), false);
+ if (!that.busy) {
+ that._setSelected($(this).parent(), false);
+ }
return false;
});
if (this.selectedList.data('multiselect.draggable')) {
@@ -656,11 +669,9 @@ $.widget("ui.multiselect", {
}
}
},
- _registerSearchEvents: function(input) {
+ _registerSearchEvents: function(input, searchNow) {
var that = this;
- var searchUrl = this.options.remoteUrl,
- delay = Math.max(this.options.searchDelay,1),
- previousValue = input.val(), timer;
+ var previousValue = input.val(), timer;
var _searchNow = function(forceUpdate) {
if (that.busy) return;
@@ -669,11 +680,11 @@ $.widget("ui.multiselect", {
if ((value != previousValue) || (forceUpdate)) {
that._setBusy(true);
- if (searchUrl) {
+ if (that.options.remoteUrl) {
var params = $.extend({}, that.options.remoteParams);
try {
$.get(
- searchUrl,
+ that.options.remoteUrl,
$.extend(params, {q:escape(value)}),
function(data) {
that.addOptions(data);
@@ -682,7 +693,7 @@ $.widget("ui.multiselect", {
}
);
} catch (e) {
- alert(e.message);
+ alert(e.message); // error message template ??
that._setBusy(false);
}
} else {
@@ -693,25 +704,33 @@ $.widget("ui.multiselect", {
previousValue = value;
}
};
+
+ // reset any events... if any
+ input.unbind('focus.multiselect blur.multiselect keydown.multiselect keypress.multiselect');
+ if (this.options.searchable) {
+ input
+ .bind('focus.multiselect', function() {
+ $(this).addClass('ui-state-active').data('multiselect.hasFocus', true);
+ })
+ .bind('blur.multiselect', function() {
+ $(this).removeClass('ui-state-active').data('multiselect.hasFocus', false);
+ })
+ .bind('keydown.multiselect keypress.multiselect', function(e) {
+ if (timer) clearTimeout(timer);
+ switch (e.which) {
+ case 13: // enter
+ _searchNow(true);
+ return false;
- input
- .bind('focus.multiselect', function() {
- $(this).addClass('ui-state-active').data('multiselect.hasFocus', true);
- })
- .bind('blur.multiselect', function() {
- $(this).removeClass('ui-state-active').data('multiselect.hasFocus', false);
- })
- .bind('keydown.multiselect keypress.multiselect', function(e) {
- if (timer) clearTimeout(timer);
- switch (e.which) {
- case 13: // enter
- _searchNow(true);
- return false;
-
- default:
- timer = setTimeout(function() { _searchNow(); }, delay);
- }
- });
+ default:
+ timer = setTimeout(function() { _searchNow(); }, Math.max(that.options.searchDelay,1));
+ }
+ })
+ .show();
+ } else {
+ input.val('').hide();
+ this._filter(that.availableList.find('li.ui-element'))
+ }
// initiate search filter (delayed)
var _initSearch = function() {
if (that.busy) {
@@ -719,7 +738,8 @@ $.widget("ui.multiselect", {
}
_searchNow(true);
};
- _initSearch();
+
+ if (searchNow) _initSearch();
}
});
// END ui.multiselect
@@ -729,14 +749,13 @@ $.widget("ui.multiselect", {
* Internal functions
********************************/
-// FIXME : add some extra data to the helper so we know where it comes from
var _dragHelper = function(event, ui) {
var item = $(event.target);
var clone = item.clone().width(item.width());
clone
.data('multiselect.optionLink', item.data('multiselect.optionLink'))
.data('multiselect.list', item.parent() )
- // node cleanup
+ // node ui cleanup
.find('a').remove()
;
$('#debug').text('Helper: start drag from list ' + item.parent()[0].className );
@@ -748,7 +767,7 @@ var _dragHelper = function(event, ui) {
* Default callbacks
********************************/
-var defaultDataFormatter = function(data) {
+var defaultDataParser = function(data) {
if ( typeof data == 'string' ) {
var pattern = /^(\s\n\r\t)*\+?$/;
var selected, line, lines = data.split(/\n/);
@@ -767,7 +786,7 @@ var defaultDataFormatter = function(data) {
}
}
} else {
- alert($.ui.multiselect.locale.errorDataFormat.template());
+ alert($.tmpl($.ui.multiselect.locale.errorDataFormat));
data = false;
}
return data;
@@ -781,10 +800,6 @@ var defaultNodeComparator = function(node1,node2) {
};
-var defaultNodeInserted = function(node) {
- /* nothing */
-};
-
/****************************
* Settings
****************************/
@@ -793,7 +808,7 @@ $.extend($.ui.multiselect, {
getter: 'selectedValues enabled isBusy',
defaults: {
// sortable and droppable
- sortable: 'both',
+ sortable: 'left',
droppable: 'both',
// searchable
searchable: true,
@@ -807,18 +822,19 @@ $.extend($.ui.multiselect, {
// ui
dividerLocation: 0.6,
// callbacks
- formatData: defaultDataFormatter,
+ dataParser: defaultDataParser,
nodeComparator: defaultNodeComparator,
- nodeInserted: defaultNodeInserted
+ nodeInserted: null
},
locale: {
addAll:'Add all',
removeAll:'Remove all',
- itemsCount:'#{0} items selected',
- itemsTotal:'#{0} items total',
+ itemsCount:'#{count} items selected',
+ itemsTotal:'#{count} items total',
busy:'please wait...',
errorDataFormat:"Cannot add options, unknown data format",
- errorInsertNode:"There was a problem trying to add the item:\n\n\t[#{0}] => #{1}\n\nThe operation was aborted."
+ errorInsertNode:"There was a problem trying to add the item:\n\n\t[#{key}] => #{value}\n\nThe operation was aborted.",
+ errorReadonly:"The option #{option} is readonly"
}
});

0 comments on commit e63317f

Please sign in to comment.
Something went wrong with that request. Please try again.