Mercurial > hg > NetworkVis
annotate query_builder/selectize/dist/js/standalone/selectize.js @ 26:22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
author | arussell |
---|---|
date | Tue, 01 Dec 2015 02:07:13 -0500 |
parents | |
children |
rev | line source |
---|---|
26
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2 * sifter.js |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3 * Copyright (c) 2013 Brian Reavis & contributors |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
4 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
6 * file except in compliance with the License. You may obtain a copy of the License at: |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
7 * http://www.apache.org/licenses/LICENSE-2.0 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
8 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
9 * Unless required by applicable law or agreed to in writing, software distributed under |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
10 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
11 * ANY KIND, either express or implied. See the License for the specific language |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
12 * governing permissions and limitations under the License. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
13 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
14 * @author Brian Reavis <brian@thirdroute.com> |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
15 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
16 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
17 (function(root, factory) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
18 if (typeof define === 'function' && define.amd) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
19 define('sifter', factory); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
20 } else if (typeof exports === 'object') { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
21 module.exports = factory(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
22 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
23 root.Sifter = factory(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
24 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
25 }(this, function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
26 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
27 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
28 * Textually searches arrays and hashes of objects |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
29 * by property (or multiple properties). Designed |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
30 * specifically for autocomplete. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
31 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
32 * @constructor |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
33 * @param {array|object} items |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
34 * @param {object} items |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
35 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
36 var Sifter = function(items, settings) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
37 this.items = items; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
38 this.settings = settings || {diacritics: true}; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
39 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
40 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
41 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
42 * Splits a search string into an array of individual |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
43 * regexps to be used to match results. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
44 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
45 * @param {string} query |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
46 * @returns {array} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
47 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
48 Sifter.prototype.tokenize = function(query) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
49 query = trim(String(query || '').toLowerCase()); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
50 if (!query || !query.length) return []; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
51 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
52 var i, n, regex, letter; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
53 var tokens = []; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
54 var words = query.split(/ +/); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
55 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
56 for (i = 0, n = words.length; i < n; i++) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
57 regex = escape_regex(words[i]); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
58 if (this.settings.diacritics) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
59 for (letter in DIACRITICS) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
60 if (DIACRITICS.hasOwnProperty(letter)) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
61 regex = regex.replace(new RegExp(letter, 'g'), DIACRITICS[letter]); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
62 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
63 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
64 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
65 tokens.push({ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
66 string : words[i], |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
67 regex : new RegExp(regex, 'i') |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
68 }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
69 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
70 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
71 return tokens; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
72 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
73 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
74 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
75 * Iterates over arrays and hashes. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
76 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
77 * ``` |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
78 * this.iterator(this.items, function(item, id) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
79 * // invoked for each item |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
80 * }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
81 * ``` |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
82 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
83 * @param {array|object} object |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
84 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
85 Sifter.prototype.iterator = function(object, callback) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
86 var iterator; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
87 if (is_array(object)) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
88 iterator = Array.prototype.forEach || function(callback) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
89 for (var i = 0, n = this.length; i < n; i++) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
90 callback(this[i], i, this); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
91 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
92 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
93 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
94 iterator = function(callback) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
95 for (var key in this) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
96 if (this.hasOwnProperty(key)) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
97 callback(this[key], key, this); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
98 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
99 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
100 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
101 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
102 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
103 iterator.apply(object, [callback]); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
104 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
105 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
106 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
107 * Returns a function to be used to score individual results. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
108 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
109 * Good matches will have a higher score than poor matches. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
110 * If an item is not a match, 0 will be returned by the function. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
111 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
112 * @param {object|string} search |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
113 * @param {object} options (optional) |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
114 * @returns {function} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
115 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
116 Sifter.prototype.getScoreFunction = function(search, options) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
117 var self, fields, tokens, token_count; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
118 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
119 self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
120 search = self.prepareSearch(search, options); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
121 tokens = search.tokens; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
122 fields = search.options.fields; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
123 token_count = tokens.length; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
124 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
125 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
126 * Calculates how close of a match the |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
127 * given value is against a search token. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
128 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
129 * @param {mixed} value |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
130 * @param {object} token |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
131 * @return {number} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
132 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
133 var scoreValue = function(value, token) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
134 var score, pos; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
135 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
136 if (!value) return 0; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
137 value = String(value || ''); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
138 pos = value.search(token.regex); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
139 if (pos === -1) return 0; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
140 score = token.string.length / value.length; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
141 if (pos === 0) score += 0.5; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
142 return score; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
143 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
144 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
145 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
146 * Calculates the score of an object |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
147 * against the search query. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
148 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
149 * @param {object} token |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
150 * @param {object} data |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
151 * @return {number} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
152 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
153 var scoreObject = (function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
154 var field_count = fields.length; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
155 if (!field_count) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
156 return function() { return 0; }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
157 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
158 if (field_count === 1) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
159 return function(token, data) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
160 return scoreValue(data[fields[0]], token); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
161 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
162 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
163 return function(token, data) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
164 for (var i = 0, sum = 0; i < field_count; i++) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
165 sum += scoreValue(data[fields[i]], token); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
166 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
167 return sum / field_count; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
168 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
169 })(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
170 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
171 if (!token_count) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
172 return function() { return 0; }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
173 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
174 if (token_count === 1) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
175 return function(data) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
176 return scoreObject(tokens[0], data); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
177 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
178 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
179 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
180 if (search.options.conjunction === 'and') { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
181 return function(data) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
182 var score; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
183 for (var i = 0, sum = 0; i < token_count; i++) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
184 score = scoreObject(tokens[i], data); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
185 if (score <= 0) return 0; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
186 sum += score; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
187 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
188 return sum / token_count; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
189 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
190 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
191 return function(data) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
192 for (var i = 0, sum = 0; i < token_count; i++) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
193 sum += scoreObject(tokens[i], data); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
194 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
195 return sum / token_count; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
196 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
197 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
198 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
199 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
200 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
201 * Returns a function that can be used to compare two |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
202 * results, for sorting purposes. If no sorting should |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
203 * be performed, `null` will be returned. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
204 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
205 * @param {string|object} search |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
206 * @param {object} options |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
207 * @return function(a,b) |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
208 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
209 Sifter.prototype.getSortFunction = function(search, options) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
210 var i, n, self, field, fields, fields_count, multiplier, multipliers, get_field, implicit_score, sort; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
211 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
212 self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
213 search = self.prepareSearch(search, options); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
214 sort = (!search.query && options.sort_empty) || options.sort; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
215 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
216 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
217 * Fetches the specified sort field value |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
218 * from a search result item. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
219 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
220 * @param {string} name |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
221 * @param {object} result |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
222 * @return {mixed} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
223 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
224 get_field = function(name, result) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
225 if (name === '$score') return result.score; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
226 return self.items[result.id][name]; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
227 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
228 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
229 // parse options |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
230 fields = []; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
231 if (sort) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
232 for (i = 0, n = sort.length; i < n; i++) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
233 if (search.query || sort[i].field !== '$score') { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
234 fields.push(sort[i]); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
235 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
236 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
237 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
238 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
239 // the "$score" field is implied to be the primary |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
240 // sort field, unless it's manually specified |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
241 if (search.query) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
242 implicit_score = true; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
243 for (i = 0, n = fields.length; i < n; i++) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
244 if (fields[i].field === '$score') { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
245 implicit_score = false; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
246 break; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
247 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
248 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
249 if (implicit_score) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
250 fields.unshift({field: '$score', direction: 'desc'}); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
251 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
252 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
253 for (i = 0, n = fields.length; i < n; i++) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
254 if (fields[i].field === '$score') { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
255 fields.splice(i, 1); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
256 break; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
257 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
258 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
259 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
260 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
261 multipliers = []; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
262 for (i = 0, n = fields.length; i < n; i++) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
263 multipliers.push(fields[i].direction === 'desc' ? -1 : 1); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
264 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
265 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
266 // build function |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
267 fields_count = fields.length; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
268 if (!fields_count) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
269 return null; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
270 } else if (fields_count === 1) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
271 field = fields[0].field; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
272 multiplier = multipliers[0]; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
273 return function(a, b) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
274 return multiplier * cmp( |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
275 get_field(field, a), |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
276 get_field(field, b) |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
277 ); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
278 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
279 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
280 return function(a, b) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
281 var i, result, a_value, b_value, field; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
282 for (i = 0; i < fields_count; i++) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
283 field = fields[i].field; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
284 result = multipliers[i] * cmp( |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
285 get_field(field, a), |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
286 get_field(field, b) |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
287 ); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
288 if (result) return result; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
289 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
290 return 0; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
291 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
292 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
293 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
294 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
295 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
296 * Parses a search query and returns an object |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
297 * with tokens and fields ready to be populated |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
298 * with results. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
299 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
300 * @param {string} query |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
301 * @param {object} options |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
302 * @returns {object} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
303 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
304 Sifter.prototype.prepareSearch = function(query, options) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
305 if (typeof query === 'object') return query; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
306 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
307 options = extend({}, options); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
308 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
309 var option_fields = options.fields; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
310 var option_sort = options.sort; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
311 var option_sort_empty = options.sort_empty; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
312 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
313 if (option_fields && !is_array(option_fields)) options.fields = [option_fields]; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
314 if (option_sort && !is_array(option_sort)) options.sort = [option_sort]; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
315 if (option_sort_empty && !is_array(option_sort_empty)) options.sort_empty = [option_sort_empty]; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
316 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
317 return { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
318 options : options, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
319 query : String(query || '').toLowerCase(), |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
320 tokens : this.tokenize(query), |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
321 total : 0, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
322 items : [] |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
323 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
324 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
325 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
326 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
327 * Searches through all items and returns a sorted array of matches. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
328 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
329 * The `options` parameter can contain: |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
330 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
331 * - fields {string|array} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
332 * - sort {array} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
333 * - score {function} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
334 * - filter {bool} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
335 * - limit {integer} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
336 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
337 * Returns an object containing: |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
338 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
339 * - options {object} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
340 * - query {string} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
341 * - tokens {array} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
342 * - total {int} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
343 * - items {array} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
344 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
345 * @param {string} query |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
346 * @param {object} options |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
347 * @returns {object} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
348 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
349 Sifter.prototype.search = function(query, options) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
350 var self = this, value, score, search, calculateScore; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
351 var fn_sort; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
352 var fn_score; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
353 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
354 search = this.prepareSearch(query, options); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
355 options = search.options; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
356 query = search.query; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
357 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
358 // generate result scoring function |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
359 fn_score = options.score || self.getScoreFunction(search); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
360 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
361 // perform search and sort |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
362 if (query.length) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
363 self.iterator(self.items, function(item, id) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
364 score = fn_score(item); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
365 if (options.filter === false || score > 0) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
366 search.items.push({'score': score, 'id': id}); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
367 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
368 }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
369 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
370 self.iterator(self.items, function(item, id) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
371 search.items.push({'score': 1, 'id': id}); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
372 }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
373 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
374 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
375 fn_sort = self.getSortFunction(search, options); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
376 if (fn_sort) search.items.sort(fn_sort); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
377 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
378 // apply limits |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
379 search.total = search.items.length; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
380 if (typeof options.limit === 'number') { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
381 search.items = search.items.slice(0, options.limit); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
382 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
383 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
384 return search; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
385 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
386 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
387 // utilities |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
388 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
389 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
390 var cmp = function(a, b) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
391 if (typeof a === 'number' && typeof b === 'number') { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
392 return a > b ? 1 : (a < b ? -1 : 0); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
393 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
394 a = asciifold(String(a || '')); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
395 b = asciifold(String(b || '')); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
396 if (a > b) return 1; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
397 if (b > a) return -1; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
398 return 0; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
399 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
400 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
401 var extend = function(a, b) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
402 var i, n, k, object; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
403 for (i = 1, n = arguments.length; i < n; i++) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
404 object = arguments[i]; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
405 if (!object) continue; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
406 for (k in object) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
407 if (object.hasOwnProperty(k)) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
408 a[k] = object[k]; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
409 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
410 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
411 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
412 return a; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
413 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
414 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
415 var trim = function(str) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
416 return (str + '').replace(/^\s+|\s+$|/g, ''); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
417 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
418 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
419 var escape_regex = function(str) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
420 return (str + '').replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
421 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
422 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
423 var is_array = Array.isArray || ($ && $.isArray) || function(object) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
424 return Object.prototype.toString.call(object) === '[object Array]'; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
425 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
426 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
427 var DIACRITICS = { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
428 'a': '[aÀÁÂÃÄÅàáâãäåĀāąĄ]', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
429 'c': '[cÇçćĆčČ]', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
430 'd': '[dđĐďĎ]', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
431 'e': '[eÈÉÊËèéêëěĚĒēęĘ]', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
432 'i': '[iÌÍÎÏìíîïĪī]', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
433 'l': '[lłŁ]', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
434 'n': '[nÑñňŇńŃ]', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
435 'o': '[oÒÓÔÕÕÖØòóôõöøŌō]', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
436 'r': '[rřŘ]', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
437 's': '[sŠšśŚ]', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
438 't': '[tťŤ]', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
439 'u': '[uÙÚÛÜùúûüůŮŪū]', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
440 'y': '[yŸÿýÝ]', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
441 'z': '[zŽžżŻźŹ]' |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
442 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
443 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
444 var asciifold = (function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
445 var i, n, k, chunk; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
446 var foreignletters = ''; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
447 var lookup = {}; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
448 for (k in DIACRITICS) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
449 if (DIACRITICS.hasOwnProperty(k)) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
450 chunk = DIACRITICS[k].substring(2, DIACRITICS[k].length - 1); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
451 foreignletters += chunk; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
452 for (i = 0, n = chunk.length; i < n; i++) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
453 lookup[chunk.charAt(i)] = k; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
454 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
455 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
456 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
457 var regexp = new RegExp('[' + foreignletters + ']', 'g'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
458 return function(str) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
459 return str.replace(regexp, function(foreignletter) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
460 return lookup[foreignletter]; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
461 }).toLowerCase(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
462 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
463 })(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
464 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
465 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
466 // export |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
467 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
468 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
469 return Sifter; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
470 })); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
471 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
472 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
473 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
474 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
475 * microplugin.js |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
476 * Copyright (c) 2013 Brian Reavis & contributors |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
477 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
478 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
479 * file except in compliance with the License. You may obtain a copy of the License at: |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
480 * http://www.apache.org/licenses/LICENSE-2.0 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
481 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
482 * Unless required by applicable law or agreed to in writing, software distributed under |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
483 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
484 * ANY KIND, either express or implied. See the License for the specific language |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
485 * governing permissions and limitations under the License. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
486 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
487 * @author Brian Reavis <brian@thirdroute.com> |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
488 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
489 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
490 (function(root, factory) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
491 if (typeof define === 'function' && define.amd) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
492 define('microplugin', factory); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
493 } else if (typeof exports === 'object') { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
494 module.exports = factory(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
495 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
496 root.MicroPlugin = factory(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
497 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
498 }(this, function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
499 var MicroPlugin = {}; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
500 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
501 MicroPlugin.mixin = function(Interface) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
502 Interface.plugins = {}; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
503 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
504 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
505 * Initializes the listed plugins (with options). |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
506 * Acceptable formats: |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
507 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
508 * List (without options): |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
509 * ['a', 'b', 'c'] |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
510 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
511 * List (with options): |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
512 * [{'name': 'a', options: {}}, {'name': 'b', options: {}}] |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
513 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
514 * Hash (with options): |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
515 * {'a': { ... }, 'b': { ... }, 'c': { ... }} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
516 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
517 * @param {mixed} plugins |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
518 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
519 Interface.prototype.initializePlugins = function(plugins) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
520 var i, n, key; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
521 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
522 var queue = []; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
523 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
524 self.plugins = { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
525 names : [], |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
526 settings : {}, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
527 requested : {}, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
528 loaded : {} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
529 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
530 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
531 if (utils.isArray(plugins)) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
532 for (i = 0, n = plugins.length; i < n; i++) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
533 if (typeof plugins[i] === 'string') { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
534 queue.push(plugins[i]); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
535 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
536 self.plugins.settings[plugins[i].name] = plugins[i].options; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
537 queue.push(plugins[i].name); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
538 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
539 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
540 } else if (plugins) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
541 for (key in plugins) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
542 if (plugins.hasOwnProperty(key)) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
543 self.plugins.settings[key] = plugins[key]; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
544 queue.push(key); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
545 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
546 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
547 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
548 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
549 while (queue.length) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
550 self.require(queue.shift()); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
551 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
552 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
553 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
554 Interface.prototype.loadPlugin = function(name) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
555 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
556 var plugins = self.plugins; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
557 var plugin = Interface.plugins[name]; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
558 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
559 if (!Interface.plugins.hasOwnProperty(name)) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
560 throw new Error('Unable to find "' + name + '" plugin'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
561 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
562 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
563 plugins.requested[name] = true; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
564 plugins.loaded[name] = plugin.fn.apply(self, [self.plugins.settings[name] || {}]); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
565 plugins.names.push(name); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
566 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
567 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
568 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
569 * Initializes a plugin. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
570 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
571 * @param {string} name |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
572 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
573 Interface.prototype.require = function(name) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
574 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
575 var plugins = self.plugins; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
576 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
577 if (!self.plugins.loaded.hasOwnProperty(name)) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
578 if (plugins.requested[name]) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
579 throw new Error('Plugin has circular dependency ("' + name + '")'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
580 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
581 self.loadPlugin(name); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
582 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
583 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
584 return plugins.loaded[name]; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
585 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
586 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
587 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
588 * Registers a plugin. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
589 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
590 * @param {string} name |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
591 * @param {function} fn |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
592 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
593 Interface.define = function(name, fn) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
594 Interface.plugins[name] = { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
595 'name' : name, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
596 'fn' : fn |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
597 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
598 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
599 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
600 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
601 var utils = { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
602 isArray: Array.isArray || function(vArg) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
603 return Object.prototype.toString.call(vArg) === '[object Array]'; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
604 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
605 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
606 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
607 return MicroPlugin; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
608 })); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
609 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
610 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
611 * selectize.js (v0.12.1) |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
612 * Copyright (c) 2013–2015 Brian Reavis & contributors |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
613 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
614 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
615 * file except in compliance with the License. You may obtain a copy of the License at: |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
616 * http://www.apache.org/licenses/LICENSE-2.0 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
617 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
618 * Unless required by applicable law or agreed to in writing, software distributed under |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
619 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
620 * ANY KIND, either express or implied. See the License for the specific language |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
621 * governing permissions and limitations under the License. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
622 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
623 * @author Brian Reavis <brian@thirdroute.com> |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
624 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
625 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
626 /*jshint curly:false */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
627 /*jshint browser:true */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
628 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
629 (function(root, factory) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
630 if (typeof define === 'function' && define.amd) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
631 define('selectize', ['jquery','sifter','microplugin'], factory); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
632 } else if (typeof exports === 'object') { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
633 module.exports = factory(require('jquery'), require('sifter'), require('microplugin')); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
634 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
635 root.Selectize = factory(root.jQuery, root.Sifter, root.MicroPlugin); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
636 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
637 }(this, function($, Sifter, MicroPlugin) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
638 'use strict'; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
639 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
640 var highlight = function($element, pattern) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
641 if (typeof pattern === 'string' && !pattern.length) return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
642 var regex = (typeof pattern === 'string') ? new RegExp(pattern, 'i') : pattern; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
643 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
644 var highlight = function(node) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
645 var skip = 0; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
646 if (node.nodeType === 3) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
647 var pos = node.data.search(regex); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
648 if (pos >= 0 && node.data.length > 0) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
649 var match = node.data.match(regex); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
650 var spannode = document.createElement('span'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
651 spannode.className = 'highlight'; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
652 var middlebit = node.splitText(pos); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
653 var endbit = middlebit.splitText(match[0].length); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
654 var middleclone = middlebit.cloneNode(true); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
655 spannode.appendChild(middleclone); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
656 middlebit.parentNode.replaceChild(spannode, middlebit); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
657 skip = 1; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
658 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
659 } else if (node.nodeType === 1 && node.childNodes && !/(script|style)/i.test(node.tagName)) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
660 for (var i = 0; i < node.childNodes.length; ++i) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
661 i += highlight(node.childNodes[i]); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
662 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
663 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
664 return skip; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
665 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
666 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
667 return $element.each(function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
668 highlight(this); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
669 }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
670 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
671 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
672 var MicroEvent = function() {}; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
673 MicroEvent.prototype = { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
674 on: function(event, fct){ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
675 this._events = this._events || {}; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
676 this._events[event] = this._events[event] || []; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
677 this._events[event].push(fct); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
678 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
679 off: function(event, fct){ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
680 var n = arguments.length; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
681 if (n === 0) return delete this._events; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
682 if (n === 1) return delete this._events[event]; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
683 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
684 this._events = this._events || {}; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
685 if (event in this._events === false) return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
686 this._events[event].splice(this._events[event].indexOf(fct), 1); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
687 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
688 trigger: function(event /* , args... */){ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
689 this._events = this._events || {}; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
690 if (event in this._events === false) return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
691 for (var i = 0; i < this._events[event].length; i++){ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
692 this._events[event][i].apply(this, Array.prototype.slice.call(arguments, 1)); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
693 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
694 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
695 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
696 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
697 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
698 * Mixin will delegate all MicroEvent.js function in the destination object. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
699 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
700 * - MicroEvent.mixin(Foobar) will make Foobar able to use MicroEvent |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
701 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
702 * @param {object} the object which will support MicroEvent |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
703 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
704 MicroEvent.mixin = function(destObject){ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
705 var props = ['on', 'off', 'trigger']; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
706 for (var i = 0; i < props.length; i++){ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
707 destObject.prototype[props[i]] = MicroEvent.prototype[props[i]]; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
708 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
709 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
710 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
711 var IS_MAC = /Mac/.test(navigator.userAgent); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
712 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
713 var KEY_A = 65; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
714 var KEY_COMMA = 188; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
715 var KEY_RETURN = 13; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
716 var KEY_ESC = 27; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
717 var KEY_LEFT = 37; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
718 var KEY_UP = 38; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
719 var KEY_P = 80; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
720 var KEY_RIGHT = 39; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
721 var KEY_DOWN = 40; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
722 var KEY_N = 78; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
723 var KEY_BACKSPACE = 8; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
724 var KEY_DELETE = 46; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
725 var KEY_SHIFT = 16; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
726 var KEY_CMD = IS_MAC ? 91 : 17; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
727 var KEY_CTRL = IS_MAC ? 18 : 17; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
728 var KEY_TAB = 9; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
729 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
730 var TAG_SELECT = 1; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
731 var TAG_INPUT = 2; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
732 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
733 // for now, android support in general is too spotty to support validity |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
734 var SUPPORTS_VALIDITY_API = !/android/i.test(window.navigator.userAgent) && !!document.createElement('form').validity; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
735 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
736 var isset = function(object) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
737 return typeof object !== 'undefined'; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
738 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
739 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
740 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
741 * Converts a scalar to its best string representation |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
742 * for hash keys and HTML attribute values. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
743 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
744 * Transformations: |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
745 * 'str' -> 'str' |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
746 * null -> '' |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
747 * undefined -> '' |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
748 * true -> '1' |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
749 * false -> '0' |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
750 * 0 -> '0' |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
751 * 1 -> '1' |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
752 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
753 * @param {string} value |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
754 * @returns {string|null} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
755 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
756 var hash_key = function(value) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
757 if (typeof value === 'undefined' || value === null) return null; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
758 if (typeof value === 'boolean') return value ? '1' : '0'; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
759 return value + ''; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
760 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
761 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
762 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
763 * Escapes a string for use within HTML. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
764 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
765 * @param {string} str |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
766 * @returns {string} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
767 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
768 var escape_html = function(str) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
769 return (str + '') |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
770 .replace(/&/g, '&') |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
771 .replace(/</g, '<') |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
772 .replace(/>/g, '>') |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
773 .replace(/"/g, '"'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
774 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
775 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
776 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
777 * Escapes "$" characters in replacement strings. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
778 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
779 * @param {string} str |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
780 * @returns {string} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
781 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
782 var escape_replace = function(str) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
783 return (str + '').replace(/\$/g, '$$$$'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
784 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
785 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
786 var hook = {}; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
787 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
788 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
789 * Wraps `method` on `self` so that `fn` |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
790 * is invoked before the original method. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
791 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
792 * @param {object} self |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
793 * @param {string} method |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
794 * @param {function} fn |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
795 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
796 hook.before = function(self, method, fn) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
797 var original = self[method]; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
798 self[method] = function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
799 fn.apply(self, arguments); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
800 return original.apply(self, arguments); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
801 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
802 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
803 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
804 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
805 * Wraps `method` on `self` so that `fn` |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
806 * is invoked after the original method. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
807 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
808 * @param {object} self |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
809 * @param {string} method |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
810 * @param {function} fn |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
811 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
812 hook.after = function(self, method, fn) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
813 var original = self[method]; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
814 self[method] = function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
815 var result = original.apply(self, arguments); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
816 fn.apply(self, arguments); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
817 return result; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
818 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
819 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
820 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
821 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
822 * Wraps `fn` so that it can only be invoked once. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
823 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
824 * @param {function} fn |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
825 * @returns {function} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
826 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
827 var once = function(fn) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
828 var called = false; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
829 return function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
830 if (called) return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
831 called = true; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
832 fn.apply(this, arguments); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
833 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
834 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
835 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
836 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
837 * Wraps `fn` so that it can only be called once |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
838 * every `delay` milliseconds (invoked on the falling edge). |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
839 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
840 * @param {function} fn |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
841 * @param {int} delay |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
842 * @returns {function} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
843 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
844 var debounce = function(fn, delay) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
845 var timeout; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
846 return function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
847 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
848 var args = arguments; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
849 window.clearTimeout(timeout); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
850 timeout = window.setTimeout(function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
851 fn.apply(self, args); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
852 }, delay); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
853 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
854 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
855 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
856 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
857 * Debounce all fired events types listed in `types` |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
858 * while executing the provided `fn`. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
859 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
860 * @param {object} self |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
861 * @param {array} types |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
862 * @param {function} fn |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
863 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
864 var debounce_events = function(self, types, fn) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
865 var type; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
866 var trigger = self.trigger; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
867 var event_args = {}; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
868 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
869 // override trigger method |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
870 self.trigger = function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
871 var type = arguments[0]; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
872 if (types.indexOf(type) !== -1) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
873 event_args[type] = arguments; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
874 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
875 return trigger.apply(self, arguments); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
876 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
877 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
878 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
879 // invoke provided function |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
880 fn.apply(self, []); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
881 self.trigger = trigger; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
882 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
883 // trigger queued events |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
884 for (type in event_args) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
885 if (event_args.hasOwnProperty(type)) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
886 trigger.apply(self, event_args[type]); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
887 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
888 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
889 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
890 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
891 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
892 * A workaround for http://bugs.jquery.com/ticket/6696 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
893 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
894 * @param {object} $parent - Parent element to listen on. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
895 * @param {string} event - Event name. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
896 * @param {string} selector - Descendant selector to filter by. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
897 * @param {function} fn - Event handler. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
898 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
899 var watchChildEvent = function($parent, event, selector, fn) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
900 $parent.on(event, selector, function(e) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
901 var child = e.target; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
902 while (child && child.parentNode !== $parent[0]) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
903 child = child.parentNode; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
904 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
905 e.currentTarget = child; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
906 return fn.apply(this, [e]); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
907 }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
908 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
909 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
910 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
911 * Determines the current selection within a text input control. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
912 * Returns an object containing: |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
913 * - start |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
914 * - length |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
915 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
916 * @param {object} input |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
917 * @returns {object} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
918 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
919 var getSelection = function(input) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
920 var result = {}; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
921 if ('selectionStart' in input) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
922 result.start = input.selectionStart; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
923 result.length = input.selectionEnd - result.start; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
924 } else if (document.selection) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
925 input.focus(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
926 var sel = document.selection.createRange(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
927 var selLen = document.selection.createRange().text.length; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
928 sel.moveStart('character', -input.value.length); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
929 result.start = sel.text.length - selLen; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
930 result.length = selLen; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
931 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
932 return result; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
933 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
934 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
935 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
936 * Copies CSS properties from one element to another. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
937 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
938 * @param {object} $from |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
939 * @param {object} $to |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
940 * @param {array} properties |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
941 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
942 var transferStyles = function($from, $to, properties) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
943 var i, n, styles = {}; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
944 if (properties) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
945 for (i = 0, n = properties.length; i < n; i++) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
946 styles[properties[i]] = $from.css(properties[i]); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
947 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
948 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
949 styles = $from.css(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
950 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
951 $to.css(styles); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
952 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
953 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
954 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
955 * Measures the width of a string within a |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
956 * parent element (in pixels). |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
957 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
958 * @param {string} str |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
959 * @param {object} $parent |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
960 * @returns {int} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
961 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
962 var measureString = function(str, $parent) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
963 if (!str) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
964 return 0; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
965 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
966 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
967 var $test = $('<test>').css({ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
968 position: 'absolute', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
969 top: -99999, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
970 left: -99999, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
971 width: 'auto', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
972 padding: 0, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
973 whiteSpace: 'pre' |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
974 }).text(str).appendTo('body'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
975 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
976 transferStyles($parent, $test, [ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
977 'letterSpacing', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
978 'fontSize', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
979 'fontFamily', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
980 'fontWeight', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
981 'textTransform' |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
982 ]); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
983 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
984 var width = $test.width(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
985 $test.remove(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
986 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
987 return width; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
988 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
989 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
990 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
991 * Sets up an input to grow horizontally as the user |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
992 * types. If the value is changed manually, you can |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
993 * trigger the "update" handler to resize: |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
994 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
995 * $input.trigger('update'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
996 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
997 * @param {object} $input |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
998 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
999 var autoGrow = function($input) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1000 var currentWidth = null; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1001 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1002 var update = function(e, options) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1003 var value, keyCode, printable, placeholder, width; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1004 var shift, character, selection; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1005 e = e || window.event || {}; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1006 options = options || {}; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1007 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1008 if (e.metaKey || e.altKey) return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1009 if (!options.force && $input.data('grow') === false) return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1010 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1011 value = $input.val(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1012 if (e.type && e.type.toLowerCase() === 'keydown') { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1013 keyCode = e.keyCode; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1014 printable = ( |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1015 (keyCode >= 97 && keyCode <= 122) || // a-z |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1016 (keyCode >= 65 && keyCode <= 90) || // A-Z |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1017 (keyCode >= 48 && keyCode <= 57) || // 0-9 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1018 keyCode === 32 // space |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1019 ); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1020 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1021 if (keyCode === KEY_DELETE || keyCode === KEY_BACKSPACE) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1022 selection = getSelection($input[0]); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1023 if (selection.length) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1024 value = value.substring(0, selection.start) + value.substring(selection.start + selection.length); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1025 } else if (keyCode === KEY_BACKSPACE && selection.start) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1026 value = value.substring(0, selection.start - 1) + value.substring(selection.start + 1); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1027 } else if (keyCode === KEY_DELETE && typeof selection.start !== 'undefined') { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1028 value = value.substring(0, selection.start) + value.substring(selection.start + 1); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1029 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1030 } else if (printable) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1031 shift = e.shiftKey; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1032 character = String.fromCharCode(e.keyCode); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1033 if (shift) character = character.toUpperCase(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1034 else character = character.toLowerCase(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1035 value += character; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1036 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1037 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1038 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1039 placeholder = $input.attr('placeholder'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1040 if (!value && placeholder) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1041 value = placeholder; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1042 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1043 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1044 width = measureString(value, $input) + 4; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1045 if (width !== currentWidth) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1046 currentWidth = width; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1047 $input.width(width); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1048 $input.triggerHandler('resize'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1049 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1050 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1051 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1052 $input.on('keydown keyup update blur', update); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1053 update(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1054 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1055 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1056 var Selectize = function($input, settings) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1057 var key, i, n, dir, input, self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1058 input = $input[0]; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1059 input.selectize = self; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1060 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1061 // detect rtl environment |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1062 var computedStyle = window.getComputedStyle && window.getComputedStyle(input, null); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1063 dir = computedStyle ? computedStyle.getPropertyValue('direction') : input.currentStyle && input.currentStyle.direction; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1064 dir = dir || $input.parents('[dir]:first').attr('dir') || ''; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1065 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1066 // setup default state |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1067 $.extend(self, { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1068 order : 0, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1069 settings : settings, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1070 $input : $input, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1071 tabIndex : $input.attr('tabindex') || '', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1072 tagType : input.tagName.toLowerCase() === 'select' ? TAG_SELECT : TAG_INPUT, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1073 rtl : /rtl/i.test(dir), |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1074 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1075 eventNS : '.selectize' + (++Selectize.count), |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1076 highlightedValue : null, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1077 isOpen : false, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1078 isDisabled : false, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1079 isRequired : $input.is('[required]'), |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1080 isInvalid : false, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1081 isLocked : false, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1082 isFocused : false, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1083 isInputHidden : false, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1084 isSetup : false, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1085 isShiftDown : false, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1086 isCmdDown : false, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1087 isCtrlDown : false, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1088 ignoreFocus : false, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1089 ignoreBlur : false, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1090 ignoreHover : false, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1091 hasOptions : false, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1092 currentResults : null, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1093 lastValue : '', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1094 caretPos : 0, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1095 loading : 0, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1096 loadedSearches : {}, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1097 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1098 $activeOption : null, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1099 $activeItems : [], |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1100 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1101 optgroups : {}, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1102 options : {}, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1103 userOptions : {}, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1104 items : [], |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1105 renderCache : {}, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1106 onSearchChange : settings.loadThrottle === null ? self.onSearchChange : debounce(self.onSearchChange, settings.loadThrottle) |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1107 }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1108 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1109 // search system |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1110 self.sifter = new Sifter(this.options, {diacritics: settings.diacritics}); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1111 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1112 // build options table |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1113 if (self.settings.options) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1114 for (i = 0, n = self.settings.options.length; i < n; i++) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1115 self.registerOption(self.settings.options[i]); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1116 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1117 delete self.settings.options; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1118 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1119 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1120 // build optgroup table |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1121 if (self.settings.optgroups) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1122 for (i = 0, n = self.settings.optgroups.length; i < n; i++) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1123 self.registerOptionGroup(self.settings.optgroups[i]); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1124 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1125 delete self.settings.optgroups; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1126 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1127 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1128 // option-dependent defaults |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1129 self.settings.mode = self.settings.mode || (self.settings.maxItems === 1 ? 'single' : 'multi'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1130 if (typeof self.settings.hideSelected !== 'boolean') { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1131 self.settings.hideSelected = self.settings.mode === 'multi'; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1132 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1133 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1134 self.initializePlugins(self.settings.plugins); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1135 self.setupCallbacks(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1136 self.setupTemplates(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1137 self.setup(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1138 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1139 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1140 // mixins |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1141 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1142 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1143 MicroEvent.mixin(Selectize); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1144 MicroPlugin.mixin(Selectize); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1145 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1146 // methods |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1147 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1148 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1149 $.extend(Selectize.prototype, { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1150 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1151 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1152 * Creates all elements and sets up event bindings. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1153 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1154 setup: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1155 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1156 var settings = self.settings; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1157 var eventNS = self.eventNS; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1158 var $window = $(window); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1159 var $document = $(document); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1160 var $input = self.$input; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1161 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1162 var $wrapper; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1163 var $control; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1164 var $control_input; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1165 var $dropdown; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1166 var $dropdown_content; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1167 var $dropdown_parent; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1168 var inputMode; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1169 var timeout_blur; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1170 var timeout_focus; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1171 var classes; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1172 var classes_plugins; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1173 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1174 inputMode = self.settings.mode; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1175 classes = $input.attr('class') || ''; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1176 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1177 $wrapper = $('<div>').addClass(settings.wrapperClass).addClass(classes).addClass(inputMode); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1178 $control = $('<div>').addClass(settings.inputClass).addClass('items').appendTo($wrapper); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1179 $control_input = $('<input type="text" autocomplete="off" />').appendTo($control).attr('tabindex', $input.is(':disabled') ? '-1' : self.tabIndex); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1180 $dropdown_parent = $(settings.dropdownParent || $wrapper); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1181 $dropdown = $('<div>').addClass(settings.dropdownClass).addClass(inputMode).hide().appendTo($dropdown_parent); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1182 $dropdown_content = $('<div>').addClass(settings.dropdownContentClass).appendTo($dropdown); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1183 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1184 if(self.settings.copyClassesToDropdown) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1185 $dropdown.addClass(classes); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1186 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1187 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1188 $wrapper.css({ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1189 width: $input[0].style.width |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1190 }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1191 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1192 if (self.plugins.names.length) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1193 classes_plugins = 'plugin-' + self.plugins.names.join(' plugin-'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1194 $wrapper.addClass(classes_plugins); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1195 $dropdown.addClass(classes_plugins); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1196 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1197 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1198 if ((settings.maxItems === null || settings.maxItems > 1) && self.tagType === TAG_SELECT) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1199 $input.attr('multiple', 'multiple'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1200 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1201 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1202 if (self.settings.placeholder) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1203 $control_input.attr('placeholder', settings.placeholder); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1204 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1205 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1206 // if splitOn was not passed in, construct it from the delimiter to allow pasting universally |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1207 if (!self.settings.splitOn && self.settings.delimiter) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1208 var delimiterEscaped = self.settings.delimiter.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1209 self.settings.splitOn = new RegExp('\\s*' + delimiterEscaped + '+\\s*'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1210 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1211 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1212 if ($input.attr('autocorrect')) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1213 $control_input.attr('autocorrect', $input.attr('autocorrect')); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1214 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1215 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1216 if ($input.attr('autocapitalize')) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1217 $control_input.attr('autocapitalize', $input.attr('autocapitalize')); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1218 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1219 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1220 self.$wrapper = $wrapper; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1221 self.$control = $control; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1222 self.$control_input = $control_input; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1223 self.$dropdown = $dropdown; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1224 self.$dropdown_content = $dropdown_content; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1225 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1226 $dropdown.on('mouseenter', '[data-selectable]', function() { return self.onOptionHover.apply(self, arguments); }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1227 $dropdown.on('mousedown click', '[data-selectable]', function() { return self.onOptionSelect.apply(self, arguments); }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1228 watchChildEvent($control, 'mousedown', '*:not(input)', function() { return self.onItemSelect.apply(self, arguments); }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1229 autoGrow($control_input); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1230 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1231 $control.on({ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1232 mousedown : function() { return self.onMouseDown.apply(self, arguments); }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1233 click : function() { return self.onClick.apply(self, arguments); } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1234 }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1235 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1236 $control_input.on({ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1237 mousedown : function(e) { e.stopPropagation(); }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1238 keydown : function() { return self.onKeyDown.apply(self, arguments); }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1239 keyup : function() { return self.onKeyUp.apply(self, arguments); }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1240 keypress : function() { return self.onKeyPress.apply(self, arguments); }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1241 resize : function() { self.positionDropdown.apply(self, []); }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1242 blur : function() { return self.onBlur.apply(self, arguments); }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1243 focus : function() { self.ignoreBlur = false; return self.onFocus.apply(self, arguments); }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1244 paste : function() { return self.onPaste.apply(self, arguments); } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1245 }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1246 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1247 $document.on('keydown' + eventNS, function(e) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1248 self.isCmdDown = e[IS_MAC ? 'metaKey' : 'ctrlKey']; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1249 self.isCtrlDown = e[IS_MAC ? 'altKey' : 'ctrlKey']; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1250 self.isShiftDown = e.shiftKey; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1251 }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1252 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1253 $document.on('keyup' + eventNS, function(e) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1254 if (e.keyCode === KEY_CTRL) self.isCtrlDown = false; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1255 if (e.keyCode === KEY_SHIFT) self.isShiftDown = false; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1256 if (e.keyCode === KEY_CMD) self.isCmdDown = false; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1257 }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1258 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1259 $document.on('mousedown' + eventNS, function(e) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1260 if (self.isFocused) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1261 // prevent events on the dropdown scrollbar from causing the control to blur |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1262 if (e.target === self.$dropdown[0] || e.target.parentNode === self.$dropdown[0]) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1263 return false; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1264 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1265 // blur on click outside |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1266 if (!self.$control.has(e.target).length && e.target !== self.$control[0]) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1267 self.blur(e.target); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1268 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1269 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1270 }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1271 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1272 $window.on(['scroll' + eventNS, 'resize' + eventNS].join(' '), function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1273 if (self.isOpen) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1274 self.positionDropdown.apply(self, arguments); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1275 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1276 }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1277 $window.on('mousemove' + eventNS, function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1278 self.ignoreHover = false; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1279 }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1280 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1281 // store original children and tab index so that they can be |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1282 // restored when the destroy() method is called. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1283 this.revertSettings = { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1284 $children : $input.children().detach(), |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1285 tabindex : $input.attr('tabindex') |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1286 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1287 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1288 $input.attr('tabindex', -1).hide().after(self.$wrapper); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1289 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1290 if ($.isArray(settings.items)) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1291 self.setValue(settings.items); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1292 delete settings.items; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1293 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1294 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1295 // feature detect for the validation API |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1296 if (SUPPORTS_VALIDITY_API) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1297 $input.on('invalid' + eventNS, function(e) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1298 e.preventDefault(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1299 self.isInvalid = true; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1300 self.refreshState(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1301 }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1302 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1303 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1304 self.updateOriginalInput(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1305 self.refreshItems(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1306 self.refreshState(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1307 self.updatePlaceholder(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1308 self.isSetup = true; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1309 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1310 if ($input.is(':disabled')) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1311 self.disable(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1312 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1313 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1314 self.on('change', this.onChange); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1315 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1316 $input.data('selectize', self); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1317 $input.addClass('selectized'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1318 self.trigger('initialize'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1319 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1320 // preload options |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1321 if (settings.preload === true) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1322 self.onSearchChange(''); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1323 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1324 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1325 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1326 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1327 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1328 * Sets up default rendering functions. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1329 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1330 setupTemplates: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1331 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1332 var field_label = self.settings.labelField; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1333 var field_optgroup = self.settings.optgroupLabelField; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1334 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1335 var templates = { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1336 'optgroup': function(data) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1337 return '<div class="optgroup">' + data.html + '</div>'; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1338 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1339 'optgroup_header': function(data, escape) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1340 return '<div class="optgroup-header">' + escape(data[field_optgroup]) + '</div>'; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1341 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1342 'option': function(data, escape) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1343 return '<div class="option">' + escape(data[field_label]) + '</div>'; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1344 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1345 'item': function(data, escape) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1346 return '<div class="item">' + escape(data[field_label]) + '</div>'; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1347 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1348 'option_create': function(data, escape) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1349 return '<div class="create">Add <strong>' + escape(data.input) + '</strong>…</div>'; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1350 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1351 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1352 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1353 self.settings.render = $.extend({}, templates, self.settings.render); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1354 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1355 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1356 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1357 * Maps fired events to callbacks provided |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1358 * in the settings used when creating the control. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1359 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1360 setupCallbacks: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1361 var key, fn, callbacks = { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1362 'initialize' : 'onInitialize', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1363 'change' : 'onChange', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1364 'item_add' : 'onItemAdd', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1365 'item_remove' : 'onItemRemove', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1366 'clear' : 'onClear', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1367 'option_add' : 'onOptionAdd', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1368 'option_remove' : 'onOptionRemove', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1369 'option_clear' : 'onOptionClear', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1370 'optgroup_add' : 'onOptionGroupAdd', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1371 'optgroup_remove' : 'onOptionGroupRemove', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1372 'optgroup_clear' : 'onOptionGroupClear', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1373 'dropdown_open' : 'onDropdownOpen', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1374 'dropdown_close' : 'onDropdownClose', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1375 'type' : 'onType', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1376 'load' : 'onLoad', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1377 'focus' : 'onFocus', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1378 'blur' : 'onBlur' |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1379 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1380 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1381 for (key in callbacks) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1382 if (callbacks.hasOwnProperty(key)) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1383 fn = this.settings[callbacks[key]]; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1384 if (fn) this.on(key, fn); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1385 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1386 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1387 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1388 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1389 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1390 * Triggered when the main control element |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1391 * has a click event. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1392 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1393 * @param {object} e |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1394 * @return {boolean} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1395 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1396 onClick: function(e) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1397 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1398 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1399 // necessary for mobile webkit devices (manual focus triggering |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1400 // is ignored unless invoked within a click event) |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1401 if (!self.isFocused) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1402 self.focus(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1403 e.preventDefault(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1404 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1405 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1406 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1407 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1408 * Triggered when the main control element |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1409 * has a mouse down event. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1410 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1411 * @param {object} e |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1412 * @return {boolean} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1413 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1414 onMouseDown: function(e) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1415 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1416 var defaultPrevented = e.isDefaultPrevented(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1417 var $target = $(e.target); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1418 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1419 if (self.isFocused) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1420 // retain focus by preventing native handling. if the |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1421 // event target is the input it should not be modified. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1422 // otherwise, text selection within the input won't work. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1423 if (e.target !== self.$control_input[0]) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1424 if (self.settings.mode === 'single') { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1425 // toggle dropdown |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1426 self.isOpen ? self.close() : self.open(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1427 } else if (!defaultPrevented) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1428 self.setActiveItem(null); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1429 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1430 return false; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1431 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1432 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1433 // give control focus |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1434 if (!defaultPrevented) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1435 window.setTimeout(function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1436 self.focus(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1437 }, 0); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1438 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1439 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1440 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1441 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1442 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1443 * Triggered when the value of the control has been changed. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1444 * This should propagate the event to the original DOM |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1445 * input / select element. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1446 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1447 onChange: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1448 this.$input.trigger('change'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1449 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1450 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1451 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1452 * Triggered on <input> paste. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1453 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1454 * @param {object} e |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1455 * @returns {boolean} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1456 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1457 onPaste: function(e) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1458 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1459 if (self.isFull() || self.isInputHidden || self.isLocked) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1460 e.preventDefault(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1461 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1462 // If a regex or string is included, this will split the pasted |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1463 // input and create Items for each separate value |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1464 if (self.settings.splitOn) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1465 setTimeout(function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1466 var splitInput = $.trim(self.$control_input.val() || '').split(self.settings.splitOn); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1467 for (var i = 0, n = splitInput.length; i < n; i++) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1468 self.createItem(splitInput[i]); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1469 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1470 }, 0); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1471 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1472 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1473 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1474 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1475 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1476 * Triggered on <input> keypress. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1477 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1478 * @param {object} e |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1479 * @returns {boolean} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1480 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1481 onKeyPress: function(e) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1482 if (this.isLocked) return e && e.preventDefault(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1483 var character = String.fromCharCode(e.keyCode || e.which); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1484 if (this.settings.create && this.settings.mode === 'multi' && character === this.settings.delimiter) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1485 this.createItem(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1486 e.preventDefault(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1487 return false; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1488 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1489 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1490 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1491 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1492 * Triggered on <input> keydown. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1493 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1494 * @param {object} e |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1495 * @returns {boolean} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1496 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1497 onKeyDown: function(e) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1498 var isInput = e.target === this.$control_input[0]; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1499 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1500 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1501 if (self.isLocked) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1502 if (e.keyCode !== KEY_TAB) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1503 e.preventDefault(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1504 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1505 return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1506 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1507 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1508 switch (e.keyCode) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1509 case KEY_A: |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1510 if (self.isCmdDown) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1511 self.selectAll(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1512 return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1513 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1514 break; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1515 case KEY_ESC: |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1516 if (self.isOpen) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1517 e.preventDefault(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1518 e.stopPropagation(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1519 self.close(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1520 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1521 return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1522 case KEY_N: |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1523 if (!e.ctrlKey || e.altKey) break; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1524 case KEY_DOWN: |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1525 if (!self.isOpen && self.hasOptions) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1526 self.open(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1527 } else if (self.$activeOption) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1528 self.ignoreHover = true; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1529 var $next = self.getAdjacentOption(self.$activeOption, 1); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1530 if ($next.length) self.setActiveOption($next, true, true); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1531 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1532 e.preventDefault(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1533 return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1534 case KEY_P: |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1535 if (!e.ctrlKey || e.altKey) break; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1536 case KEY_UP: |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1537 if (self.$activeOption) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1538 self.ignoreHover = true; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1539 var $prev = self.getAdjacentOption(self.$activeOption, -1); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1540 if ($prev.length) self.setActiveOption($prev, true, true); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1541 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1542 e.preventDefault(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1543 return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1544 case KEY_RETURN: |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1545 if (self.isOpen && self.$activeOption) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1546 self.onOptionSelect({currentTarget: self.$activeOption}); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1547 e.preventDefault(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1548 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1549 return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1550 case KEY_LEFT: |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1551 self.advanceSelection(-1, e); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1552 return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1553 case KEY_RIGHT: |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1554 self.advanceSelection(1, e); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1555 return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1556 case KEY_TAB: |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1557 if (self.settings.selectOnTab && self.isOpen && self.$activeOption) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1558 self.onOptionSelect({currentTarget: self.$activeOption}); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1559 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1560 // Default behaviour is to jump to the next field, we only want this |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1561 // if the current field doesn't accept any more entries |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1562 if (!self.isFull()) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1563 e.preventDefault(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1564 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1565 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1566 if (self.settings.create && self.createItem()) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1567 e.preventDefault(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1568 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1569 return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1570 case KEY_BACKSPACE: |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1571 case KEY_DELETE: |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1572 self.deleteSelection(e); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1573 return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1574 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1575 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1576 if ((self.isFull() || self.isInputHidden) && !(IS_MAC ? e.metaKey : e.ctrlKey)) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1577 e.preventDefault(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1578 return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1579 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1580 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1581 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1582 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1583 * Triggered on <input> keyup. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1584 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1585 * @param {object} e |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1586 * @returns {boolean} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1587 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1588 onKeyUp: function(e) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1589 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1590 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1591 if (self.isLocked) return e && e.preventDefault(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1592 var value = self.$control_input.val() || ''; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1593 if (self.lastValue !== value) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1594 self.lastValue = value; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1595 self.onSearchChange(value); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1596 self.refreshOptions(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1597 self.trigger('type', value); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1598 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1599 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1600 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1601 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1602 * Invokes the user-provide option provider / loader. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1603 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1604 * Note: this function is debounced in the Selectize |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1605 * constructor (by `settings.loadDelay` milliseconds) |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1606 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1607 * @param {string} value |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1608 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1609 onSearchChange: function(value) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1610 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1611 var fn = self.settings.load; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1612 if (!fn) return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1613 if (self.loadedSearches.hasOwnProperty(value)) return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1614 self.loadedSearches[value] = true; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1615 self.load(function(callback) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1616 fn.apply(self, [value, callback]); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1617 }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1618 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1619 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1620 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1621 * Triggered on <input> focus. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1622 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1623 * @param {object} e (optional) |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1624 * @returns {boolean} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1625 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1626 onFocus: function(e) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1627 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1628 var wasFocused = self.isFocused; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1629 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1630 if (self.isDisabled) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1631 self.blur(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1632 e && e.preventDefault(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1633 return false; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1634 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1635 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1636 if (self.ignoreFocus) return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1637 self.isFocused = true; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1638 if (self.settings.preload === 'focus') self.onSearchChange(''); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1639 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1640 if (!wasFocused) self.trigger('focus'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1641 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1642 if (!self.$activeItems.length) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1643 self.showInput(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1644 self.setActiveItem(null); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1645 self.refreshOptions(!!self.settings.openOnFocus); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1646 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1647 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1648 self.refreshState(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1649 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1650 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1651 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1652 * Triggered on <input> blur. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1653 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1654 * @param {object} e |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1655 * @param {Element} dest |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1656 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1657 onBlur: function(e, dest) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1658 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1659 if (!self.isFocused) return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1660 self.isFocused = false; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1661 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1662 if (self.ignoreFocus) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1663 return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1664 } else if (!self.ignoreBlur && document.activeElement === self.$dropdown_content[0]) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1665 // necessary to prevent IE closing the dropdown when the scrollbar is clicked |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1666 self.ignoreBlur = true; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1667 self.onFocus(e); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1668 return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1669 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1670 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1671 var deactivate = function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1672 self.close(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1673 self.setTextboxValue(''); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1674 self.setActiveItem(null); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1675 self.setActiveOption(null); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1676 self.setCaret(self.items.length); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1677 self.refreshState(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1678 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1679 // IE11 bug: element still marked as active |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1680 (dest || document.body).focus(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1681 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1682 self.ignoreFocus = false; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1683 self.trigger('blur'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1684 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1685 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1686 self.ignoreFocus = true; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1687 if (self.settings.create && self.settings.createOnBlur) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1688 self.createItem(null, false, deactivate); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1689 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1690 deactivate(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1691 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1692 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1693 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1694 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1695 * Triggered when the user rolls over |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1696 * an option in the autocomplete dropdown menu. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1697 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1698 * @param {object} e |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1699 * @returns {boolean} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1700 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1701 onOptionHover: function(e) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1702 if (this.ignoreHover) return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1703 this.setActiveOption(e.currentTarget, false); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1704 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1705 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1706 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1707 * Triggered when the user clicks on an option |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1708 * in the autocomplete dropdown menu. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1709 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1710 * @param {object} e |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1711 * @returns {boolean} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1712 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1713 onOptionSelect: function(e) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1714 var value, $target, $option, self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1715 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1716 if (e.preventDefault) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1717 e.preventDefault(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1718 e.stopPropagation(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1719 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1720 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1721 $target = $(e.currentTarget); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1722 if ($target.hasClass('create')) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1723 self.createItem(null, function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1724 if (self.settings.closeAfterSelect) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1725 self.close(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1726 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1727 }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1728 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1729 value = $target.attr('data-value'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1730 if (typeof value !== 'undefined') { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1731 self.lastQuery = null; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1732 self.setTextboxValue(''); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1733 self.addItem(value); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1734 if (self.settings.closeAfterSelect) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1735 self.close(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1736 } else if (!self.settings.hideSelected && e.type && /mouse/.test(e.type)) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1737 self.setActiveOption(self.getOption(value)); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1738 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1739 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1740 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1741 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1742 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1743 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1744 * Triggered when the user clicks on an item |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1745 * that has been selected. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1746 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1747 * @param {object} e |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1748 * @returns {boolean} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1749 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1750 onItemSelect: function(e) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1751 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1752 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1753 if (self.isLocked) return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1754 if (self.settings.mode === 'multi') { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1755 e.preventDefault(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1756 self.setActiveItem(e.currentTarget, e); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1757 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1758 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1759 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1760 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1761 * Invokes the provided method that provides |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1762 * results to a callback---which are then added |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1763 * as options to the control. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1764 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1765 * @param {function} fn |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1766 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1767 load: function(fn) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1768 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1769 var $wrapper = self.$wrapper.addClass(self.settings.loadingClass); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1770 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1771 self.loading++; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1772 fn.apply(self, [function(results) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1773 self.loading = Math.max(self.loading - 1, 0); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1774 if (results && results.length) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1775 self.addOption(results); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1776 self.refreshOptions(self.isFocused && !self.isInputHidden); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1777 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1778 if (!self.loading) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1779 $wrapper.removeClass(self.settings.loadingClass); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1780 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1781 self.trigger('load', results); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1782 }]); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1783 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1784 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1785 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1786 * Sets the input field of the control to the specified value. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1787 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1788 * @param {string} value |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1789 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1790 setTextboxValue: function(value) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1791 var $input = this.$control_input; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1792 var changed = $input.val() !== value; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1793 if (changed) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1794 $input.val(value).triggerHandler('update'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1795 this.lastValue = value; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1796 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1797 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1798 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1799 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1800 * Returns the value of the control. If multiple items |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1801 * can be selected (e.g. <select multiple>), this returns |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1802 * an array. If only one item can be selected, this |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1803 * returns a string. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1804 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1805 * @returns {mixed} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1806 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1807 getValue: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1808 if (this.tagType === TAG_SELECT && this.$input.attr('multiple')) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1809 return this.items; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1810 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1811 return this.items.join(this.settings.delimiter); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1812 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1813 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1814 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1815 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1816 * Resets the selected items to the given value. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1817 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1818 * @param {mixed} value |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1819 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1820 setValue: function(value, silent) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1821 var events = silent ? [] : ['change']; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1822 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1823 debounce_events(this, events, function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1824 this.clear(silent); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1825 this.addItems(value, silent); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1826 }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1827 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1828 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1829 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1830 * Sets the selected item. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1831 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1832 * @param {object} $item |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1833 * @param {object} e (optional) |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1834 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1835 setActiveItem: function($item, e) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1836 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1837 var eventName; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1838 var i, idx, begin, end, item, swap; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1839 var $last; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1840 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1841 if (self.settings.mode === 'single') return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1842 $item = $($item); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1843 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1844 // clear the active selection |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1845 if (!$item.length) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1846 $(self.$activeItems).removeClass('active'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1847 self.$activeItems = []; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1848 if (self.isFocused) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1849 self.showInput(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1850 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1851 return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1852 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1853 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1854 // modify selection |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1855 eventName = e && e.type.toLowerCase(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1856 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1857 if (eventName === 'mousedown' && self.isShiftDown && self.$activeItems.length) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1858 $last = self.$control.children('.active:last'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1859 begin = Array.prototype.indexOf.apply(self.$control[0].childNodes, [$last[0]]); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1860 end = Array.prototype.indexOf.apply(self.$control[0].childNodes, [$item[0]]); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1861 if (begin > end) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1862 swap = begin; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1863 begin = end; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1864 end = swap; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1865 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1866 for (i = begin; i <= end; i++) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1867 item = self.$control[0].childNodes[i]; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1868 if (self.$activeItems.indexOf(item) === -1) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1869 $(item).addClass('active'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1870 self.$activeItems.push(item); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1871 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1872 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1873 e.preventDefault(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1874 } else if ((eventName === 'mousedown' && self.isCtrlDown) || (eventName === 'keydown' && this.isShiftDown)) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1875 if ($item.hasClass('active')) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1876 idx = self.$activeItems.indexOf($item[0]); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1877 self.$activeItems.splice(idx, 1); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1878 $item.removeClass('active'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1879 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1880 self.$activeItems.push($item.addClass('active')[0]); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1881 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1882 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1883 $(self.$activeItems).removeClass('active'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1884 self.$activeItems = [$item.addClass('active')[0]]; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1885 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1886 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1887 // ensure control has focus |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1888 self.hideInput(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1889 if (!this.isFocused) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1890 self.focus(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1891 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1892 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1893 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1894 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1895 * Sets the selected item in the dropdown menu |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1896 * of available options. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1897 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1898 * @param {object} $object |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1899 * @param {boolean} scroll |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1900 * @param {boolean} animate |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1901 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1902 setActiveOption: function($option, scroll, animate) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1903 var height_menu, height_item, y; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1904 var scroll_top, scroll_bottom; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1905 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1906 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1907 if (self.$activeOption) self.$activeOption.removeClass('active'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1908 self.$activeOption = null; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1909 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1910 $option = $($option); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1911 if (!$option.length) return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1912 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1913 self.$activeOption = $option.addClass('active'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1914 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1915 if (scroll || !isset(scroll)) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1916 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1917 height_menu = self.$dropdown_content.height(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1918 height_item = self.$activeOption.outerHeight(true); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1919 scroll = self.$dropdown_content.scrollTop() || 0; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1920 y = self.$activeOption.offset().top - self.$dropdown_content.offset().top + scroll; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1921 scroll_top = y; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1922 scroll_bottom = y - height_menu + height_item; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1923 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1924 if (y + height_item > height_menu + scroll) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1925 self.$dropdown_content.stop().animate({scrollTop: scroll_bottom}, animate ? self.settings.scrollDuration : 0); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1926 } else if (y < scroll) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1927 self.$dropdown_content.stop().animate({scrollTop: scroll_top}, animate ? self.settings.scrollDuration : 0); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1928 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1929 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1930 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1931 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1932 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1933 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1934 * Selects all items (CTRL + A). |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1935 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1936 selectAll: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1937 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1938 if (self.settings.mode === 'single') return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1939 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1940 self.$activeItems = Array.prototype.slice.apply(self.$control.children(':not(input)').addClass('active')); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1941 if (self.$activeItems.length) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1942 self.hideInput(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1943 self.close(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1944 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1945 self.focus(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1946 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1947 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1948 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1949 * Hides the input element out of view, while |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1950 * retaining its focus. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1951 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1952 hideInput: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1953 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1954 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1955 self.setTextboxValue(''); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1956 self.$control_input.css({opacity: 0, position: 'absolute', left: self.rtl ? 10000 : -10000}); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1957 self.isInputHidden = true; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1958 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1959 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1960 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1961 * Restores input visibility. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1962 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1963 showInput: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1964 this.$control_input.css({opacity: 1, position: 'relative', left: 0}); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1965 this.isInputHidden = false; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1966 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1967 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1968 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1969 * Gives the control focus. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1970 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1971 focus: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1972 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1973 if (self.isDisabled) return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1974 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1975 self.ignoreFocus = true; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1976 self.$control_input[0].focus(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1977 window.setTimeout(function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1978 self.ignoreFocus = false; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1979 self.onFocus(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1980 }, 0); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1981 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1982 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1983 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1984 * Forces the control out of focus. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1985 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1986 * @param {Element} dest |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1987 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1988 blur: function(dest) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1989 this.$control_input[0].blur(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1990 this.onBlur(null, dest); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1991 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1992 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1993 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1994 * Returns a function that scores an object |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1995 * to show how good of a match it is to the |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1996 * provided query. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1997 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1998 * @param {string} query |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1999 * @param {object} options |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2000 * @return {function} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2001 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2002 getScoreFunction: function(query) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2003 return this.sifter.getScoreFunction(query, this.getSearchOptions()); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2004 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2005 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2006 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2007 * Returns search options for sifter (the system |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2008 * for scoring and sorting results). |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2009 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2010 * @see https://github.com/brianreavis/sifter.js |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2011 * @return {object} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2012 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2013 getSearchOptions: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2014 var settings = this.settings; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2015 var sort = settings.sortField; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2016 if (typeof sort === 'string') { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2017 sort = [{field: sort}]; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2018 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2019 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2020 return { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2021 fields : settings.searchField, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2022 conjunction : settings.searchConjunction, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2023 sort : sort |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2024 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2025 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2026 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2027 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2028 * Searches through available options and returns |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2029 * a sorted array of matches. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2030 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2031 * Returns an object containing: |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2032 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2033 * - query {string} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2034 * - tokens {array} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2035 * - total {int} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2036 * - items {array} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2037 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2038 * @param {string} query |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2039 * @returns {object} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2040 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2041 search: function(query) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2042 var i, value, score, result, calculateScore; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2043 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2044 var settings = self.settings; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2045 var options = this.getSearchOptions(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2046 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2047 // validate user-provided result scoring function |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2048 if (settings.score) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2049 calculateScore = self.settings.score.apply(this, [query]); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2050 if (typeof calculateScore !== 'function') { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2051 throw new Error('Selectize "score" setting must be a function that returns a function'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2052 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2053 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2054 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2055 // perform search |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2056 if (query !== self.lastQuery) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2057 self.lastQuery = query; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2058 result = self.sifter.search(query, $.extend(options, {score: calculateScore})); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2059 self.currentResults = result; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2060 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2061 result = $.extend(true, {}, self.currentResults); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2062 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2063 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2064 // filter out selected items |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2065 if (settings.hideSelected) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2066 for (i = result.items.length - 1; i >= 0; i--) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2067 if (self.items.indexOf(hash_key(result.items[i].id)) !== -1) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2068 result.items.splice(i, 1); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2069 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2070 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2071 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2072 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2073 return result; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2074 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2075 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2076 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2077 * Refreshes the list of available options shown |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2078 * in the autocomplete dropdown menu. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2079 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2080 * @param {boolean} triggerDropdown |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2081 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2082 refreshOptions: function(triggerDropdown) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2083 var i, j, k, n, groups, groups_order, option, option_html, optgroup, optgroups, html, html_children, has_create_option; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2084 var $active, $active_before, $create; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2085 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2086 if (typeof triggerDropdown === 'undefined') { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2087 triggerDropdown = true; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2088 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2089 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2090 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2091 var query = $.trim(self.$control_input.val()); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2092 var results = self.search(query); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2093 var $dropdown_content = self.$dropdown_content; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2094 var active_before = self.$activeOption && hash_key(self.$activeOption.attr('data-value')); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2095 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2096 // build markup |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2097 n = results.items.length; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2098 if (typeof self.settings.maxOptions === 'number') { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2099 n = Math.min(n, self.settings.maxOptions); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2100 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2101 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2102 // render and group available options individually |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2103 groups = {}; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2104 groups_order = []; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2105 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2106 for (i = 0; i < n; i++) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2107 option = self.options[results.items[i].id]; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2108 option_html = self.render('option', option); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2109 optgroup = option[self.settings.optgroupField] || ''; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2110 optgroups = $.isArray(optgroup) ? optgroup : [optgroup]; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2111 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2112 for (j = 0, k = optgroups && optgroups.length; j < k; j++) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2113 optgroup = optgroups[j]; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2114 if (!self.optgroups.hasOwnProperty(optgroup)) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2115 optgroup = ''; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2116 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2117 if (!groups.hasOwnProperty(optgroup)) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2118 groups[optgroup] = []; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2119 groups_order.push(optgroup); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2120 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2121 groups[optgroup].push(option_html); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2122 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2123 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2124 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2125 // sort optgroups |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2126 if (this.settings.lockOptgroupOrder) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2127 groups_order.sort(function(a, b) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2128 var a_order = self.optgroups[a].$order || 0; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2129 var b_order = self.optgroups[b].$order || 0; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2130 return a_order - b_order; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2131 }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2132 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2133 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2134 // render optgroup headers & join groups |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2135 html = []; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2136 for (i = 0, n = groups_order.length; i < n; i++) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2137 optgroup = groups_order[i]; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2138 if (self.optgroups.hasOwnProperty(optgroup) && groups[optgroup].length) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2139 // render the optgroup header and options within it, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2140 // then pass it to the wrapper template |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2141 html_children = self.render('optgroup_header', self.optgroups[optgroup]) || ''; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2142 html_children += groups[optgroup].join(''); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2143 html.push(self.render('optgroup', $.extend({}, self.optgroups[optgroup], { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2144 html: html_children |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2145 }))); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2146 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2147 html.push(groups[optgroup].join('')); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2148 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2149 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2150 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2151 $dropdown_content.html(html.join('')); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2152 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2153 // highlight matching terms inline |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2154 if (self.settings.highlight && results.query.length && results.tokens.length) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2155 for (i = 0, n = results.tokens.length; i < n; i++) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2156 highlight($dropdown_content, results.tokens[i].regex); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2157 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2158 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2159 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2160 // add "selected" class to selected options |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2161 if (!self.settings.hideSelected) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2162 for (i = 0, n = self.items.length; i < n; i++) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2163 self.getOption(self.items[i]).addClass('selected'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2164 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2165 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2166 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2167 // add create option |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2168 has_create_option = self.canCreate(query); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2169 if (has_create_option) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2170 $dropdown_content.prepend(self.render('option_create', {input: query})); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2171 $create = $($dropdown_content[0].childNodes[0]); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2172 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2173 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2174 // activate |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2175 self.hasOptions = results.items.length > 0 || has_create_option; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2176 if (self.hasOptions) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2177 if (results.items.length > 0) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2178 $active_before = active_before && self.getOption(active_before); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2179 if ($active_before && $active_before.length) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2180 $active = $active_before; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2181 } else if (self.settings.mode === 'single' && self.items.length) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2182 $active = self.getOption(self.items[0]); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2183 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2184 if (!$active || !$active.length) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2185 if ($create && !self.settings.addPrecedence) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2186 $active = self.getAdjacentOption($create, 1); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2187 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2188 $active = $dropdown_content.find('[data-selectable]:first'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2189 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2190 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2191 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2192 $active = $create; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2193 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2194 self.setActiveOption($active); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2195 if (triggerDropdown && !self.isOpen) { self.open(); } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2196 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2197 self.setActiveOption(null); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2198 if (triggerDropdown && self.isOpen) { self.close(); } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2199 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2200 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2201 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2202 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2203 * Adds an available option. If it already exists, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2204 * nothing will happen. Note: this does not refresh |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2205 * the options list dropdown (use `refreshOptions` |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2206 * for that). |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2207 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2208 * Usage: |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2209 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2210 * this.addOption(data) |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2211 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2212 * @param {object|array} data |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2213 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2214 addOption: function(data) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2215 var i, n, value, self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2216 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2217 if ($.isArray(data)) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2218 for (i = 0, n = data.length; i < n; i++) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2219 self.addOption(data[i]); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2220 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2221 return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2222 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2223 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2224 if (value = self.registerOption(data)) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2225 self.userOptions[value] = true; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2226 self.lastQuery = null; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2227 self.trigger('option_add', value, data); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2228 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2229 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2230 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2231 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2232 * Registers an option to the pool of options. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2233 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2234 * @param {object} data |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2235 * @return {boolean|string} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2236 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2237 registerOption: function(data) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2238 var key = hash_key(data[this.settings.valueField]); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2239 if (!key || this.options.hasOwnProperty(key)) return false; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2240 data.$order = data.$order || ++this.order; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2241 this.options[key] = data; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2242 return key; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2243 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2244 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2245 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2246 * Registers an option group to the pool of option groups. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2247 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2248 * @param {object} data |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2249 * @return {boolean|string} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2250 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2251 registerOptionGroup: function(data) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2252 var key = hash_key(data[this.settings.optgroupValueField]); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2253 if (!key) return false; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2254 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2255 data.$order = data.$order || ++this.order; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2256 this.optgroups[key] = data; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2257 return key; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2258 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2259 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2260 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2261 * Registers a new optgroup for options |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2262 * to be bucketed into. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2263 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2264 * @param {string} id |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2265 * @param {object} data |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2266 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2267 addOptionGroup: function(id, data) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2268 data[this.settings.optgroupValueField] = id; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2269 if (id = this.registerOptionGroup(data)) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2270 this.trigger('optgroup_add', id, data); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2271 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2272 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2273 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2274 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2275 * Removes an existing option group. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2276 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2277 * @param {string} id |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2278 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2279 removeOptionGroup: function(id) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2280 if (this.optgroups.hasOwnProperty(id)) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2281 delete this.optgroups[id]; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2282 this.renderCache = {}; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2283 this.trigger('optgroup_remove', id); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2284 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2285 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2286 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2287 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2288 * Clears all existing option groups. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2289 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2290 clearOptionGroups: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2291 this.optgroups = {}; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2292 this.renderCache = {}; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2293 this.trigger('optgroup_clear'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2294 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2295 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2296 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2297 * Updates an option available for selection. If |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2298 * it is visible in the selected items or options |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2299 * dropdown, it will be re-rendered automatically. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2300 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2301 * @param {string} value |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2302 * @param {object} data |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2303 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2304 updateOption: function(value, data) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2305 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2306 var $item, $item_new; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2307 var value_new, index_item, cache_items, cache_options, order_old; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2308 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2309 value = hash_key(value); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2310 value_new = hash_key(data[self.settings.valueField]); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2311 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2312 // sanity checks |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2313 if (value === null) return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2314 if (!self.options.hasOwnProperty(value)) return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2315 if (typeof value_new !== 'string') throw new Error('Value must be set in option data'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2316 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2317 order_old = self.options[value].$order; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2318 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2319 // update references |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2320 if (value_new !== value) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2321 delete self.options[value]; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2322 index_item = self.items.indexOf(value); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2323 if (index_item !== -1) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2324 self.items.splice(index_item, 1, value_new); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2325 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2326 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2327 data.$order = data.$order || order_old; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2328 self.options[value_new] = data; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2329 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2330 // invalidate render cache |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2331 cache_items = self.renderCache['item']; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2332 cache_options = self.renderCache['option']; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2333 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2334 if (cache_items) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2335 delete cache_items[value]; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2336 delete cache_items[value_new]; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2337 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2338 if (cache_options) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2339 delete cache_options[value]; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2340 delete cache_options[value_new]; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2341 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2342 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2343 // update the item if it's selected |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2344 if (self.items.indexOf(value_new) !== -1) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2345 $item = self.getItem(value); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2346 $item_new = $(self.render('item', data)); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2347 if ($item.hasClass('active')) $item_new.addClass('active'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2348 $item.replaceWith($item_new); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2349 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2350 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2351 // invalidate last query because we might have updated the sortField |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2352 self.lastQuery = null; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2353 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2354 // update dropdown contents |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2355 if (self.isOpen) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2356 self.refreshOptions(false); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2357 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2358 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2359 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2360 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2361 * Removes a single option. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2362 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2363 * @param {string} value |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2364 * @param {boolean} silent |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2365 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2366 removeOption: function(value, silent) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2367 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2368 value = hash_key(value); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2369 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2370 var cache_items = self.renderCache['item']; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2371 var cache_options = self.renderCache['option']; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2372 if (cache_items) delete cache_items[value]; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2373 if (cache_options) delete cache_options[value]; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2374 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2375 delete self.userOptions[value]; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2376 delete self.options[value]; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2377 self.lastQuery = null; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2378 self.trigger('option_remove', value); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2379 self.removeItem(value, silent); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2380 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2381 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2382 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2383 * Clears all options. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2384 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2385 clearOptions: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2386 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2387 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2388 self.loadedSearches = {}; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2389 self.userOptions = {}; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2390 self.renderCache = {}; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2391 self.options = self.sifter.items = {}; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2392 self.lastQuery = null; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2393 self.trigger('option_clear'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2394 self.clear(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2395 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2396 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2397 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2398 * Returns the jQuery element of the option |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2399 * matching the given value. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2400 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2401 * @param {string} value |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2402 * @returns {object} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2403 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2404 getOption: function(value) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2405 return this.getElementWithValue(value, this.$dropdown_content.find('[data-selectable]')); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2406 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2407 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2408 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2409 * Returns the jQuery element of the next or |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2410 * previous selectable option. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2411 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2412 * @param {object} $option |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2413 * @param {int} direction can be 1 for next or -1 for previous |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2414 * @return {object} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2415 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2416 getAdjacentOption: function($option, direction) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2417 var $options = this.$dropdown.find('[data-selectable]'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2418 var index = $options.index($option) + direction; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2419 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2420 return index >= 0 && index < $options.length ? $options.eq(index) : $(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2421 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2422 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2423 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2424 * Finds the first element with a "data-value" attribute |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2425 * that matches the given value. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2426 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2427 * @param {mixed} value |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2428 * @param {object} $els |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2429 * @return {object} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2430 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2431 getElementWithValue: function(value, $els) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2432 value = hash_key(value); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2433 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2434 if (typeof value !== 'undefined' && value !== null) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2435 for (var i = 0, n = $els.length; i < n; i++) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2436 if ($els[i].getAttribute('data-value') === value) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2437 return $($els[i]); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2438 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2439 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2440 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2441 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2442 return $(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2443 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2444 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2445 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2446 * Returns the jQuery element of the item |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2447 * matching the given value. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2448 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2449 * @param {string} value |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2450 * @returns {object} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2451 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2452 getItem: function(value) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2453 return this.getElementWithValue(value, this.$control.children()); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2454 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2455 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2456 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2457 * "Selects" multiple items at once. Adds them to the list |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2458 * at the current caret position. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2459 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2460 * @param {string} value |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2461 * @param {boolean} silent |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2462 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2463 addItems: function(values, silent) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2464 var items = $.isArray(values) ? values : [values]; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2465 for (var i = 0, n = items.length; i < n; i++) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2466 this.isPending = (i < n - 1); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2467 this.addItem(items[i], silent); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2468 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2469 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2470 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2471 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2472 * "Selects" an item. Adds it to the list |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2473 * at the current caret position. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2474 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2475 * @param {string} value |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2476 * @param {boolean} silent |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2477 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2478 addItem: function(value, silent) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2479 var events = silent ? [] : ['change']; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2480 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2481 debounce_events(this, events, function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2482 var $item, $option, $options; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2483 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2484 var inputMode = self.settings.mode; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2485 var i, active, value_next, wasFull; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2486 value = hash_key(value); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2487 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2488 if (self.items.indexOf(value) !== -1) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2489 if (inputMode === 'single') self.close(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2490 return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2491 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2492 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2493 if (!self.options.hasOwnProperty(value)) return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2494 if (inputMode === 'single') self.clear(silent); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2495 if (inputMode === 'multi' && self.isFull()) return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2496 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2497 $item = $(self.render('item', self.options[value])); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2498 wasFull = self.isFull(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2499 self.items.splice(self.caretPos, 0, value); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2500 self.insertAtCaret($item); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2501 if (!self.isPending || (!wasFull && self.isFull())) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2502 self.refreshState(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2503 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2504 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2505 if (self.isSetup) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2506 $options = self.$dropdown_content.find('[data-selectable]'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2507 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2508 // update menu / remove the option (if this is not one item being added as part of series) |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2509 if (!self.isPending) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2510 $option = self.getOption(value); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2511 value_next = self.getAdjacentOption($option, 1).attr('data-value'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2512 self.refreshOptions(self.isFocused && inputMode !== 'single'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2513 if (value_next) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2514 self.setActiveOption(self.getOption(value_next)); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2515 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2516 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2517 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2518 // hide the menu if the maximum number of items have been selected or no options are left |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2519 if (!$options.length || self.isFull()) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2520 self.close(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2521 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2522 self.positionDropdown(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2523 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2524 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2525 self.updatePlaceholder(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2526 self.trigger('item_add', value, $item); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2527 self.updateOriginalInput({silent: silent}); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2528 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2529 }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2530 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2531 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2532 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2533 * Removes the selected item matching |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2534 * the provided value. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2535 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2536 * @param {string} value |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2537 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2538 removeItem: function(value, silent) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2539 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2540 var $item, i, idx; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2541 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2542 $item = (typeof value === 'object') ? value : self.getItem(value); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2543 value = hash_key($item.attr('data-value')); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2544 i = self.items.indexOf(value); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2545 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2546 if (i !== -1) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2547 $item.remove(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2548 if ($item.hasClass('active')) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2549 idx = self.$activeItems.indexOf($item[0]); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2550 self.$activeItems.splice(idx, 1); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2551 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2552 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2553 self.items.splice(i, 1); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2554 self.lastQuery = null; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2555 if (!self.settings.persist && self.userOptions.hasOwnProperty(value)) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2556 self.removeOption(value, silent); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2557 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2558 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2559 if (i < self.caretPos) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2560 self.setCaret(self.caretPos - 1); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2561 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2562 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2563 self.refreshState(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2564 self.updatePlaceholder(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2565 self.updateOriginalInput({silent: silent}); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2566 self.positionDropdown(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2567 self.trigger('item_remove', value, $item); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2568 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2569 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2570 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2571 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2572 * Invokes the `create` method provided in the |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2573 * selectize options that should provide the data |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2574 * for the new item, given the user input. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2575 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2576 * Once this completes, it will be added |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2577 * to the item list. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2578 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2579 * @param {string} value |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2580 * @param {boolean} [triggerDropdown] |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2581 * @param {function} [callback] |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2582 * @return {boolean} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2583 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2584 createItem: function(input, triggerDropdown) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2585 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2586 var caret = self.caretPos; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2587 input = input || $.trim(self.$control_input.val() || ''); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2588 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2589 var callback = arguments[arguments.length - 1]; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2590 if (typeof callback !== 'function') callback = function() {}; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2591 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2592 if (typeof triggerDropdown !== 'boolean') { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2593 triggerDropdown = true; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2594 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2595 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2596 if (!self.canCreate(input)) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2597 callback(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2598 return false; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2599 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2600 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2601 self.lock(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2602 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2603 var setup = (typeof self.settings.create === 'function') ? this.settings.create : function(input) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2604 var data = {}; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2605 data[self.settings.labelField] = input; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2606 data[self.settings.valueField] = input; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2607 return data; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2608 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2609 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2610 var create = once(function(data) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2611 self.unlock(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2612 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2613 if (!data || typeof data !== 'object') return callback(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2614 var value = hash_key(data[self.settings.valueField]); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2615 if (typeof value !== 'string') return callback(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2616 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2617 self.setTextboxValue(''); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2618 self.addOption(data); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2619 self.setCaret(caret); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2620 self.addItem(value); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2621 self.refreshOptions(triggerDropdown && self.settings.mode !== 'single'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2622 callback(data); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2623 }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2624 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2625 var output = setup.apply(this, [input, create]); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2626 if (typeof output !== 'undefined') { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2627 create(output); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2628 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2629 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2630 return true; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2631 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2632 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2633 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2634 * Re-renders the selected item lists. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2635 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2636 refreshItems: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2637 this.lastQuery = null; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2638 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2639 if (this.isSetup) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2640 this.addItem(this.items); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2641 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2642 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2643 this.refreshState(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2644 this.updateOriginalInput(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2645 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2646 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2647 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2648 * Updates all state-dependent attributes |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2649 * and CSS classes. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2650 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2651 refreshState: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2652 var invalid, self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2653 if (self.isRequired) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2654 if (self.items.length) self.isInvalid = false; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2655 self.$control_input.prop('required', invalid); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2656 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2657 self.refreshClasses(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2658 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2659 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2660 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2661 * Updates all state-dependent CSS classes. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2662 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2663 refreshClasses: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2664 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2665 var isFull = self.isFull(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2666 var isLocked = self.isLocked; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2667 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2668 self.$wrapper |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2669 .toggleClass('rtl', self.rtl); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2670 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2671 self.$control |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2672 .toggleClass('focus', self.isFocused) |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2673 .toggleClass('disabled', self.isDisabled) |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2674 .toggleClass('required', self.isRequired) |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2675 .toggleClass('invalid', self.isInvalid) |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2676 .toggleClass('locked', isLocked) |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2677 .toggleClass('full', isFull).toggleClass('not-full', !isFull) |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2678 .toggleClass('input-active', self.isFocused && !self.isInputHidden) |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2679 .toggleClass('dropdown-active', self.isOpen) |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2680 .toggleClass('has-options', !$.isEmptyObject(self.options)) |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2681 .toggleClass('has-items', self.items.length > 0); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2682 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2683 self.$control_input.data('grow', !isFull && !isLocked); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2684 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2685 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2686 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2687 * Determines whether or not more items can be added |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2688 * to the control without exceeding the user-defined maximum. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2689 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2690 * @returns {boolean} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2691 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2692 isFull: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2693 return this.settings.maxItems !== null && this.items.length >= this.settings.maxItems; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2694 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2695 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2696 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2697 * Refreshes the original <select> or <input> |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2698 * element to reflect the current state. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2699 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2700 updateOriginalInput: function(opts) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2701 var i, n, options, label, self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2702 opts = opts || {}; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2703 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2704 if (self.tagType === TAG_SELECT) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2705 options = []; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2706 for (i = 0, n = self.items.length; i < n; i++) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2707 label = self.options[self.items[i]][self.settings.labelField] || ''; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2708 options.push('<option value="' + escape_html(self.items[i]) + '" selected="selected">' + escape_html(label) + '</option>'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2709 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2710 if (!options.length && !this.$input.attr('multiple')) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2711 options.push('<option value="" selected="selected"></option>'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2712 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2713 self.$input.html(options.join('')); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2714 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2715 self.$input.val(self.getValue()); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2716 self.$input.attr('value',self.$input.val()); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2717 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2718 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2719 if (self.isSetup) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2720 if (!opts.silent) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2721 self.trigger('change', self.$input.val()); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2722 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2723 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2724 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2725 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2726 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2727 * Shows/hide the input placeholder depending |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2728 * on if there items in the list already. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2729 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2730 updatePlaceholder: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2731 if (!this.settings.placeholder) return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2732 var $input = this.$control_input; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2733 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2734 if (this.items.length) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2735 $input.removeAttr('placeholder'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2736 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2737 $input.attr('placeholder', this.settings.placeholder); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2738 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2739 $input.triggerHandler('update', {force: true}); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2740 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2741 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2742 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2743 * Shows the autocomplete dropdown containing |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2744 * the available options. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2745 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2746 open: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2747 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2748 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2749 if (self.isLocked || self.isOpen || (self.settings.mode === 'multi' && self.isFull())) return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2750 self.focus(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2751 self.isOpen = true; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2752 self.refreshState(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2753 self.$dropdown.css({visibility: 'hidden', display: 'block'}); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2754 self.positionDropdown(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2755 self.$dropdown.css({visibility: 'visible'}); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2756 self.trigger('dropdown_open', self.$dropdown); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2757 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2758 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2759 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2760 * Closes the autocomplete dropdown menu. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2761 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2762 close: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2763 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2764 var trigger = self.isOpen; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2765 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2766 if (self.settings.mode === 'single' && self.items.length) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2767 self.hideInput(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2768 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2769 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2770 self.isOpen = false; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2771 self.$dropdown.hide(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2772 self.setActiveOption(null); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2773 self.refreshState(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2774 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2775 if (trigger) self.trigger('dropdown_close', self.$dropdown); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2776 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2777 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2778 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2779 * Calculates and applies the appropriate |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2780 * position of the dropdown. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2781 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2782 positionDropdown: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2783 var $control = this.$control; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2784 var offset = this.settings.dropdownParent === 'body' ? $control.offset() : $control.position(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2785 offset.top += $control.outerHeight(true); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2786 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2787 this.$dropdown.css({ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2788 width : $control.outerWidth(), |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2789 top : offset.top, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2790 left : offset.left |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2791 }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2792 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2793 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2794 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2795 * Resets / clears all selected items |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2796 * from the control. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2797 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2798 * @param {boolean} silent |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2799 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2800 clear: function(silent) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2801 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2802 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2803 if (!self.items.length) return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2804 self.$control.children(':not(input)').remove(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2805 self.items = []; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2806 self.lastQuery = null; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2807 self.setCaret(0); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2808 self.setActiveItem(null); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2809 self.updatePlaceholder(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2810 self.updateOriginalInput({silent: silent}); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2811 self.refreshState(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2812 self.showInput(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2813 self.trigger('clear'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2814 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2815 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2816 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2817 * A helper method for inserting an element |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2818 * at the current caret position. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2819 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2820 * @param {object} $el |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2821 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2822 insertAtCaret: function($el) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2823 var caret = Math.min(this.caretPos, this.items.length); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2824 if (caret === 0) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2825 this.$control.prepend($el); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2826 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2827 $(this.$control[0].childNodes[caret]).before($el); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2828 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2829 this.setCaret(caret + 1); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2830 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2831 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2832 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2833 * Removes the current selected item(s). |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2834 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2835 * @param {object} e (optional) |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2836 * @returns {boolean} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2837 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2838 deleteSelection: function(e) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2839 var i, n, direction, selection, values, caret, option_select, $option_select, $tail; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2840 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2841 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2842 direction = (e && e.keyCode === KEY_BACKSPACE) ? -1 : 1; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2843 selection = getSelection(self.$control_input[0]); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2844 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2845 if (self.$activeOption && !self.settings.hideSelected) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2846 option_select = self.getAdjacentOption(self.$activeOption, -1).attr('data-value'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2847 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2848 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2849 // determine items that will be removed |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2850 values = []; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2851 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2852 if (self.$activeItems.length) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2853 $tail = self.$control.children('.active:' + (direction > 0 ? 'last' : 'first')); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2854 caret = self.$control.children(':not(input)').index($tail); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2855 if (direction > 0) { caret++; } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2856 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2857 for (i = 0, n = self.$activeItems.length; i < n; i++) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2858 values.push($(self.$activeItems[i]).attr('data-value')); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2859 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2860 if (e) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2861 e.preventDefault(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2862 e.stopPropagation(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2863 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2864 } else if ((self.isFocused || self.settings.mode === 'single') && self.items.length) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2865 if (direction < 0 && selection.start === 0 && selection.length === 0) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2866 values.push(self.items[self.caretPos - 1]); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2867 } else if (direction > 0 && selection.start === self.$control_input.val().length) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2868 values.push(self.items[self.caretPos]); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2869 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2870 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2871 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2872 // allow the callback to abort |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2873 if (!values.length || (typeof self.settings.onDelete === 'function' && self.settings.onDelete.apply(self, [values]) === false)) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2874 return false; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2875 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2876 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2877 // perform removal |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2878 if (typeof caret !== 'undefined') { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2879 self.setCaret(caret); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2880 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2881 while (values.length) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2882 self.removeItem(values.pop()); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2883 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2884 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2885 self.showInput(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2886 self.positionDropdown(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2887 self.refreshOptions(true); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2888 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2889 // select previous option |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2890 if (option_select) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2891 $option_select = self.getOption(option_select); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2892 if ($option_select.length) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2893 self.setActiveOption($option_select); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2894 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2895 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2896 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2897 return true; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2898 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2899 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2900 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2901 * Selects the previous / next item (depending |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2902 * on the `direction` argument). |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2903 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2904 * > 0 - right |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2905 * < 0 - left |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2906 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2907 * @param {int} direction |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2908 * @param {object} e (optional) |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2909 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2910 advanceSelection: function(direction, e) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2911 var tail, selection, idx, valueLength, cursorAtEdge, $tail; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2912 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2913 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2914 if (direction === 0) return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2915 if (self.rtl) direction *= -1; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2916 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2917 tail = direction > 0 ? 'last' : 'first'; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2918 selection = getSelection(self.$control_input[0]); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2919 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2920 if (self.isFocused && !self.isInputHidden) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2921 valueLength = self.$control_input.val().length; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2922 cursorAtEdge = direction < 0 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2923 ? selection.start === 0 && selection.length === 0 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2924 : selection.start === valueLength; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2925 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2926 if (cursorAtEdge && !valueLength) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2927 self.advanceCaret(direction, e); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2928 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2929 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2930 $tail = self.$control.children('.active:' + tail); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2931 if ($tail.length) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2932 idx = self.$control.children(':not(input)').index($tail); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2933 self.setActiveItem(null); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2934 self.setCaret(direction > 0 ? idx + 1 : idx); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2935 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2936 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2937 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2938 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2939 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2940 * Moves the caret left / right. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2941 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2942 * @param {int} direction |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2943 * @param {object} e (optional) |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2944 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2945 advanceCaret: function(direction, e) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2946 var self = this, fn, $adj; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2947 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2948 if (direction === 0) return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2949 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2950 fn = direction > 0 ? 'next' : 'prev'; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2951 if (self.isShiftDown) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2952 $adj = self.$control_input[fn](); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2953 if ($adj.length) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2954 self.hideInput(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2955 self.setActiveItem($adj); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2956 e && e.preventDefault(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2957 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2958 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2959 self.setCaret(self.caretPos + direction); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2960 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2961 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2962 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2963 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2964 * Moves the caret to the specified index. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2965 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2966 * @param {int} i |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2967 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2968 setCaret: function(i) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2969 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2970 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2971 if (self.settings.mode === 'single') { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2972 i = self.items.length; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2973 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2974 i = Math.max(0, Math.min(self.items.length, i)); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2975 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2976 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2977 if(!self.isPending) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2978 // the input must be moved by leaving it in place and moving the |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2979 // siblings, due to the fact that focus cannot be restored once lost |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2980 // on mobile webkit devices |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2981 var j, n, fn, $children, $child; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2982 $children = self.$control.children(':not(input)'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2983 for (j = 0, n = $children.length; j < n; j++) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2984 $child = $($children[j]).detach(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2985 if (j < i) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2986 self.$control_input.before($child); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2987 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2988 self.$control.append($child); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2989 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2990 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2991 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2992 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2993 self.caretPos = i; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2994 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2995 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2996 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2997 * Disables user input on the control. Used while |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2998 * items are being asynchronously created. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2999 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3000 lock: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3001 this.close(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3002 this.isLocked = true; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3003 this.refreshState(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3004 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3005 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3006 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3007 * Re-enables user input on the control. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3008 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3009 unlock: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3010 this.isLocked = false; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3011 this.refreshState(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3012 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3013 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3014 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3015 * Disables user input on the control completely. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3016 * While disabled, it cannot receive focus. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3017 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3018 disable: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3019 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3020 self.$input.prop('disabled', true); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3021 self.$control_input.prop('disabled', true).prop('tabindex', -1); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3022 self.isDisabled = true; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3023 self.lock(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3024 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3025 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3026 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3027 * Enables the control so that it can respond |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3028 * to focus and user input. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3029 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3030 enable: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3031 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3032 self.$input.prop('disabled', false); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3033 self.$control_input.prop('disabled', false).prop('tabindex', self.tabIndex); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3034 self.isDisabled = false; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3035 self.unlock(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3036 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3037 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3038 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3039 * Completely destroys the control and |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3040 * unbinds all event listeners so that it can |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3041 * be garbage collected. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3042 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3043 destroy: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3044 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3045 var eventNS = self.eventNS; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3046 var revertSettings = self.revertSettings; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3047 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3048 self.trigger('destroy'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3049 self.off(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3050 self.$wrapper.remove(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3051 self.$dropdown.remove(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3052 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3053 self.$input |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3054 .html('') |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3055 .append(revertSettings.$children) |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3056 .removeAttr('tabindex') |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3057 .removeClass('selectized') |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3058 .attr({tabindex: revertSettings.tabindex}) |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3059 .show(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3060 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3061 self.$control_input.removeData('grow'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3062 self.$input.removeData('selectize'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3063 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3064 $(window).off(eventNS); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3065 $(document).off(eventNS); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3066 $(document.body).off(eventNS); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3067 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3068 delete self.$input[0].selectize; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3069 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3070 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3071 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3072 * A helper method for rendering "item" and |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3073 * "option" templates, given the data. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3074 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3075 * @param {string} templateName |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3076 * @param {object} data |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3077 * @returns {string} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3078 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3079 render: function(templateName, data) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3080 var value, id, label; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3081 var html = ''; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3082 var cache = false; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3083 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3084 var regex_tag = /^[\t \r\n]*<([a-z][a-z0-9\-_]*(?:\:[a-z][a-z0-9\-_]*)?)/i; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3085 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3086 if (templateName === 'option' || templateName === 'item') { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3087 value = hash_key(data[self.settings.valueField]); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3088 cache = !!value; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3089 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3090 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3091 // pull markup from cache if it exists |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3092 if (cache) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3093 if (!isset(self.renderCache[templateName])) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3094 self.renderCache[templateName] = {}; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3095 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3096 if (self.renderCache[templateName].hasOwnProperty(value)) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3097 return self.renderCache[templateName][value]; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3098 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3099 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3100 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3101 // render markup |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3102 html = self.settings.render[templateName].apply(this, [data, escape_html]); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3103 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3104 // add mandatory attributes |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3105 if (templateName === 'option' || templateName === 'option_create') { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3106 html = html.replace(regex_tag, '<$1 data-selectable'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3107 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3108 if (templateName === 'optgroup') { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3109 id = data[self.settings.optgroupValueField] || ''; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3110 html = html.replace(regex_tag, '<$1 data-group="' + escape_replace(escape_html(id)) + '"'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3111 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3112 if (templateName === 'option' || templateName === 'item') { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3113 html = html.replace(regex_tag, '<$1 data-value="' + escape_replace(escape_html(value || '')) + '"'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3114 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3115 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3116 // update cache |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3117 if (cache) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3118 self.renderCache[templateName][value] = html; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3119 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3120 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3121 return html; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3122 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3123 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3124 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3125 * Clears the render cache for a template. If |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3126 * no template is given, clears all render |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3127 * caches. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3128 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3129 * @param {string} templateName |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3130 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3131 clearCache: function(templateName) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3132 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3133 if (typeof templateName === 'undefined') { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3134 self.renderCache = {}; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3135 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3136 delete self.renderCache[templateName]; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3137 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3138 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3139 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3140 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3141 * Determines whether or not to display the |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3142 * create item prompt, given a user input. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3143 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3144 * @param {string} input |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3145 * @return {boolean} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3146 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3147 canCreate: function(input) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3148 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3149 if (!self.settings.create) return false; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3150 var filter = self.settings.createFilter; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3151 return input.length |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3152 && (typeof filter !== 'function' || filter.apply(self, [input])) |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3153 && (typeof filter !== 'string' || new RegExp(filter).test(input)) |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3154 && (!(filter instanceof RegExp) || filter.test(input)); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3155 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3156 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3157 }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3158 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3159 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3160 Selectize.count = 0; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3161 Selectize.defaults = { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3162 options: [], |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3163 optgroups: [], |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3164 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3165 plugins: [], |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3166 delimiter: ',', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3167 splitOn: null, // regexp or string for splitting up values from a paste command |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3168 persist: true, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3169 diacritics: true, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3170 create: false, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3171 createOnBlur: false, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3172 createFilter: null, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3173 highlight: true, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3174 openOnFocus: true, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3175 maxOptions: 1000, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3176 maxItems: null, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3177 hideSelected: null, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3178 addPrecedence: false, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3179 selectOnTab: false, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3180 preload: false, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3181 allowEmptyOption: false, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3182 closeAfterSelect: false, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3183 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3184 scrollDuration: 60, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3185 loadThrottle: 300, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3186 loadingClass: 'loading', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3187 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3188 dataAttr: 'data-data', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3189 optgroupField: 'optgroup', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3190 valueField: 'value', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3191 labelField: 'text', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3192 optgroupLabelField: 'label', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3193 optgroupValueField: 'value', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3194 lockOptgroupOrder: false, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3195 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3196 sortField: '$order', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3197 searchField: ['text'], |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3198 searchConjunction: 'and', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3199 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3200 mode: null, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3201 wrapperClass: 'selectize-control', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3202 inputClass: 'selectize-input', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3203 dropdownClass: 'selectize-dropdown', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3204 dropdownContentClass: 'selectize-dropdown-content', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3205 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3206 dropdownParent: null, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3207 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3208 copyClassesToDropdown: true, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3209 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3210 /* |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3211 load : null, // function(query, callback) { ... } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3212 score : null, // function(search) { ... } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3213 onInitialize : null, // function() { ... } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3214 onChange : null, // function(value) { ... } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3215 onItemAdd : null, // function(value, $item) { ... } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3216 onItemRemove : null, // function(value) { ... } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3217 onClear : null, // function() { ... } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3218 onOptionAdd : null, // function(value, data) { ... } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3219 onOptionRemove : null, // function(value) { ... } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3220 onOptionClear : null, // function() { ... } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3221 onOptionGroupAdd : null, // function(id, data) { ... } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3222 onOptionGroupRemove : null, // function(id) { ... } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3223 onOptionGroupClear : null, // function() { ... } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3224 onDropdownOpen : null, // function($dropdown) { ... } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3225 onDropdownClose : null, // function($dropdown) { ... } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3226 onType : null, // function(str) { ... } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3227 onDelete : null, // function(values) { ... } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3228 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3229 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3230 render: { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3231 /* |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3232 item: null, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3233 optgroup: null, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3234 optgroup_header: null, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3235 option: null, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3236 option_create: null |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3237 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3238 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3239 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3240 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3241 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3242 $.fn.selectize = function(settings_user) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3243 var defaults = $.fn.selectize.defaults; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3244 var settings = $.extend({}, defaults, settings_user); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3245 var attr_data = settings.dataAttr; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3246 var field_label = settings.labelField; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3247 var field_value = settings.valueField; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3248 var field_optgroup = settings.optgroupField; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3249 var field_optgroup_label = settings.optgroupLabelField; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3250 var field_optgroup_value = settings.optgroupValueField; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3251 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3252 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3253 * Initializes selectize from a <input type="text"> element. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3254 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3255 * @param {object} $input |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3256 * @param {object} settings_element |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3257 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3258 var init_textbox = function($input, settings_element) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3259 var i, n, values, option; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3260 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3261 var data_raw = $input.attr(attr_data); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3262 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3263 if (!data_raw) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3264 var value = $.trim($input.val() || ''); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3265 if (!settings.allowEmptyOption && !value.length) return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3266 values = value.split(settings.delimiter); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3267 for (i = 0, n = values.length; i < n; i++) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3268 option = {}; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3269 option[field_label] = values[i]; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3270 option[field_value] = values[i]; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3271 settings_element.options.push(option); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3272 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3273 settings_element.items = values; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3274 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3275 settings_element.options = JSON.parse(data_raw); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3276 for (i = 0, n = settings_element.options.length; i < n; i++) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3277 settings_element.items.push(settings_element.options[i][field_value]); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3278 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3279 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3280 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3281 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3282 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3283 * Initializes selectize from a <select> element. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3284 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3285 * @param {object} $input |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3286 * @param {object} settings_element |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3287 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3288 var init_select = function($input, settings_element) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3289 var i, n, tagName, $children, order = 0; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3290 var options = settings_element.options; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3291 var optionsMap = {}; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3292 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3293 var readData = function($el) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3294 var data = attr_data && $el.attr(attr_data); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3295 if (typeof data === 'string' && data.length) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3296 return JSON.parse(data); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3297 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3298 return null; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3299 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3300 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3301 var addOption = function($option, group) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3302 $option = $($option); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3303 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3304 var value = hash_key($option.attr('value')); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3305 if (!value && !settings.allowEmptyOption) return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3306 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3307 // if the option already exists, it's probably been |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3308 // duplicated in another optgroup. in this case, push |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3309 // the current group to the "optgroup" property on the |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3310 // existing option so that it's rendered in both places. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3311 if (optionsMap.hasOwnProperty(value)) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3312 if (group) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3313 var arr = optionsMap[value][field_optgroup]; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3314 if (!arr) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3315 optionsMap[value][field_optgroup] = group; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3316 } else if (!$.isArray(arr)) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3317 optionsMap[value][field_optgroup] = [arr, group]; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3318 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3319 arr.push(group); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3320 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3321 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3322 return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3323 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3324 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3325 var option = readData($option) || {}; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3326 option[field_label] = option[field_label] || $option.text(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3327 option[field_value] = option[field_value] || value; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3328 option[field_optgroup] = option[field_optgroup] || group; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3329 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3330 optionsMap[value] = option; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3331 options.push(option); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3332 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3333 if ($option.is(':selected')) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3334 settings_element.items.push(value); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3335 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3336 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3337 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3338 var addGroup = function($optgroup) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3339 var i, n, id, optgroup, $options; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3340 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3341 $optgroup = $($optgroup); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3342 id = $optgroup.attr('label'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3343 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3344 if (id) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3345 optgroup = readData($optgroup) || {}; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3346 optgroup[field_optgroup_label] = id; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3347 optgroup[field_optgroup_value] = id; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3348 settings_element.optgroups.push(optgroup); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3349 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3350 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3351 $options = $('option', $optgroup); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3352 for (i = 0, n = $options.length; i < n; i++) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3353 addOption($options[i], id); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3354 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3355 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3356 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3357 settings_element.maxItems = $input.attr('multiple') ? null : 1; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3358 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3359 $children = $input.children(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3360 for (i = 0, n = $children.length; i < n; i++) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3361 tagName = $children[i].tagName.toLowerCase(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3362 if (tagName === 'optgroup') { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3363 addGroup($children[i]); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3364 } else if (tagName === 'option') { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3365 addOption($children[i]); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3366 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3367 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3368 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3369 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3370 return this.each(function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3371 if (this.selectize) return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3372 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3373 var instance; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3374 var $input = $(this); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3375 var tag_name = this.tagName.toLowerCase(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3376 var placeholder = $input.attr('placeholder') || $input.attr('data-placeholder'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3377 if (!placeholder && !settings.allowEmptyOption) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3378 placeholder = $input.children('option[value=""]').text(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3379 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3380 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3381 var settings_element = { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3382 'placeholder' : placeholder, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3383 'options' : [], |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3384 'optgroups' : [], |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3385 'items' : [] |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3386 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3387 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3388 if (tag_name === 'select') { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3389 init_select($input, settings_element); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3390 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3391 init_textbox($input, settings_element); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3392 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3393 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3394 instance = new Selectize($input, $.extend(true, {}, defaults, settings_element, settings_user)); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3395 }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3396 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3397 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3398 $.fn.selectize.defaults = Selectize.defaults; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3399 $.fn.selectize.support = { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3400 validity: SUPPORTS_VALIDITY_API |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3401 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3402 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3403 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3404 Selectize.define('drag_drop', function(options) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3405 if (!$.fn.sortable) throw new Error('The "drag_drop" plugin requires jQuery UI "sortable".'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3406 if (this.settings.mode !== 'multi') return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3407 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3408 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3409 self.lock = (function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3410 var original = self.lock; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3411 return function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3412 var sortable = self.$control.data('sortable'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3413 if (sortable) sortable.disable(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3414 return original.apply(self, arguments); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3415 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3416 })(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3417 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3418 self.unlock = (function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3419 var original = self.unlock; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3420 return function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3421 var sortable = self.$control.data('sortable'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3422 if (sortable) sortable.enable(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3423 return original.apply(self, arguments); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3424 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3425 })(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3426 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3427 self.setup = (function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3428 var original = self.setup; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3429 return function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3430 original.apply(this, arguments); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3431 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3432 var $control = self.$control.sortable({ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3433 items: '[data-value]', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3434 forcePlaceholderSize: true, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3435 disabled: self.isLocked, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3436 start: function(e, ui) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3437 ui.placeholder.css('width', ui.helper.css('width')); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3438 $control.css({overflow: 'visible'}); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3439 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3440 stop: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3441 $control.css({overflow: 'hidden'}); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3442 var active = self.$activeItems ? self.$activeItems.slice() : null; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3443 var values = []; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3444 $control.children('[data-value]').each(function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3445 values.push($(this).attr('data-value')); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3446 }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3447 self.setValue(values); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3448 self.setActiveItem(active); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3449 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3450 }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3451 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3452 })(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3453 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3454 }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3455 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3456 Selectize.define('dropdown_header', function(options) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3457 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3458 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3459 options = $.extend({ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3460 title : 'Untitled', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3461 headerClass : 'selectize-dropdown-header', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3462 titleRowClass : 'selectize-dropdown-header-title', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3463 labelClass : 'selectize-dropdown-header-label', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3464 closeClass : 'selectize-dropdown-header-close', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3465 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3466 html: function(data) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3467 return ( |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3468 '<div class="' + data.headerClass + '">' + |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3469 '<div class="' + data.titleRowClass + '">' + |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3470 '<span class="' + data.labelClass + '">' + data.title + '</span>' + |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3471 '<a href="javascript:void(0)" class="' + data.closeClass + '">×</a>' + |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3472 '</div>' + |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3473 '</div>' |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3474 ); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3475 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3476 }, options); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3477 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3478 self.setup = (function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3479 var original = self.setup; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3480 return function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3481 original.apply(self, arguments); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3482 self.$dropdown_header = $(options.html(options)); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3483 self.$dropdown.prepend(self.$dropdown_header); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3484 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3485 })(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3486 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3487 }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3488 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3489 Selectize.define('optgroup_columns', function(options) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3490 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3491 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3492 options = $.extend({ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3493 equalizeWidth : true, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3494 equalizeHeight : true |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3495 }, options); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3496 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3497 this.getAdjacentOption = function($option, direction) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3498 var $options = $option.closest('[data-group]').find('[data-selectable]'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3499 var index = $options.index($option) + direction; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3500 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3501 return index >= 0 && index < $options.length ? $options.eq(index) : $(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3502 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3503 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3504 this.onKeyDown = (function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3505 var original = self.onKeyDown; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3506 return function(e) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3507 var index, $option, $options, $optgroup; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3508 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3509 if (this.isOpen && (e.keyCode === KEY_LEFT || e.keyCode === KEY_RIGHT)) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3510 self.ignoreHover = true; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3511 $optgroup = this.$activeOption.closest('[data-group]'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3512 index = $optgroup.find('[data-selectable]').index(this.$activeOption); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3513 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3514 if(e.keyCode === KEY_LEFT) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3515 $optgroup = $optgroup.prev('[data-group]'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3516 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3517 $optgroup = $optgroup.next('[data-group]'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3518 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3519 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3520 $options = $optgroup.find('[data-selectable]'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3521 $option = $options.eq(Math.min($options.length - 1, index)); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3522 if ($option.length) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3523 this.setActiveOption($option); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3524 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3525 return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3526 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3527 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3528 return original.apply(this, arguments); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3529 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3530 })(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3531 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3532 var getScrollbarWidth = function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3533 var div; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3534 var width = getScrollbarWidth.width; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3535 var doc = document; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3536 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3537 if (typeof width === 'undefined') { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3538 div = doc.createElement('div'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3539 div.innerHTML = '<div style="width:50px;height:50px;position:absolute;left:-50px;top:-50px;overflow:auto;"><div style="width:1px;height:100px;"></div></div>'; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3540 div = div.firstChild; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3541 doc.body.appendChild(div); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3542 width = getScrollbarWidth.width = div.offsetWidth - div.clientWidth; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3543 doc.body.removeChild(div); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3544 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3545 return width; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3546 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3547 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3548 var equalizeSizes = function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3549 var i, n, height_max, width, width_last, width_parent, $optgroups; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3550 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3551 $optgroups = $('[data-group]', self.$dropdown_content); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3552 n = $optgroups.length; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3553 if (!n || !self.$dropdown_content.width()) return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3554 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3555 if (options.equalizeHeight) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3556 height_max = 0; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3557 for (i = 0; i < n; i++) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3558 height_max = Math.max(height_max, $optgroups.eq(i).height()); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3559 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3560 $optgroups.css({height: height_max}); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3561 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3562 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3563 if (options.equalizeWidth) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3564 width_parent = self.$dropdown_content.innerWidth() - getScrollbarWidth(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3565 width = Math.round(width_parent / n); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3566 $optgroups.css({width: width}); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3567 if (n > 1) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3568 width_last = width_parent - width * (n - 1); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3569 $optgroups.eq(n - 1).css({width: width_last}); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3570 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3571 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3572 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3573 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3574 if (options.equalizeHeight || options.equalizeWidth) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3575 hook.after(this, 'positionDropdown', equalizeSizes); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3576 hook.after(this, 'refreshOptions', equalizeSizes); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3577 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3578 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3579 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3580 }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3581 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3582 Selectize.define('remove_button', function(options) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3583 if (this.settings.mode === 'single') return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3584 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3585 options = $.extend({ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3586 label : '×', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3587 title : 'Remove', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3588 className : 'remove', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3589 append : true |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3590 }, options); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3591 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3592 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3593 var html = '<a href="javascript:void(0)" class="' + options.className + '" tabindex="-1" title="' + escape_html(options.title) + '">' + options.label + '</a>'; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3594 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3595 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3596 * Appends an element as a child (with raw HTML). |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3597 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3598 * @param {string} html_container |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3599 * @param {string} html_element |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3600 * @return {string} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3601 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3602 var append = function(html_container, html_element) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3603 var pos = html_container.search(/(<\/[^>]+>\s*)$/); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3604 return html_container.substring(0, pos) + html_element + html_container.substring(pos); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3605 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3606 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3607 this.setup = (function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3608 var original = self.setup; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3609 return function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3610 // override the item rendering method to add the button to each |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3611 if (options.append) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3612 var render_item = self.settings.render.item; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3613 self.settings.render.item = function(data) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3614 return append(render_item.apply(this, arguments), html); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3615 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3616 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3617 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3618 original.apply(this, arguments); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3619 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3620 // add event listener |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3621 this.$control.on('click', '.' + options.className, function(e) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3622 e.preventDefault(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3623 if (self.isLocked) return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3624 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3625 var $item = $(e.currentTarget).parent(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3626 self.setActiveItem($item); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3627 if (self.deleteSelection()) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3628 self.setCaret(self.items.length); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3629 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3630 }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3631 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3632 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3633 })(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3634 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3635 }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3636 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3637 Selectize.define('restore_on_backspace', function(options) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3638 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3639 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3640 options.text = options.text || function(option) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3641 return option[this.settings.labelField]; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3642 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3643 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3644 this.onKeyDown = (function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3645 var original = self.onKeyDown; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3646 return function(e) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3647 var index, option; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3648 if (e.keyCode === KEY_BACKSPACE && this.$control_input.val() === '' && !this.$activeItems.length) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3649 index = this.caretPos - 1; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3650 if (index >= 0 && index < this.items.length) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3651 option = this.options[this.items[index]]; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3652 if (this.deleteSelection(e)) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3653 this.setTextboxValue(options.text.apply(this, [option])); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3654 this.refreshOptions(true); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3655 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3656 e.preventDefault(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3657 return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3658 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3659 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3660 return original.apply(this, arguments); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3661 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3662 })(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3663 }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3664 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3665 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3666 return Selectize; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3667 })); |