Изменения

SimpleAutocomplete/en

3259 байтов добавлено, 15:19, 4 сентября 2014
м
Нет описания правки
* Source code: [{{SVN|vitaphoto/js/hinter.js}} hinter.js], [{{SVN|vitaphoto/js/hinter.css}} hinter.css].
* Minified JS: [{{SVN|vitaphoto/js/hinter.min.js|co}} hinter.min.js]
* Last update: {{../updatedate}}.
* License: [http://www.mozilla.org/MPL/2.0/ Mozilla Public License версии 2.0] или более новойor later.
*: In a nutshell, «strong file-level copyleft". Each separate file including any MPL-licensed code portions must be licensed under MPL2.0+, GPL2.0+, LGPL2.1+ or AGPL3.0+.
::; name: HTML option name
::; value: plaintext option value
::; disabled: only meaningful when multipleListener is setprevent selection of this option
::; checked: only meaningful when multipleListener is set
:; append: 'more' parameter should be passed here
; multipleDelimiter: Pass a delimiter string (for example ',' or ';') to enable multiple selection. Item values cannot have leading or trailing whitespace. Input value will consist of selected item values separated by this delimiter plus single space. dataLoader should handle it's 'value' parameter accordingly in this case, because it will be just the raw value of the input, probably with incomplete item or items, typed by the user.
; multipleListener(hint, index, item): If you don't want to touch the input value, but want to use multi-select for your own purposes, specify a callback that will handle item clicks here. Also you can disable and check/uncheck items during loading in this mode.
; onChangeListener(hint, index, item): Callback which is called when input value is changed using this dropdown. index is the number of element which selection is changed, starting with 0. It must be used instead of normal 'onchange' event.
; emptyText: Text to show when dataLoader returns no options. Empty (default) means 'hide hint'.
: ; prompt: HTML text to be displayed before a non-empty option list. Empty by default.
; delay: If this is set to a non-zero value, the autocompleter does no more than 1 request in each delay milliseconds.
; moreMarker: The server supplying hint options usually limits their count. But it's not always convenient having to type additional characters to narrow down the selection. Optionally you can supply additional item with special value equal to moreMarker value or '#MORE' at the end of the list, and SimpleAutocomplete will issue another request to dataLoader with incremented 'more' parameter when it will be clicked. You can also set moreMarker to false to disable this feature.
; persist: If true, the hint layer will never be hidden. You can use it to create multiselect-like controls (see example at the homepage).
; className: CSS class name for the hint layer. Default is 'hintLayer'.
When you don't need SimpleAutocomplete instance any more, you can destroy it with:
<p>Multiselect with prompt: <input type="text" id="x" name="x" value="" /></p>
<p>Side-effect multiselect: <input type="text" id="y" name="y" value="" /></p>
<p>Always visible multiselect:</p>
<div class="wrapPersist">
<input class="inputPersist" type="text" id="ms" value="" size="40" />
</div>
<div style="clear: both"></div>
<link rel="stylesheet" type="text/css" href="http://svn.yourcmc.ru/viewvc.py/vitaphoto/js/hinter.css?view=co" />
<style>
.wrapPersist {
border-radius: 5px;
border: 1px solid rgb(82, 168, 236);
float: left;
-webkit-box-shadow: inset 0 1px 5px rgba(82, 168, 236, 0.6);
-moz-box-shadow: inset 0 1px 5px rgba(82, 168, 236, 0.6);
box-shadow: inset 0 1px 5px rgba(82, 168, 236, 0.6);
}
.wrapPersist .inputPersist {
margin: 5px;
border-width: 0 0 1px 0;
border-bottom-style: solid;
border-bottom-color: rgb(82, 168, 236);
}
.wrapPersist .hintActiveItem {
background: #7db9e8; /* Old browsers */
background: -moz-linear-gradient(top, #7db9e8 0%, #2989d8 83%, #7db9e8 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#7db9e8), color-stop(83%,#2989d8), color-stop(100%,#7db9e8)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #7db9e8 0%,#2989d8 83%,#7db9e8 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #7db9e8 0%,#2989d8 83%,#7db9e8 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #7db9e8 0%,#2989d8 83%,#7db9e8 100%); /* IE10+ */
background: linear-gradient(to bottom, #7db9e8 0%,#2989d8 83%,#7db9e8 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#7db9e8', endColorstr='#7db9e8',GradientType=0 ); /* IE6-9 */
}
.email { color: gray; }
.wrapPersist .hintActiveItem .email { color: #e0e0e0; }
.hintPersist {
height: 200px;
font-size: 85%;
overflow-y: scroll;
}
</style>
<script language="JavaScript" src="http://svn.yourcmc.ru/viewvc.py/vitaphoto/js/hinter.js?view=co"></script>
<script language="JavaScript">
<!--
function cb(h, v, m) {
h.replaceItems([[ 'Vasya Pupkin', 'Vasya' ], [ 'Misha Metelkin', 'Misha' ], [ 'NecroPedoZoophile', 'x', 1 ]], m);
}
var sel = {};
h.replaceItems(i);
}
var ya;
function clcb(h, i, item) {
sel[i] = item[3];
new SimpleAutocomplete('z', cb);
new SimpleAutocomplete('x', cb, { multipleDelimiter: ',', prompt: 'Select peoples' });
ya = new SimpleAutocomplete('y', cb2, { multipleListener: clcb }); var users = [ [ 'vasya@oymorozmoroz.ru', 'Vasya Pupkin' ], [ 'misha@oymorozmoroz.ru', 'Misha Metelkin' ], [ 'alisa@oymorozmoroz.ru', 'Alisa Amosova' ], [ 'zoya@oymorozmoroz.ru', 'Zoya Zotova' ], [ 'pavel@oymorozmoroz.ru', 'Pavel Kosolapov' ]];var sel3 = { 'vasya@oymorozmoroz.ru': 1 };function cb3(h, v){ var items = []; for (var i = 0; i < users.length; i++) { if (!sel3[users[i][0]]) if (v.length) if (users[i][0].toLowerCase().indexOf(v.toLowerCase()) >= 0 || users[i][1].toLowerCase().indexOf(v.toLowerCase()) >= 0) { items.push([ users[i][1]+'<div class="email">'+users[i][0]+'</div>', users[i][0], false, sel3[users[i][0]] ]); } } for (var i = 0; i < users.length; i++) { if (sel3[users[i][0]]) { items.push([ users[i][1]+'<div class="email">'+users[i][0]+'</div>', users[i][0], false, sel3[users[i][0]] ]); } } h.replaceItems(items);}function clcb3(h, i, item){ sel3[item[1]] = item[3];}new SimpleAutocomplete('ms', cb3, { multipleListener: clcb3, persist: true, className: 'hintPersist', prompt: '<center style="color: gray">start typing a user name</center>', emptyText: '<center style="color: gray">no users selected<br /><i>start typing a user name</i></center>'});-->
</script>
</html>