Mercurial > hg > NetworkVis
annotate query_builder/selectize/dist/js/selectize.js @ 31:a6b2a09ea413
fix commentary chain visualisation author name display and search by clicking author name.
author | casties |
---|---|
date | Fri, 11 Dec 2015 17:06:26 -0500 |
parents | 22be4ea663a7 |
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 * 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
|
3 * 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
|
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 /*jshint curly:false */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
18 /*jshint browser:true */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
19 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
20 (function(root, factory) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
21 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
|
22 define(['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
|
23 } 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
|
24 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
|
25 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
26 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
|
27 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
28 }(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
|
29 'use strict'; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
30 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
31 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
|
32 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
|
33 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
|
34 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
35 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
|
36 var skip = 0; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
37 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
|
38 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
|
39 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
|
40 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
|
41 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
|
42 spannode.className = 'highlight'; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
43 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
|
44 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
|
45 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
|
46 spannode.appendChild(middleclone); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
47 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
|
48 skip = 1; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
49 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
50 } 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
|
51 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
|
52 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
|
53 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
54 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
55 return skip; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
56 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
57 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
58 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
|
59 highlight(this); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
60 }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
61 }; |
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 var MicroEvent = function() {}; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
64 MicroEvent.prototype = { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
65 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
|
66 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
|
67 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
|
68 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
|
69 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
70 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
|
71 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
|
72 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
|
73 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
|
74 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
75 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
|
76 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
|
77 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
|
78 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
79 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
|
80 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
|
81 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
|
82 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
|
83 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
|
84 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
85 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
86 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
87 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
88 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
89 * 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
|
90 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
91 * - 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
|
92 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
93 * @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
|
94 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
95 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
|
96 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
|
97 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
|
98 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
|
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 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
|
103 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
104 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
|
105 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
|
106 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
|
107 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
|
108 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
|
109 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
|
110 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
|
111 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
|
112 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
|
113 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
|
114 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
|
115 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
|
116 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
|
117 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
|
118 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
|
119 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
|
120 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
121 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
|
122 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
|
123 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
124 // 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
|
125 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
|
126 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
127 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
|
128 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
|
129 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
130 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
131 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
132 * 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
|
133 * 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
|
134 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
135 * Transformations: |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
136 * 'str' -> 'str' |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
137 * null -> '' |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
138 * undefined -> '' |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
139 * true -> '1' |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
140 * false -> '0' |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
141 * 0 -> '0' |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
142 * 1 -> '1' |
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 * @param {string} value |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
145 * @returns {string|null} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
146 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
147 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
|
148 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
|
149 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
|
150 return value + ''; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
151 }; |
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 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
154 * 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
|
155 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
156 * @param {string} str |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
157 * @returns {string} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
158 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
159 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
|
160 return (str + '') |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
161 .replace(/&/g, '&') |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
162 .replace(/</g, '<') |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
163 .replace(/>/g, '>') |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
164 .replace(/"/g, '"'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
165 }; |
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 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
168 * 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
|
169 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
170 * @param {string} str |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
171 * @returns {string} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
172 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
173 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
|
174 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
|
175 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
176 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
177 var hook = {}; |
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 * 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
|
181 * 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
|
182 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
183 * @param {object} self |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
184 * @param {string} method |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
185 * @param {function} fn |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
186 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
187 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
|
188 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
|
189 self[method] = function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
190 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
|
191 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
|
192 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
193 }; |
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 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
196 * 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
|
197 * 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
|
198 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
199 * @param {object} self |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
200 * @param {string} method |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
201 * @param {function} fn |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
202 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
203 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
|
204 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
|
205 self[method] = function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
206 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
|
207 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
|
208 return result; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
209 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
210 }; |
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 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
213 * 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
|
214 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
215 * @param {function} fn |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
216 * @returns {function} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
217 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
218 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
|
219 var called = false; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
220 return function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
221 if (called) return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
222 called = true; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
223 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
|
224 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
225 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
226 |
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 * 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
|
229 * 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
|
230 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
231 * @param {function} fn |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
232 * @param {int} delay |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
233 * @returns {function} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
234 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
235 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
|
236 var timeout; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
237 return function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
238 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
239 var args = arguments; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
240 window.clearTimeout(timeout); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
241 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
|
242 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
|
243 }, delay); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
244 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
245 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
246 |
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 * 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
|
249 * 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
|
250 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
251 * @param {object} self |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
252 * @param {array} types |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
253 * @param {function} fn |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
254 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
255 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
|
256 var type; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
257 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
|
258 var event_args = {}; |
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 // override trigger method |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
261 self.trigger = function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
262 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
|
263 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
|
264 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
|
265 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
266 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
|
267 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
268 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
269 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
270 // invoke provided function |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
271 fn.apply(self, []); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
272 self.trigger = trigger; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
273 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
274 // trigger queued events |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
275 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
|
276 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
|
277 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
|
278 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
279 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
280 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
281 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
282 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
283 * 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
|
284 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
285 * @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
|
286 * @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
|
287 * @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
|
288 * @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
|
289 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
290 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
|
291 $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
|
292 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
|
293 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
|
294 child = child.parentNode; |
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 e.currentTarget = child; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
297 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
|
298 }); |
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 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
301 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
302 * 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
|
303 * 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
|
304 * - start |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
305 * - length |
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 * @param {object} input |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
308 * @returns {object} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
309 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
310 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
|
311 var result = {}; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
312 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
|
313 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
|
314 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
|
315 } 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
|
316 input.focus(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
317 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
|
318 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
|
319 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
|
320 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
|
321 result.length = selLen; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
322 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
323 return result; |
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 * 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
|
328 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
329 * @param {object} $from |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
330 * @param {object} $to |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
331 * @param {array} properties |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
332 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
333 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
|
334 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
|
335 if (properties) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
336 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
|
337 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
|
338 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
339 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
340 styles = $from.css(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
341 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
342 $to.css(styles); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
343 }; |
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 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
346 * 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
|
347 * 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
|
348 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
349 * @param {string} str |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
350 * @param {object} $parent |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
351 * @returns {int} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
352 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
353 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
|
354 if (!str) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
355 return 0; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
356 } |
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 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
|
359 position: 'absolute', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
360 top: -99999, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
361 left: -99999, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
362 width: 'auto', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
363 padding: 0, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
364 whiteSpace: 'pre' |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
365 }).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
|
366 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
367 transferStyles($parent, $test, [ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
368 'letterSpacing', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
369 'fontSize', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
370 'fontFamily', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
371 'fontWeight', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
372 'textTransform' |
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 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
|
376 $test.remove(); |
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 return width; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
379 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
380 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
381 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
382 * 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
|
383 * 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
|
384 * 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
|
385 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
386 * $input.trigger('update'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
387 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
388 * @param {object} $input |
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 autoGrow = function($input) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
391 var currentWidth = null; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
392 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
393 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
|
394 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
|
395 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
|
396 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
|
397 options = options || {}; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
398 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
399 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
|
400 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
|
401 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
402 value = $input.val(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
403 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
|
404 keyCode = e.keyCode; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
405 printable = ( |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
406 (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
|
407 (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
|
408 (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
|
409 keyCode === 32 // space |
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 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
|
413 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
|
414 if (selection.length) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
415 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
|
416 } 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
|
417 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
|
418 } 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
|
419 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
|
420 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
421 } else if (printable) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
422 shift = e.shiftKey; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
423 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
|
424 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
|
425 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
|
426 value += character; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
427 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
428 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
429 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
430 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
|
431 if (!value && placeholder) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
432 value = placeholder; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
433 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
434 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
435 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
|
436 if (width !== currentWidth) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
437 currentWidth = width; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
438 $input.width(width); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
439 $input.triggerHandler('resize'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
440 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
441 }; |
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 $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
|
444 update(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
445 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
446 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
447 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
|
448 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
|
449 input = $input[0]; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
450 input.selectize = self; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
451 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
452 // detect rtl environment |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
453 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
|
454 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
|
455 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
|
456 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
457 // setup default state |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
458 $.extend(self, { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
459 order : 0, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
460 settings : settings, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
461 $input : $input, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
462 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
|
463 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
|
464 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
|
465 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
466 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
|
467 highlightedValue : null, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
468 isOpen : false, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
469 isDisabled : false, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
470 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
|
471 isInvalid : false, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
472 isLocked : false, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
473 isFocused : false, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
474 isInputHidden : false, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
475 isSetup : false, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
476 isShiftDown : false, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
477 isCmdDown : false, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
478 isCtrlDown : false, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
479 ignoreFocus : false, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
480 ignoreBlur : false, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
481 ignoreHover : false, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
482 hasOptions : false, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
483 currentResults : null, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
484 lastValue : '', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
485 caretPos : 0, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
486 loading : 0, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
487 loadedSearches : {}, |
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 $activeOption : null, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
490 $activeItems : [], |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
491 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
492 optgroups : {}, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
493 options : {}, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
494 userOptions : {}, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
495 items : [], |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
496 renderCache : {}, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
497 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
|
498 }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
499 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
500 // search system |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
501 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
|
502 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
503 // build options table |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
504 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
|
505 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
|
506 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
|
507 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
508 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
|
509 } |
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 // build optgroup table |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
512 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
|
513 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
|
514 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
|
515 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
516 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
|
517 } |
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 // option-dependent defaults |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
520 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
|
521 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
|
522 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
|
523 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
524 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
525 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
|
526 self.setupCallbacks(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
527 self.setupTemplates(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
528 self.setup(); |
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 // mixins |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
532 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
533 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
534 MicroEvent.mixin(Selectize); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
535 MicroPlugin.mixin(Selectize); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
536 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
537 // methods |
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 $.extend(Selectize.prototype, { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
541 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
542 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
543 * 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
|
544 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
545 setup: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
546 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
547 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
|
548 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
|
549 var $window = $(window); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
550 var $document = $(document); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
551 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
|
552 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
553 var $wrapper; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
554 var $control; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
555 var $control_input; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
556 var $dropdown; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
557 var $dropdown_content; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
558 var $dropdown_parent; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
559 var inputMode; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
560 var timeout_blur; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
561 var timeout_focus; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
562 var classes; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
563 var classes_plugins; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
564 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
565 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
|
566 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
|
567 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
568 $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
|
569 $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
|
570 $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
|
571 $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
|
572 $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
|
573 $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
|
574 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
575 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
|
576 $dropdown.addClass(classes); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
577 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
578 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
579 $wrapper.css({ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
580 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
|
581 }); |
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 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
|
584 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
|
585 $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
|
586 $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
|
587 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
588 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
589 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
|
590 $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
|
591 } |
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 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
|
594 $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
|
595 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
596 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
597 // 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
|
598 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
|
599 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
|
600 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
|
601 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
602 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
603 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
|
604 $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
|
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 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
|
608 $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
|
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 self.$wrapper = $wrapper; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
612 self.$control = $control; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
613 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
|
614 self.$dropdown = $dropdown; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
615 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
|
616 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
617 $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
|
618 $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
|
619 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
|
620 autoGrow($control_input); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
621 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
622 $control.on({ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
623 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
|
624 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
|
625 }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
626 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
627 $control_input.on({ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
628 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
|
629 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
|
630 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
|
631 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
|
632 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
|
633 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
|
634 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
|
635 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
|
636 }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
637 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
638 $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
|
639 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
|
640 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
|
641 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
|
642 }); |
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 $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
|
645 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
|
646 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
|
647 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
|
648 }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
649 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
650 $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
|
651 if (self.isFocused) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
652 // 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
|
653 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
|
654 return false; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
655 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
656 // 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
|
657 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
|
658 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
|
659 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
660 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
661 }); |
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 $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
|
664 if (self.isOpen) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
665 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
|
666 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
667 }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
668 $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
|
669 self.ignoreHover = false; |
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 // 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
|
673 // 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
|
674 this.revertSettings = { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
675 $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
|
676 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
|
677 }; |
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 $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
|
680 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
681 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
|
682 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
|
683 delete settings.items; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
684 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
685 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
686 // 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
|
687 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
|
688 $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
|
689 e.preventDefault(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
690 self.isInvalid = true; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
691 self.refreshState(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
692 }); |
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 self.updateOriginalInput(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
696 self.refreshItems(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
697 self.refreshState(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
698 self.updatePlaceholder(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
699 self.isSetup = true; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
700 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
701 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
|
702 self.disable(); |
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 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
705 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
|
706 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
707 $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
|
708 $input.addClass('selectized'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
709 self.trigger('initialize'); |
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 // preload options |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
712 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
|
713 self.onSearchChange(''); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
714 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
715 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
716 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
717 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
718 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
719 * 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
|
720 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
721 setupTemplates: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
722 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
723 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
|
724 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
|
725 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
726 var templates = { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
727 'optgroup': function(data) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
728 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
|
729 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
730 '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
|
731 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
|
732 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
733 '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
|
734 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
|
735 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
736 '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
|
737 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
|
738 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
739 '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
|
740 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
|
741 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
742 }; |
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 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
|
745 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
746 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
747 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
748 * 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
|
749 * 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
|
750 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
751 setupCallbacks: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
752 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
|
753 'initialize' : 'onInitialize', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
754 'change' : 'onChange', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
755 'item_add' : 'onItemAdd', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
756 'item_remove' : 'onItemRemove', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
757 'clear' : 'onClear', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
758 'option_add' : 'onOptionAdd', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
759 'option_remove' : 'onOptionRemove', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
760 'option_clear' : 'onOptionClear', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
761 'optgroup_add' : 'onOptionGroupAdd', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
762 'optgroup_remove' : 'onOptionGroupRemove', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
763 'optgroup_clear' : 'onOptionGroupClear', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
764 'dropdown_open' : 'onDropdownOpen', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
765 'dropdown_close' : 'onDropdownClose', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
766 'type' : 'onType', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
767 'load' : 'onLoad', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
768 'focus' : 'onFocus', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
769 'blur' : 'onBlur' |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
770 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
771 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
772 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
|
773 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
|
774 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
|
775 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
|
776 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
777 } |
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 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
780 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
781 * 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
|
782 * 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
|
783 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
784 * @param {object} e |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
785 * @return {boolean} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
786 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
787 onClick: function(e) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
788 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
789 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
790 // 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
|
791 // 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
|
792 if (!self.isFocused) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
793 self.focus(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
794 e.preventDefault(); |
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 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
797 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
798 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
799 * 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
|
800 * 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
|
801 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
802 * @param {object} e |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
803 * @return {boolean} |
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 onMouseDown: function(e) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
806 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
807 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
|
808 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
|
809 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
810 if (self.isFocused) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
811 // 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
|
812 // 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
|
813 // 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
|
814 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
|
815 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
|
816 // toggle dropdown |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
817 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
|
818 } else if (!defaultPrevented) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
819 self.setActiveItem(null); |
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 return false; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
822 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
823 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
824 // give control focus |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
825 if (!defaultPrevented) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
826 window.setTimeout(function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
827 self.focus(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
828 }, 0); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
829 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
830 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
831 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
832 |
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 * 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
|
835 * 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
|
836 * input / select element. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
837 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
838 onChange: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
839 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
|
840 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
841 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
842 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
843 * 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
|
844 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
845 * @param {object} e |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
846 * @returns {boolean} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
847 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
848 onPaste: function(e) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
849 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
850 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
|
851 e.preventDefault(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
852 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
853 // 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
|
854 // 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
|
855 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
|
856 setTimeout(function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
857 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
|
858 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
|
859 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
|
860 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
861 }, 0); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
862 } |
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 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
865 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
866 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
867 * 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
|
868 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
869 * @param {object} e |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
870 * @returns {boolean} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
871 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
872 onKeyPress: function(e) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
873 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
|
874 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
|
875 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
|
876 this.createItem(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
877 e.preventDefault(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
878 return false; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
879 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
880 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
881 |
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 * 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
|
884 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
885 * @param {object} e |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
886 * @returns {boolean} |
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 onKeyDown: function(e) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
889 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
|
890 var self = this; |
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 if (self.isLocked) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
893 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
|
894 e.preventDefault(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
895 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
896 return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
897 } |
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 switch (e.keyCode) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
900 case KEY_A: |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
901 if (self.isCmdDown) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
902 self.selectAll(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
903 return; |
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 break; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
906 case KEY_ESC: |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
907 if (self.isOpen) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
908 e.preventDefault(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
909 e.stopPropagation(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
910 self.close(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
911 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
912 return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
913 case KEY_N: |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
914 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
|
915 case KEY_DOWN: |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
916 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
|
917 self.open(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
918 } 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
|
919 self.ignoreHover = true; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
920 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
|
921 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
|
922 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
923 e.preventDefault(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
924 return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
925 case KEY_P: |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
926 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
|
927 case KEY_UP: |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
928 if (self.$activeOption) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
929 self.ignoreHover = true; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
930 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
|
931 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
|
932 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
933 e.preventDefault(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
934 return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
935 case KEY_RETURN: |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
936 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
|
937 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
|
938 e.preventDefault(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
939 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
940 return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
941 case KEY_LEFT: |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
942 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
|
943 return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
944 case KEY_RIGHT: |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
945 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
|
946 return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
947 case KEY_TAB: |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
948 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
|
949 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
|
950 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
951 // 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
|
952 // 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
|
953 if (!self.isFull()) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
954 e.preventDefault(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
955 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
956 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
957 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
|
958 e.preventDefault(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
959 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
960 return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
961 case KEY_BACKSPACE: |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
962 case KEY_DELETE: |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
963 self.deleteSelection(e); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
964 return; |
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 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
|
968 e.preventDefault(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
969 return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
970 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
971 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
972 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
973 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
974 * 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
|
975 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
976 * @param {object} e |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
977 * @returns {boolean} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
978 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
979 onKeyUp: function(e) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
980 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
981 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
982 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
|
983 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
|
984 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
|
985 self.lastValue = value; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
986 self.onSearchChange(value); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
987 self.refreshOptions(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
988 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
|
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 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
992 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
993 * 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
|
994 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
995 * 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
|
996 * 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
|
997 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
998 * @param {string} value |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
999 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1000 onSearchChange: function(value) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1001 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1002 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
|
1003 if (!fn) return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1004 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
|
1005 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
|
1006 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
|
1007 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
|
1008 }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1009 }, |
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 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1012 * 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
|
1013 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1014 * @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
|
1015 * @returns {boolean} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1016 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1017 onFocus: function(e) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1018 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1019 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
|
1020 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1021 if (self.isDisabled) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1022 self.blur(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1023 e && e.preventDefault(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1024 return false; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1025 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1026 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1027 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
|
1028 self.isFocused = true; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1029 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
|
1030 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1031 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
|
1032 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1033 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
|
1034 self.showInput(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1035 self.setActiveItem(null); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1036 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
|
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 self.refreshState(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1040 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1041 |
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 * 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
|
1044 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1045 * @param {object} e |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1046 * @param {Element} dest |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1047 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1048 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
|
1049 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1050 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
|
1051 self.isFocused = false; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1052 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1053 if (self.ignoreFocus) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1054 return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1055 } 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
|
1056 // 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
|
1057 self.ignoreBlur = true; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1058 self.onFocus(e); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1059 return; |
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 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1062 var deactivate = function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1063 self.close(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1064 self.setTextboxValue(''); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1065 self.setActiveItem(null); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1066 self.setActiveOption(null); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1067 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
|
1068 self.refreshState(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1069 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1070 // 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
|
1071 (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
|
1072 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1073 self.ignoreFocus = false; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1074 self.trigger('blur'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1075 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1076 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1077 self.ignoreFocus = true; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1078 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
|
1079 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
|
1080 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1081 deactivate(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1082 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1083 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1084 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1085 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1086 * 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
|
1087 * 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
|
1088 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1089 * @param {object} e |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1090 * @returns {boolean} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1091 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1092 onOptionHover: function(e) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1093 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
|
1094 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
|
1095 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1096 |
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 * 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
|
1099 * 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
|
1100 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1101 * @param {object} e |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1102 * @returns {boolean} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1103 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1104 onOptionSelect: function(e) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1105 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
|
1106 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1107 if (e.preventDefault) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1108 e.preventDefault(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1109 e.stopPropagation(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1110 } |
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 $target = $(e.currentTarget); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1113 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
|
1114 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
|
1115 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
|
1116 self.close(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1117 } |
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 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1120 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
|
1121 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
|
1122 self.lastQuery = null; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1123 self.setTextboxValue(''); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1124 self.addItem(value); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1125 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
|
1126 self.close(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1127 } 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
|
1128 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
|
1129 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1130 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1131 } |
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 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1135 * 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
|
1136 * 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
|
1137 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1138 * @param {object} e |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1139 * @returns {boolean} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1140 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1141 onItemSelect: function(e) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1142 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1143 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1144 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
|
1145 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
|
1146 e.preventDefault(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1147 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
|
1148 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1149 }, |
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 * 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
|
1153 * 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
|
1154 * 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
|
1155 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1156 * @param {function} fn |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1157 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1158 load: function(fn) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1159 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1160 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
|
1161 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1162 self.loading++; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1163 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
|
1164 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
|
1165 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
|
1166 self.addOption(results); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1167 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
|
1168 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1169 if (!self.loading) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1170 $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
|
1171 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1172 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
|
1173 }]); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1174 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1175 |
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 * 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
|
1178 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1179 * @param {string} value |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1180 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1181 setTextboxValue: function(value) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1182 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
|
1183 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
|
1184 if (changed) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1185 $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
|
1186 this.lastValue = value; |
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 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1189 |
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 * 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
|
1192 * 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
|
1193 * 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
|
1194 * returns a string. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1195 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1196 * @returns {mixed} |
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 getValue: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1199 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
|
1200 return this.items; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1201 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1202 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
|
1203 } |
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 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1207 * 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
|
1208 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1209 * @param {mixed} value |
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 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
|
1212 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
|
1213 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1214 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
|
1215 this.clear(silent); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1216 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
|
1217 }); |
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 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1221 * 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
|
1222 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1223 * @param {object} $item |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1224 * @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
|
1225 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1226 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
|
1227 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1228 var eventName; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1229 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
|
1230 var $last; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1231 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1232 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
|
1233 $item = $($item); |
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 // 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
|
1236 if (!$item.length) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1237 $(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
|
1238 self.$activeItems = []; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1239 if (self.isFocused) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1240 self.showInput(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1241 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1242 return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1243 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1244 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1245 // modify selection |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1246 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
|
1247 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1248 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
|
1249 $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
|
1250 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
|
1251 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
|
1252 if (begin > end) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1253 swap = begin; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1254 begin = end; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1255 end = swap; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1256 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1257 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
|
1258 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
|
1259 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
|
1260 $(item).addClass('active'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1261 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
|
1262 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1263 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1264 e.preventDefault(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1265 } 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
|
1266 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
|
1267 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
|
1268 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
|
1269 $item.removeClass('active'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1270 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1271 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
|
1272 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1273 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1274 $(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
|
1275 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
|
1276 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1277 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1278 // 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
|
1279 self.hideInput(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1280 if (!this.isFocused) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1281 self.focus(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1282 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1283 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1284 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1285 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1286 * 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
|
1287 * of available options. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1288 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1289 * @param {object} $object |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1290 * @param {boolean} scroll |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1291 * @param {boolean} animate |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1292 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1293 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
|
1294 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
|
1295 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
|
1296 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1297 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1298 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
|
1299 self.$activeOption = null; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1300 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1301 $option = $($option); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1302 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
|
1303 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1304 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
|
1305 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1306 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
|
1307 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1308 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
|
1309 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
|
1310 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
|
1311 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
|
1312 scroll_top = y; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1313 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
|
1314 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1315 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
|
1316 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
|
1317 } 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
|
1318 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
|
1319 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1320 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1321 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1322 }, |
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 * 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
|
1326 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1327 selectAll: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1328 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1329 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
|
1330 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1331 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
|
1332 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
|
1333 self.hideInput(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1334 self.close(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1335 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1336 self.focus(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1337 }, |
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 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1340 * 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
|
1341 * retaining its focus. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1342 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1343 hideInput: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1344 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1345 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1346 self.setTextboxValue(''); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1347 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
|
1348 self.isInputHidden = true; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1349 }, |
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 * Restores input visibility. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1353 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1354 showInput: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1355 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
|
1356 this.isInputHidden = false; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1357 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1358 |
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 * 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
|
1361 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1362 focus: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1363 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1364 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
|
1365 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1366 self.ignoreFocus = true; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1367 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
|
1368 window.setTimeout(function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1369 self.ignoreFocus = false; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1370 self.onFocus(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1371 }, 0); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1372 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1373 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1374 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1375 * 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
|
1376 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1377 * @param {Element} dest |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1378 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1379 blur: function(dest) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1380 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
|
1381 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
|
1382 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1383 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1384 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1385 * 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
|
1386 * 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
|
1387 * provided query. |
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 * @param {string} query |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1390 * @param {object} options |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1391 * @return {function} |
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 getScoreFunction: function(query) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1394 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
|
1395 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1396 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1397 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1398 * 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
|
1399 * 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
|
1400 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1401 * @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
|
1402 * @return {object} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1403 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1404 getSearchOptions: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1405 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
|
1406 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
|
1407 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
|
1408 sort = [{field: sort}]; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1409 } |
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 return { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1412 fields : settings.searchField, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1413 conjunction : settings.searchConjunction, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1414 sort : sort |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1415 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1416 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1417 |
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 * 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
|
1420 * 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
|
1421 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1422 * 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
|
1423 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1424 * - query {string} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1425 * - tokens {array} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1426 * - total {int} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1427 * - items {array} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1428 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1429 * @param {string} query |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1430 * @returns {object} |
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 search: function(query) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1433 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
|
1434 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1435 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
|
1436 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
|
1437 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1438 // 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
|
1439 if (settings.score) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1440 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
|
1441 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
|
1442 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
|
1443 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1444 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1445 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1446 // perform search |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1447 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
|
1448 self.lastQuery = query; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1449 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
|
1450 self.currentResults = result; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1451 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1452 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
|
1453 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1454 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1455 // 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
|
1456 if (settings.hideSelected) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1457 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
|
1458 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
|
1459 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
|
1460 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1461 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1462 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1463 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1464 return result; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1465 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1466 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1467 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1468 * 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
|
1469 * 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
|
1470 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1471 * @param {boolean} triggerDropdown |
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 refreshOptions: function(triggerDropdown) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1474 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
|
1475 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
|
1476 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1477 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
|
1478 triggerDropdown = true; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1479 } |
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 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1482 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
|
1483 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
|
1484 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
|
1485 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
|
1486 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1487 // build markup |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1488 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
|
1489 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
|
1490 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
|
1491 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1492 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1493 // 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
|
1494 groups = {}; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1495 groups_order = []; |
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 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
|
1498 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
|
1499 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
|
1500 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
|
1501 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
|
1502 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1503 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
|
1504 optgroup = optgroups[j]; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1505 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
|
1506 optgroup = ''; |
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 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
|
1509 groups[optgroup] = []; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1510 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
|
1511 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1512 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
|
1513 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1514 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1515 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1516 // sort optgroups |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1517 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
|
1518 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
|
1519 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
|
1520 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
|
1521 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
|
1522 }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1523 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1524 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1525 // 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
|
1526 html = []; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1527 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
|
1528 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
|
1529 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
|
1530 // 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
|
1531 // 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
|
1532 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
|
1533 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
|
1534 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
|
1535 html: html_children |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1536 }))); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1537 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1538 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
|
1539 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1540 } |
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 $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
|
1543 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1544 // 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
|
1545 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
|
1546 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
|
1547 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
|
1548 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1549 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1550 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1551 // 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
|
1552 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
|
1553 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
|
1554 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
|
1555 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1556 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1557 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1558 // add create option |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1559 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
|
1560 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
|
1561 $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
|
1562 $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
|
1563 } |
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 // activate |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1566 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
|
1567 if (self.hasOptions) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1568 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
|
1569 $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
|
1570 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
|
1571 $active = $active_before; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1572 } 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
|
1573 $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
|
1574 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1575 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
|
1576 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
|
1577 $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
|
1578 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1579 $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
|
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 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1583 $active = $create; |
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 self.setActiveOption($active); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1586 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
|
1587 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1588 self.setActiveOption(null); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1589 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
|
1590 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1591 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1592 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1593 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1594 * 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
|
1595 * 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
|
1596 * 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
|
1597 * for that). |
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 * Usage: |
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 * this.addOption(data) |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1602 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1603 * @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
|
1604 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1605 addOption: function(data) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1606 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
|
1607 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1608 if ($.isArray(data)) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1609 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
|
1610 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
|
1611 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1612 return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1613 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1614 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1615 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
|
1616 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
|
1617 self.lastQuery = null; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1618 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
|
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 |
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 * 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
|
1624 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1625 * @param {object} data |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1626 * @return {boolean|string} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1627 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1628 registerOption: function(data) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1629 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
|
1630 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
|
1631 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
|
1632 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
|
1633 return key; |
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 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1637 * 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
|
1638 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1639 * @param {object} data |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1640 * @return {boolean|string} |
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 registerOptionGroup: function(data) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1643 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
|
1644 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
|
1645 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1646 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
|
1647 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
|
1648 return key; |
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 * 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
|
1653 * 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
|
1654 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1655 * @param {string} id |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1656 * @param {object} data |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1657 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1658 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
|
1659 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
|
1660 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
|
1661 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
|
1662 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1663 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1664 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1665 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1666 * 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
|
1667 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1668 * @param {string} id |
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 removeOptionGroup: function(id) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1671 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
|
1672 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
|
1673 this.renderCache = {}; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1674 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
|
1675 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1676 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1677 |
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 * 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
|
1680 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1681 clearOptionGroups: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1682 this.optgroups = {}; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1683 this.renderCache = {}; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1684 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
|
1685 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1686 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1687 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1688 * 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
|
1689 * 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
|
1690 * 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
|
1691 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1692 * @param {string} value |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1693 * @param {object} data |
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 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
|
1696 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1697 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
|
1698 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
|
1699 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1700 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
|
1701 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
|
1702 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1703 // sanity checks |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1704 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
|
1705 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
|
1706 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
|
1707 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1708 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
|
1709 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1710 // update references |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1711 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
|
1712 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
|
1713 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
|
1714 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
|
1715 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
|
1716 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1717 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1718 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
|
1719 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
|
1720 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1721 // invalidate render cache |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1722 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
|
1723 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
|
1724 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1725 if (cache_items) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1726 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
|
1727 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
|
1728 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1729 if (cache_options) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1730 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
|
1731 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
|
1732 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1733 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1734 // 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
|
1735 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
|
1736 $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
|
1737 $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
|
1738 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
|
1739 $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
|
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 // 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
|
1743 self.lastQuery = null; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1744 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1745 // update dropdown contents |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1746 if (self.isOpen) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1747 self.refreshOptions(false); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1748 } |
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 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1751 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1752 * 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
|
1753 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1754 * @param {string} value |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1755 * @param {boolean} silent |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1756 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1757 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
|
1758 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1759 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
|
1760 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1761 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
|
1762 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
|
1763 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
|
1764 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
|
1765 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1766 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
|
1767 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
|
1768 self.lastQuery = null; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1769 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
|
1770 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
|
1771 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1772 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1773 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1774 * Clears all options. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1775 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1776 clearOptions: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1777 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1778 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1779 self.loadedSearches = {}; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1780 self.userOptions = {}; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1781 self.renderCache = {}; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1782 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
|
1783 self.lastQuery = null; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1784 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
|
1785 self.clear(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1786 }, |
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 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1789 * 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
|
1790 * 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
|
1791 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1792 * @param {string} value |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1793 * @returns {object} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1794 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1795 getOption: function(value) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1796 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
|
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 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
|
1801 * previous selectable option. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1802 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1803 * @param {object} $option |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1804 * @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
|
1805 * @return {object} |
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 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
|
1808 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
|
1809 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
|
1810 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1811 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
|
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 * 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
|
1816 * 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
|
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 * @param {object} $els |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1820 * @return {object} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1821 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1822 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
|
1823 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
|
1824 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1825 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
|
1826 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
|
1827 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
|
1828 return $($els[i]); |
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 } |
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 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1833 return $(); |
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 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1836 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1837 * 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
|
1838 * 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
|
1839 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1840 * @param {string} value |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1841 * @returns {object} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1842 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1843 getItem: function(value) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1844 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
|
1845 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1846 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1847 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1848 * "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
|
1849 * 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
|
1850 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1851 * @param {string} value |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1852 * @param {boolean} silent |
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 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
|
1855 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
|
1856 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
|
1857 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
|
1858 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
|
1859 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1860 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1861 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1862 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1863 * "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
|
1864 * 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
|
1865 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1866 * @param {string} value |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1867 * @param {boolean} silent |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1868 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1869 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
|
1870 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
|
1871 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1872 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
|
1873 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
|
1874 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1875 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
|
1876 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
|
1877 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
|
1878 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1879 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
|
1880 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
|
1881 return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1882 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1883 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1884 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
|
1885 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
|
1886 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
|
1887 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1888 $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
|
1889 wasFull = self.isFull(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1890 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
|
1891 self.insertAtCaret($item); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1892 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
|
1893 self.refreshState(); |
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 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1896 if (self.isSetup) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1897 $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
|
1898 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1899 // 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
|
1900 if (!self.isPending) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1901 $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
|
1902 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
|
1903 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
|
1904 if (value_next) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1905 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
|
1906 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1907 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1908 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1909 // 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
|
1910 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
|
1911 self.close(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1912 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1913 self.positionDropdown(); |
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 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1916 self.updatePlaceholder(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1917 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
|
1918 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
|
1919 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1920 }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1921 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1922 |
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 * 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
|
1925 * the provided value. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1926 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1927 * @param {string} value |
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 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
|
1930 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1931 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
|
1932 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1933 $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
|
1934 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
|
1935 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
|
1936 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1937 if (i !== -1) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1938 $item.remove(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1939 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
|
1940 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
|
1941 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
|
1942 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1943 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1944 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
|
1945 self.lastQuery = null; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1946 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
|
1947 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
|
1948 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1949 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1950 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
|
1951 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
|
1952 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1953 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1954 self.refreshState(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1955 self.updatePlaceholder(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1956 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
|
1957 self.positionDropdown(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1958 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
|
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 |
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 * 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
|
1964 * 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
|
1965 * 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
|
1966 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1967 * 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
|
1968 * 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
|
1969 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1970 * @param {string} value |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1971 * @param {boolean} [triggerDropdown] |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1972 * @param {function} [callback] |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1973 * @return {boolean} |
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 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
|
1976 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1977 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
|
1978 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
|
1979 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1980 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
|
1981 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
|
1982 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1983 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
|
1984 triggerDropdown = true; |
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 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1987 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
|
1988 callback(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1989 return false; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1990 } |
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 self.lock(); |
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 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
|
1995 var data = {}; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1996 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
|
1997 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
|
1998 return data; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
1999 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2000 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2001 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
|
2002 self.unlock(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2003 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2004 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
|
2005 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
|
2006 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
|
2007 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2008 self.setTextboxValue(''); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2009 self.addOption(data); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2010 self.setCaret(caret); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2011 self.addItem(value); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2012 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
|
2013 callback(data); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2014 }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2015 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2016 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
|
2017 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
|
2018 create(output); |
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 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2021 return true; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2022 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2023 |
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 * 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
|
2026 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2027 refreshItems: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2028 this.lastQuery = null; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2029 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2030 if (this.isSetup) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2031 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
|
2032 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2033 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2034 this.refreshState(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2035 this.updateOriginalInput(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2036 }, |
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 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2039 * 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
|
2040 * and CSS classes. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2041 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2042 refreshState: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2043 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
|
2044 if (self.isRequired) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2045 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
|
2046 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
|
2047 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2048 self.refreshClasses(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2049 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2050 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2051 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2052 * 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
|
2053 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2054 refreshClasses: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2055 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2056 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
|
2057 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
|
2058 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2059 self.$wrapper |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2060 .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
|
2061 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2062 self.$control |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2063 .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
|
2064 .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
|
2065 .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
|
2066 .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
|
2067 .toggleClass('locked', isLocked) |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2068 .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
|
2069 .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
|
2070 .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
|
2071 .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
|
2072 .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
|
2073 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2074 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
|
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 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2078 * 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
|
2079 * 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
|
2080 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2081 * @returns {boolean} |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2082 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2083 isFull: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2084 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
|
2085 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2086 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2087 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2088 * 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
|
2089 * 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
|
2090 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2091 updateOriginalInput: function(opts) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2092 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
|
2093 opts = opts || {}; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2094 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2095 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
|
2096 options = []; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2097 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
|
2098 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
|
2099 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
|
2100 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2101 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
|
2102 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
|
2103 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2104 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
|
2105 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2106 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
|
2107 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
|
2108 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2109 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2110 if (self.isSetup) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2111 if (!opts.silent) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2112 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
|
2113 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2114 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2115 }, |
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 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2118 * 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
|
2119 * 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
|
2120 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2121 updatePlaceholder: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2122 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
|
2123 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
|
2124 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2125 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
|
2126 $input.removeAttr('placeholder'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2127 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2128 $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
|
2129 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2130 $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
|
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 * 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
|
2135 * the available options. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2136 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2137 open: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2138 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2139 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2140 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
|
2141 self.focus(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2142 self.isOpen = true; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2143 self.refreshState(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2144 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
|
2145 self.positionDropdown(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2146 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
|
2147 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
|
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 * 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
|
2152 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2153 close: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2154 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2155 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
|
2156 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2157 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
|
2158 self.hideInput(); |
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 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2161 self.isOpen = false; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2162 self.$dropdown.hide(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2163 self.setActiveOption(null); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2164 self.refreshState(); |
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 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
|
2167 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2168 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2169 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2170 * 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
|
2171 * 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
|
2172 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2173 positionDropdown: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2174 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
|
2175 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
|
2176 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
|
2177 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2178 this.$dropdown.css({ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2179 width : $control.outerWidth(), |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2180 top : offset.top, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2181 left : offset.left |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2182 }); |
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 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2185 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2186 * 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
|
2187 * from the control. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2188 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2189 * @param {boolean} silent |
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 clear: function(silent) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2192 var self = this; |
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 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
|
2195 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
|
2196 self.items = []; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2197 self.lastQuery = null; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2198 self.setCaret(0); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2199 self.setActiveItem(null); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2200 self.updatePlaceholder(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2201 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
|
2202 self.refreshState(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2203 self.showInput(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2204 self.trigger('clear'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2205 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2206 |
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 * 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
|
2209 * 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
|
2210 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2211 * @param {object} $el |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2212 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2213 insertAtCaret: function($el) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2214 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
|
2215 if (caret === 0) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2216 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
|
2217 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2218 $(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
|
2219 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2220 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
|
2221 }, |
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 * 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
|
2225 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2226 * @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
|
2227 * @returns {boolean} |
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 deleteSelection: function(e) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2230 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
|
2231 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2232 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2233 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
|
2234 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
|
2235 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2236 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
|
2237 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
|
2238 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2239 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2240 // 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
|
2241 values = []; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2242 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2243 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
|
2244 $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
|
2245 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
|
2246 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
|
2247 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2248 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
|
2249 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
|
2250 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2251 if (e) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2252 e.preventDefault(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2253 e.stopPropagation(); |
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 } 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
|
2256 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
|
2257 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
|
2258 } 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
|
2259 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
|
2260 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2261 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2262 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2263 // 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
|
2264 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
|
2265 return false; |
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 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2268 // perform removal |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2269 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
|
2270 self.setCaret(caret); |
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 while (values.length) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2273 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
|
2274 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2275 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2276 self.showInput(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2277 self.positionDropdown(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2278 self.refreshOptions(true); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2279 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2280 // select previous option |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2281 if (option_select) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2282 $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
|
2283 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
|
2284 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
|
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 return true; |
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 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2291 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2292 * 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
|
2293 * 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
|
2294 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2295 * > 0 - right |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2296 * < 0 - left |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2297 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2298 * @param {int} direction |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2299 * @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
|
2300 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2301 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
|
2302 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
|
2303 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2304 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2305 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
|
2306 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
|
2307 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2308 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
|
2309 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
|
2310 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2311 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
|
2312 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
|
2313 cursorAtEdge = direction < 0 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2314 ? 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
|
2315 : selection.start === valueLength; |
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 if (cursorAtEdge && !valueLength) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2318 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
|
2319 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2320 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2321 $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
|
2322 if ($tail.length) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2323 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
|
2324 self.setActiveItem(null); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2325 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
|
2326 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2327 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2328 }, |
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 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2331 * 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
|
2332 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2333 * @param {int} direction |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2334 * @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
|
2335 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2336 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
|
2337 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
|
2338 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2339 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
|
2340 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2341 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
|
2342 if (self.isShiftDown) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2343 $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
|
2344 if ($adj.length) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2345 self.hideInput(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2346 self.setActiveItem($adj); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2347 e && e.preventDefault(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2348 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2349 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2350 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
|
2351 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2352 }, |
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 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2355 * 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
|
2356 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2357 * @param {int} i |
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 setCaret: function(i) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2360 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2361 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2362 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
|
2363 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
|
2364 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2365 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
|
2366 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2367 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2368 if(!self.isPending) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2369 // 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
|
2370 // 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
|
2371 // 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
|
2372 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
|
2373 $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
|
2374 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
|
2375 $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
|
2376 if (j < i) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2377 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
|
2378 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2379 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
|
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 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2384 self.caretPos = i; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2385 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2386 |
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 * 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
|
2389 * 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
|
2390 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2391 lock: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2392 this.close(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2393 this.isLocked = true; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2394 this.refreshState(); |
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 * 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
|
2399 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2400 unlock: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2401 this.isLocked = false; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2402 this.refreshState(); |
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 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2405 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2406 * 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
|
2407 * 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
|
2408 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2409 disable: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2410 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2411 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
|
2412 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
|
2413 self.isDisabled = true; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2414 self.lock(); |
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 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2417 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2418 * 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
|
2419 * 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
|
2420 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2421 enable: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2422 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2423 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
|
2424 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
|
2425 self.isDisabled = false; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2426 self.unlock(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2427 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2428 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2429 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2430 * 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
|
2431 * 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
|
2432 * be garbage collected. |
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 destroy: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2435 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2436 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
|
2437 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
|
2438 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2439 self.trigger('destroy'); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2440 self.off(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2441 self.$wrapper.remove(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2442 self.$dropdown.remove(); |
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 self.$input |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2445 .html('') |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2446 .append(revertSettings.$children) |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2447 .removeAttr('tabindex') |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2448 .removeClass('selectized') |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2449 .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
|
2450 .show(); |
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 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
|
2453 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
|
2454 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2455 $(window).off(eventNS); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2456 $(document).off(eventNS); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2457 $(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
|
2458 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2459 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
|
2460 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2461 |
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 * 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
|
2464 * "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
|
2465 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2466 * @param {string} templateName |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2467 * @param {object} data |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2468 * @returns {string} |
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 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
|
2471 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
|
2472 var html = ''; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2473 var cache = false; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2474 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2475 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
|
2476 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2477 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
|
2478 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
|
2479 cache = !!value; |
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 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2482 // 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
|
2483 if (cache) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2484 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
|
2485 self.renderCache[templateName] = {}; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2486 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2487 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
|
2488 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
|
2489 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2490 } |
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 // render markup |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2493 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
|
2494 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2495 // add mandatory attributes |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2496 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
|
2497 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
|
2498 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2499 if (templateName === 'optgroup') { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2500 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
|
2501 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
|
2502 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2503 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
|
2504 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
|
2505 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2506 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2507 // update cache |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2508 if (cache) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2509 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
|
2510 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2511 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2512 return html; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2513 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2514 |
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 * 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
|
2517 * 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
|
2518 * caches. |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2519 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2520 * @param {string} templateName |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2521 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2522 clearCache: function(templateName) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2523 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2524 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
|
2525 self.renderCache = {}; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2526 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2527 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
|
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 * 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
|
2533 * 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
|
2534 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2535 * @param {string} input |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2536 * @return {boolean} |
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 canCreate: function(input) { |
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 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
|
2541 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
|
2542 return input.length |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2543 && (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
|
2544 && (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
|
2545 && (!(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
|
2546 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2547 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2548 }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2549 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2550 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2551 Selectize.count = 0; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2552 Selectize.defaults = { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2553 options: [], |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2554 optgroups: [], |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2555 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2556 plugins: [], |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2557 delimiter: ',', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2558 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
|
2559 persist: true, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2560 diacritics: true, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2561 create: false, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2562 createOnBlur: false, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2563 createFilter: null, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2564 highlight: true, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2565 openOnFocus: true, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2566 maxOptions: 1000, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2567 maxItems: null, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2568 hideSelected: null, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2569 addPrecedence: false, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2570 selectOnTab: false, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2571 preload: false, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2572 allowEmptyOption: false, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2573 closeAfterSelect: false, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2574 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2575 scrollDuration: 60, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2576 loadThrottle: 300, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2577 loadingClass: 'loading', |
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 dataAttr: 'data-data', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2580 optgroupField: 'optgroup', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2581 valueField: 'value', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2582 labelField: 'text', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2583 optgroupLabelField: 'label', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2584 optgroupValueField: 'value', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2585 lockOptgroupOrder: false, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2586 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2587 sortField: '$order', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2588 searchField: ['text'], |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2589 searchConjunction: 'and', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2590 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2591 mode: null, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2592 wrapperClass: 'selectize-control', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2593 inputClass: 'selectize-input', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2594 dropdownClass: 'selectize-dropdown', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2595 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
|
2596 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2597 dropdownParent: null, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2598 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2599 copyClassesToDropdown: true, |
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 /* |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2602 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
|
2603 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
|
2604 onInitialize : null, // function() { ... } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2605 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
|
2606 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
|
2607 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
|
2608 onClear : null, // function() { ... } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2609 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
|
2610 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
|
2611 onOptionClear : null, // function() { ... } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2612 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
|
2613 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
|
2614 onOptionGroupClear : null, // function() { ... } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2615 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
|
2616 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
|
2617 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
|
2618 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
|
2619 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2620 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2621 render: { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2622 /* |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2623 item: null, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2624 optgroup: null, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2625 optgroup_header: null, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2626 option: null, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2627 option_create: null |
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 }; |
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 $.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
|
2634 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
|
2635 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
|
2636 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
|
2637 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
|
2638 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
|
2639 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
|
2640 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
|
2641 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
|
2642 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2643 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2644 * 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
|
2645 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2646 * @param {object} $input |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2647 * @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
|
2648 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2649 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
|
2650 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
|
2651 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2652 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
|
2653 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2654 if (!data_raw) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2655 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
|
2656 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
|
2657 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
|
2658 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
|
2659 option = {}; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2660 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
|
2661 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
|
2662 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
|
2663 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2664 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
|
2665 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2666 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
|
2667 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
|
2668 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
|
2669 } |
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 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2672 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2673 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2674 * 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
|
2675 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2676 * @param {object} $input |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2677 * @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
|
2678 */ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2679 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
|
2680 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
|
2681 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
|
2682 var optionsMap = {}; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2683 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2684 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
|
2685 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
|
2686 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
|
2687 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
|
2688 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2689 return null; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2690 }; |
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 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
|
2693 $option = $($option); |
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 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
|
2696 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
|
2697 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2698 // 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
|
2699 // 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
|
2700 // 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
|
2701 // 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
|
2702 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
|
2703 if (group) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2704 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
|
2705 if (!arr) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2706 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
|
2707 } 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
|
2708 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
|
2709 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2710 arr.push(group); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2711 } |
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 return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2714 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2715 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2716 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
|
2717 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
|
2718 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
|
2719 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
|
2720 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2721 optionsMap[value] = option; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2722 options.push(option); |
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 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
|
2725 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
|
2726 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2727 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2728 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2729 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
|
2730 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
|
2731 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2732 $optgroup = $($optgroup); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2733 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
|
2734 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2735 if (id) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2736 optgroup = readData($optgroup) || {}; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2737 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
|
2738 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
|
2739 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
|
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 $options = $('option', $optgroup); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2743 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
|
2744 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
|
2745 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2746 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2747 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2748 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
|
2749 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2750 $children = $input.children(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2751 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
|
2752 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
|
2753 if (tagName === 'optgroup') { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2754 addGroup($children[i]); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2755 } 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
|
2756 addOption($children[i]); |
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 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2761 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
|
2762 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
|
2763 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2764 var instance; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2765 var $input = $(this); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2766 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
|
2767 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
|
2768 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
|
2769 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
|
2770 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2771 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2772 var settings_element = { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2773 'placeholder' : placeholder, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2774 'options' : [], |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2775 'optgroups' : [], |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2776 'items' : [] |
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 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
|
2780 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
|
2781 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2782 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
|
2783 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2784 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2785 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
|
2786 }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2787 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2788 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2789 $.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
|
2790 $.fn.selectize.support = { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2791 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
|
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 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
|
2796 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
|
2797 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
|
2798 var self = this; |
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 self.lock = (function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2801 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
|
2802 return function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2803 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
|
2804 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
|
2805 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
|
2806 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2807 })(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2808 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2809 self.unlock = (function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2810 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
|
2811 return function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2812 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
|
2813 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
|
2814 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
|
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 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2818 self.setup = (function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2819 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
|
2820 return function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2821 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
|
2822 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2823 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
|
2824 items: '[data-value]', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2825 forcePlaceholderSize: true, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2826 disabled: self.isLocked, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2827 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
|
2828 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
|
2829 $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
|
2830 }, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2831 stop: function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2832 $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
|
2833 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
|
2834 var values = []; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2835 $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
|
2836 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
|
2837 }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2838 self.setValue(values); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2839 self.setActiveItem(active); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2840 } |
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 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2843 })(); |
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 }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2846 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2847 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
|
2848 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2849 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2850 options = $.extend({ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2851 title : 'Untitled', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2852 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
|
2853 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
|
2854 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
|
2855 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
|
2856 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2857 html: function(data) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2858 return ( |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2859 '<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
|
2860 '<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
|
2861 '<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
|
2862 '<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
|
2863 '</div>' + |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2864 '</div>' |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2865 ); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2866 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2867 }, options); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2868 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2869 self.setup = (function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2870 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
|
2871 return function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2872 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
|
2873 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
|
2874 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
|
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 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2878 }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2879 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2880 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
|
2881 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2882 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2883 options = $.extend({ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2884 equalizeWidth : true, |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2885 equalizeHeight : true |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2886 }, options); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2887 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2888 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
|
2889 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
|
2890 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
|
2891 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2892 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
|
2893 }; |
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 this.onKeyDown = (function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2896 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
|
2897 return function(e) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2898 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
|
2899 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2900 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
|
2901 self.ignoreHover = true; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2902 $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
|
2903 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
|
2904 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2905 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
|
2906 $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
|
2907 } else { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2908 $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
|
2909 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2910 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2911 $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
|
2912 $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
|
2913 if ($option.length) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2914 this.setActiveOption($option); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2915 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2916 return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2917 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2918 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2919 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
|
2920 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2921 })(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2922 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2923 var getScrollbarWidth = function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2924 var div; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2925 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
|
2926 var doc = document; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2927 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2928 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
|
2929 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
|
2930 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
|
2931 div = div.firstChild; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2932 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
|
2933 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
|
2934 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
|
2935 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2936 return width; |
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 var equalizeSizes = function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2940 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
|
2941 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2942 $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
|
2943 n = $optgroups.length; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2944 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
|
2945 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2946 if (options.equalizeHeight) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2947 height_max = 0; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2948 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
|
2949 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
|
2950 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2951 $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
|
2952 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2953 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2954 if (options.equalizeWidth) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2955 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
|
2956 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
|
2957 $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
|
2958 if (n > 1) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2959 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
|
2960 $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
|
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 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2965 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
|
2966 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
|
2967 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
|
2968 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2969 |
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 }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2972 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2973 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
|
2974 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
|
2975 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2976 options = $.extend({ |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2977 label : '×', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2978 title : 'Remove', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2979 className : 'remove', |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2980 append : true |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2981 }, options); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2982 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2983 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2984 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
|
2985 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2986 /** |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2987 * 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
|
2988 * |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2989 * @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
|
2990 * @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
|
2991 * @return {string} |
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 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
|
2994 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
|
2995 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
|
2996 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2997 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2998 this.setup = (function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
2999 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
|
3000 return function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3001 // 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
|
3002 if (options.append) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3003 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
|
3004 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
|
3005 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
|
3006 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3007 } |
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 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
|
3010 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3011 // add event listener |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3012 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
|
3013 e.preventDefault(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3014 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
|
3015 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3016 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
|
3017 self.setActiveItem($item); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3018 if (self.deleteSelection()) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3019 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
|
3020 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3021 }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3022 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3023 }; |
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 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3028 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
|
3029 var self = this; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3030 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3031 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
|
3032 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
|
3033 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3034 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3035 this.onKeyDown = (function() { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3036 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
|
3037 return function(e) { |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3038 var index, option; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3039 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
|
3040 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
|
3041 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
|
3042 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
|
3043 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
|
3044 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
|
3045 this.refreshOptions(true); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3046 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3047 e.preventDefault(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3048 return; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3049 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3050 } |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3051 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
|
3052 }; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3053 })(); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3054 }); |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3055 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3056 |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3057 return Selectize; |
22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
arussell
parents:
diff
changeset
|
3058 })); |