Mercurial > hg > NetworkVis
annotate query_builder/bootstrap/bootstrap-slider/js/bootstrap-slider.js @ 25:f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
author | alistair |
---|---|
date | Mon, 23 Nov 2015 02:03:51 -0500 |
parents | |
children |
rev | line source |
---|---|
25
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1 /*! ========================================================= |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
2 * bootstrap-slider.js |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
3 * |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
4 * Maintainers: |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
5 * Kyle Kemp |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
6 * - Twitter: @seiyria |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
7 * - Github: seiyria |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
8 * Rohit Kalkur |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
9 * - Twitter: @Rovolutionary |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
10 * - Github: rovolution |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
11 * |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
12 * ========================================================= |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
13 * |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
14 * Licensed under the Apache License, Version 2.0 (the "License"); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
15 * you may not use this file except in compliance with the License. |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
16 * You may obtain a copy of the License at |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
17 * |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
18 * http://www.apache.org/licenses/LICENSE-2.0 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
19 * |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
20 * Unless required by applicable law or agreed to in writing, software |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
21 * distributed under the License is distributed on an "AS IS" BASIS, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
22 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
23 * See the License for the specific language governing permissions and |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
24 * limitations under the License. |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
25 * ========================================================= */ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
26 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
27 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
28 /** |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
29 * Bridget makes jQuery widgets |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
30 * v1.0.1 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
31 * MIT license |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
32 */ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
33 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
34 (function(root, factory) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
35 if(typeof define === "function" && define.amd) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
36 define(["jquery"], factory); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
37 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
38 else if(typeof module === "object" && module.exports) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
39 var jQuery; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
40 try { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
41 jQuery = require("jquery"); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
42 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
43 catch (err) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
44 jQuery = null; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
45 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
46 module.exports = factory(jQuery); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
47 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
48 else { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
49 root.Slider = factory(root.jQuery); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
50 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
51 }(this, function($) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
52 // Reference to Slider constructor |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
53 var Slider; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
54 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
55 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
56 (function( $ ) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
57 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
58 'use strict'; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
59 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
60 // -------------------------- utils -------------------------- // |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
61 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
62 var slice = Array.prototype.slice; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
63 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
64 function noop() {} |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
65 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
66 // -------------------------- definition -------------------------- // |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
67 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
68 function defineBridget( $ ) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
69 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
70 // bail if no jQuery |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
71 if ( !$ ) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
72 return; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
73 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
74 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
75 // -------------------------- addOptionMethod -------------------------- // |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
76 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
77 /** |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
78 * adds option method -> $().plugin('option', {...}) |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
79 * @param {Function} PluginClass - constructor class |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
80 */ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
81 function addOptionMethod( PluginClass ) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
82 // don't overwrite original option method |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
83 if ( PluginClass.prototype.option ) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
84 return; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
85 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
86 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
87 // option setter |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
88 PluginClass.prototype.option = function( opts ) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
89 // bail out if not an object |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
90 if ( !$.isPlainObject( opts ) ){ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
91 return; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
92 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
93 this.options = $.extend( true, this.options, opts ); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
94 }; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
95 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
96 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
97 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
98 // -------------------------- plugin bridge -------------------------- // |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
99 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
100 // helper function for logging errors |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
101 // $.error breaks jQuery chaining |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
102 var logError = typeof console === 'undefined' ? noop : |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
103 function( message ) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
104 console.error( message ); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
105 }; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
106 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
107 /** |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
108 * jQuery plugin bridge, access methods like $elem.plugin('method') |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
109 * @param {String} namespace - plugin name |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
110 * @param {Function} PluginClass - constructor class |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
111 */ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
112 function bridge( namespace, PluginClass ) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
113 // add to jQuery fn namespace |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
114 $.fn[ namespace ] = function( options ) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
115 if ( typeof options === 'string' ) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
116 // call plugin method when first argument is a string |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
117 // get arguments for method |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
118 var args = slice.call( arguments, 1 ); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
119 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
120 for ( var i=0, len = this.length; i < len; i++ ) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
121 var elem = this[i]; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
122 var instance = $.data( elem, namespace ); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
123 if ( !instance ) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
124 logError( "cannot call methods on " + namespace + " prior to initialization; " + |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
125 "attempted to call '" + options + "'" ); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
126 continue; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
127 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
128 if ( !$.isFunction( instance[options] ) || options.charAt(0) === '_' ) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
129 logError( "no such method '" + options + "' for " + namespace + " instance" ); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
130 continue; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
131 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
132 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
133 // trigger method with arguments |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
134 var returnValue = instance[ options ].apply( instance, args); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
135 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
136 // break look and return first value if provided |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
137 if ( returnValue !== undefined && returnValue !== instance) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
138 return returnValue; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
139 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
140 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
141 // return this if no return value |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
142 return this; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
143 } else { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
144 var objects = this.map( function() { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
145 var instance = $.data( this, namespace ); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
146 if ( instance ) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
147 // apply options & init |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
148 instance.option( options ); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
149 instance._init(); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
150 } else { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
151 // initialize new instance |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
152 instance = new PluginClass( this, options ); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
153 $.data( this, namespace, instance ); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
154 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
155 return $(this); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
156 }); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
157 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
158 if(!objects || objects.length > 1) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
159 return objects; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
160 } else { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
161 return objects[0]; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
162 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
163 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
164 }; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
165 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
166 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
167 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
168 // -------------------------- bridget -------------------------- // |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
169 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
170 /** |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
171 * converts a Prototypical class into a proper jQuery plugin |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
172 * the class must have a ._init method |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
173 * @param {String} namespace - plugin name, used in $().pluginName |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
174 * @param {Function} PluginClass - constructor class |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
175 */ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
176 $.bridget = function( namespace, PluginClass ) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
177 addOptionMethod( PluginClass ); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
178 bridge( namespace, PluginClass ); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
179 }; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
180 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
181 return $.bridget; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
182 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
183 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
184 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
185 // get jquery from browser global |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
186 defineBridget( $ ); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
187 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
188 })( $ ); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
189 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
190 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
191 /************************************************* |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
192 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
193 BOOTSTRAP-SLIDER SOURCE CODE |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
194 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
195 **************************************************/ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
196 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
197 (function($) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
198 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
199 var ErrorMsgs = { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
200 formatInvalidInputErrorMsg : function(input) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
201 return "Invalid input value '" + input + "' passed in"; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
202 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
203 callingContextNotSliderInstance : "Calling context element does not have instance of Slider bound to it. Check your code to make sure the JQuery object returned from the call to the slider() initializer is calling the method" |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
204 }; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
205 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
206 var SliderScale = { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
207 linear: { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
208 toValue: function(percentage) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
209 var rawValue = percentage/100 * (this.options.max - this.options.min); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
210 if (this.options.ticks_positions.length > 0) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
211 var minv, maxv, minp, maxp = 0; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
212 for (var i = 0; i < this.options.ticks_positions.length; i++) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
213 if (percentage <= this.options.ticks_positions[i]) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
214 minv = (i > 0) ? this.options.ticks[i-1] : 0; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
215 minp = (i > 0) ? this.options.ticks_positions[i-1] : 0; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
216 maxv = this.options.ticks[i]; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
217 maxp = this.options.ticks_positions[i]; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
218 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
219 break; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
220 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
221 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
222 if (i > 0) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
223 var partialPercentage = (percentage - minp) / (maxp - minp); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
224 rawValue = minv + partialPercentage * (maxv - minv); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
225 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
226 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
227 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
228 var value = this.options.min + Math.round(rawValue / this.options.step) * this.options.step; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
229 if (value < this.options.min) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
230 return this.options.min; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
231 } else if (value > this.options.max) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
232 return this.options.max; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
233 } else { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
234 return value; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
235 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
236 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
237 toPercentage: function(value) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
238 if (this.options.max === this.options.min) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
239 return 0; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
240 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
241 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
242 if (this.options.ticks_positions.length > 0) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
243 var minv, maxv, minp, maxp = 0; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
244 for (var i = 0; i < this.options.ticks.length; i++) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
245 if (value <= this.options.ticks[i]) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
246 minv = (i > 0) ? this.options.ticks[i-1] : 0; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
247 minp = (i > 0) ? this.options.ticks_positions[i-1] : 0; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
248 maxv = this.options.ticks[i]; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
249 maxp = this.options.ticks_positions[i]; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
250 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
251 break; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
252 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
253 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
254 if (i > 0) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
255 var partialPercentage = (value - minv) / (maxv - minv); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
256 return minp + partialPercentage * (maxp - minp); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
257 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
258 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
259 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
260 return 100 * (value - this.options.min) / (this.options.max - this.options.min); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
261 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
262 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
263 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
264 logarithmic: { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
265 /* Based on http://stackoverflow.com/questions/846221/logarithmic-slider */ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
266 toValue: function(percentage) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
267 var min = (this.options.min === 0) ? 0 : Math.log(this.options.min); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
268 var max = Math.log(this.options.max); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
269 var value = Math.exp(min + (max - min) * percentage / 100); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
270 value = this.options.min + Math.round((value - this.options.min) / this.options.step) * this.options.step; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
271 /* Rounding to the nearest step could exceed the min or |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
272 * max, so clip to those values. */ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
273 if (value < this.options.min) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
274 return this.options.min; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
275 } else if (value > this.options.max) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
276 return this.options.max; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
277 } else { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
278 return value; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
279 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
280 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
281 toPercentage: function(value) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
282 if (this.options.max === this.options.min) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
283 return 0; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
284 } else { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
285 var max = Math.log(this.options.max); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
286 var min = this.options.min === 0 ? 0 : Math.log(this.options.min); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
287 var v = value === 0 ? 0 : Math.log(value); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
288 return 100 * (v - min) / (max - min); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
289 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
290 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
291 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
292 }; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
293 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
294 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
295 /************************************************* |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
296 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
297 CONSTRUCTOR |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
298 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
299 **************************************************/ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
300 Slider = function(element, options) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
301 createNewSlider.call(this, element, options); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
302 return this; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
303 }; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
304 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
305 function createNewSlider(element, options) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
306 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
307 /* |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
308 The internal state object is used to store data about the current 'state' of slider. |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
309 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
310 This includes values such as the `value`, `enabled`, etc... |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
311 */ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
312 this._state = { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
313 value: null, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
314 enabled: null, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
315 offset: null, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
316 size: null, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
317 percentage: null, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
318 inDrag: false, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
319 over: false |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
320 }; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
321 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
322 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
323 if(typeof element === "string") { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
324 this.element = document.querySelector(element); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
325 } else if(element instanceof HTMLElement) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
326 this.element = element; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
327 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
328 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
329 /************************************************* |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
330 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
331 Process Options |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
332 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
333 **************************************************/ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
334 options = options ? options : {}; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
335 var optionTypes = Object.keys(this.defaultOptions); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
336 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
337 for(var i = 0; i < optionTypes.length; i++) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
338 var optName = optionTypes[i]; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
339 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
340 // First check if an option was passed in via the constructor |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
341 var val = options[optName]; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
342 // If no data attrib, then check data atrributes |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
343 val = (typeof val !== 'undefined') ? val : getDataAttrib(this.element, optName); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
344 // Finally, if nothing was specified, use the defaults |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
345 val = (val !== null) ? val : this.defaultOptions[optName]; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
346 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
347 // Set all options on the instance of the Slider |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
348 if(!this.options) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
349 this.options = {}; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
350 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
351 this.options[optName] = val; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
352 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
353 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
354 /* |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
355 Validate `tooltip_position` against 'orientation` |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
356 - if `tooltip_position` is incompatible with orientation, swith it to a default compatible with specified `orientation` |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
357 -- default for "vertical" -> "right" |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
358 -- default for "horizontal" -> "left" |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
359 */ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
360 if(this.options.orientation === "vertical" && (this.options.tooltip_position === "top" || this.options.tooltip_position === "bottom")) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
361 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
362 this.options.tooltip_position = "right"; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
363 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
364 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
365 else if(this.options.orientation === "horizontal" && (this.options.tooltip_position === "left" || this.options.tooltip_position === "right")) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
366 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
367 this.options.tooltip_position = "top"; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
368 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
369 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
370 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
371 function getDataAttrib(element, optName) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
372 var dataName = "data-slider-" + optName.replace(/_/g, '-'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
373 var dataValString = element.getAttribute(dataName); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
374 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
375 try { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
376 return JSON.parse(dataValString); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
377 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
378 catch(err) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
379 return dataValString; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
380 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
381 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
382 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
383 /************************************************* |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
384 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
385 Create Markup |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
386 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
387 **************************************************/ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
388 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
389 var origWidth = this.element.style.width; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
390 var updateSlider = false; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
391 var parent = this.element.parentNode; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
392 var sliderTrackSelection; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
393 var sliderTrackLow, sliderTrackHigh; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
394 var sliderMinHandle; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
395 var sliderMaxHandle; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
396 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
397 if (this.sliderElem) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
398 updateSlider = true; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
399 } else { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
400 /* Create elements needed for slider */ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
401 this.sliderElem = document.createElement("div"); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
402 this.sliderElem.className = "slider"; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
403 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
404 /* Create slider track elements */ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
405 var sliderTrack = document.createElement("div"); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
406 sliderTrack.className = "slider-track"; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
407 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
408 sliderTrackLow = document.createElement("div"); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
409 sliderTrackLow.className = "slider-track-low"; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
410 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
411 sliderTrackSelection = document.createElement("div"); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
412 sliderTrackSelection.className = "slider-selection"; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
413 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
414 sliderTrackHigh = document.createElement("div"); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
415 sliderTrackHigh.className = "slider-track-high"; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
416 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
417 sliderMinHandle = document.createElement("div"); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
418 sliderMinHandle.className = "slider-handle min-slider-handle"; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
419 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
420 sliderMaxHandle = document.createElement("div"); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
421 sliderMaxHandle.className = "slider-handle max-slider-handle"; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
422 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
423 sliderTrack.appendChild(sliderTrackLow); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
424 sliderTrack.appendChild(sliderTrackSelection); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
425 sliderTrack.appendChild(sliderTrackHigh); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
426 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
427 /* Create ticks */ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
428 this.ticks = []; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
429 if (Array.isArray(this.options.ticks) && this.options.ticks.length > 0) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
430 for (i = 0; i < this.options.ticks.length; i++) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
431 var tick = document.createElement('div'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
432 tick.className = 'slider-tick'; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
433 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
434 this.ticks.push(tick); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
435 sliderTrack.appendChild(tick); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
436 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
437 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
438 sliderTrackSelection.className += " tick-slider-selection"; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
439 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
440 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
441 sliderTrack.appendChild(sliderMinHandle); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
442 sliderTrack.appendChild(sliderMaxHandle); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
443 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
444 this.tickLabels = []; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
445 if (Array.isArray(this.options.ticks_labels) && this.options.ticks_labels.length > 0) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
446 this.tickLabelContainer = document.createElement('div'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
447 this.tickLabelContainer.className = 'slider-tick-label-container'; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
448 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
449 for (i = 0; i < this.options.ticks_labels.length; i++) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
450 var label = document.createElement('div'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
451 var noTickPositionsSpecified = this.options.ticks_positions.length === 0; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
452 var tickLabelsIndex = (this.options.reversed && noTickPositionsSpecified) ? (this.options.ticks_labels.length - (i + 1)) : i; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
453 label.className = 'slider-tick-label'; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
454 label.innerHTML = this.options.ticks_labels[tickLabelsIndex]; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
455 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
456 this.tickLabels.push(label); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
457 this.tickLabelContainer.appendChild(label); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
458 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
459 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
460 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
461 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
462 var createAndAppendTooltipSubElements = function(tooltipElem) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
463 var arrow = document.createElement("div"); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
464 arrow.className = "tooltip-arrow"; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
465 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
466 var inner = document.createElement("div"); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
467 inner.className = "tooltip-inner"; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
468 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
469 tooltipElem.appendChild(arrow); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
470 tooltipElem.appendChild(inner); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
471 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
472 }; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
473 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
474 /* Create tooltip elements */ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
475 var sliderTooltip = document.createElement("div"); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
476 sliderTooltip.className = "tooltip tooltip-main"; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
477 createAndAppendTooltipSubElements(sliderTooltip); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
478 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
479 var sliderTooltipMin = document.createElement("div"); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
480 sliderTooltipMin.className = "tooltip tooltip-min"; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
481 createAndAppendTooltipSubElements(sliderTooltipMin); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
482 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
483 var sliderTooltipMax = document.createElement("div"); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
484 sliderTooltipMax.className = "tooltip tooltip-max"; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
485 createAndAppendTooltipSubElements(sliderTooltipMax); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
486 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
487 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
488 /* Append components to sliderElem */ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
489 this.sliderElem.appendChild(sliderTrack); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
490 this.sliderElem.appendChild(sliderTooltip); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
491 this.sliderElem.appendChild(sliderTooltipMin); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
492 this.sliderElem.appendChild(sliderTooltipMax); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
493 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
494 if (this.tickLabelContainer) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
495 this.sliderElem.appendChild(this.tickLabelContainer); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
496 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
497 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
498 /* Append slider element to parent container, right before the original <input> element */ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
499 parent.insertBefore(this.sliderElem, this.element); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
500 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
501 /* Hide original <input> element */ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
502 this.element.style.display = "none"; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
503 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
504 /* If JQuery exists, cache JQ references */ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
505 if($) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
506 this.$element = $(this.element); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
507 this.$sliderElem = $(this.sliderElem); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
508 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
509 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
510 /************************************************* |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
511 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
512 Setup |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
513 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
514 **************************************************/ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
515 this.eventToCallbackMap = {}; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
516 this.sliderElem.id = this.options.id; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
517 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
518 this.touchCapable = 'ontouchstart' in window || (window.DocumentTouch && document instanceof window.DocumentTouch); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
519 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
520 this.tooltip = this.sliderElem.querySelector('.tooltip-main'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
521 this.tooltipInner = this.tooltip.querySelector('.tooltip-inner'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
522 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
523 this.tooltip_min = this.sliderElem.querySelector('.tooltip-min'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
524 this.tooltipInner_min = this.tooltip_min.querySelector('.tooltip-inner'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
525 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
526 this.tooltip_max = this.sliderElem.querySelector('.tooltip-max'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
527 this.tooltipInner_max= this.tooltip_max.querySelector('.tooltip-inner'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
528 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
529 if (SliderScale[this.options.scale]) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
530 this.options.scale = SliderScale[this.options.scale]; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
531 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
532 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
533 if (updateSlider === true) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
534 // Reset classes |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
535 this._removeClass(this.sliderElem, 'slider-horizontal'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
536 this._removeClass(this.sliderElem, 'slider-vertical'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
537 this._removeClass(this.tooltip, 'hide'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
538 this._removeClass(this.tooltip_min, 'hide'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
539 this._removeClass(this.tooltip_max, 'hide'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
540 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
541 // Undo existing inline styles for track |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
542 ["left", "top", "width", "height"].forEach(function(prop) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
543 this._removeProperty(this.trackLow, prop); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
544 this._removeProperty(this.trackSelection, prop); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
545 this._removeProperty(this.trackHigh, prop); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
546 }, this); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
547 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
548 // Undo inline styles on handles |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
549 [this.handle1, this.handle2].forEach(function(handle) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
550 this._removeProperty(handle, 'left'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
551 this._removeProperty(handle, 'top'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
552 }, this); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
553 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
554 // Undo inline styles and classes on tooltips |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
555 [this.tooltip, this.tooltip_min, this.tooltip_max].forEach(function(tooltip) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
556 this._removeProperty(tooltip, 'left'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
557 this._removeProperty(tooltip, 'top'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
558 this._removeProperty(tooltip, 'margin-left'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
559 this._removeProperty(tooltip, 'margin-top'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
560 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
561 this._removeClass(tooltip, 'right'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
562 this._removeClass(tooltip, 'top'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
563 }, this); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
564 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
565 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
566 if(this.options.orientation === 'vertical') { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
567 this._addClass(this.sliderElem,'slider-vertical'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
568 this.stylePos = 'top'; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
569 this.mousePos = 'pageY'; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
570 this.sizePos = 'offsetHeight'; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
571 } else { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
572 this._addClass(this.sliderElem, 'slider-horizontal'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
573 this.sliderElem.style.width = origWidth; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
574 this.options.orientation = 'horizontal'; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
575 this.stylePos = 'left'; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
576 this.mousePos = 'pageX'; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
577 this.sizePos = 'offsetWidth'; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
578 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
579 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
580 this._setTooltipPosition(); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
581 /* In case ticks are specified, overwrite the min and max bounds */ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
582 if (Array.isArray(this.options.ticks) && this.options.ticks.length > 0) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
583 this.options.max = Math.max.apply(Math, this.options.ticks); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
584 this.options.min = Math.min.apply(Math, this.options.ticks); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
585 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
586 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
587 if (Array.isArray(this.options.value)) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
588 this.options.range = true; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
589 this._state.value = this.options.value; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
590 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
591 else if (this.options.range) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
592 // User wants a range, but value is not an array |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
593 this._state.value = [this.options.value, this.options.max]; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
594 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
595 else { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
596 this._state.value = this.options.value; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
597 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
598 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
599 this.trackLow = sliderTrackLow || this.trackLow; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
600 this.trackSelection = sliderTrackSelection || this.trackSelection; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
601 this.trackHigh = sliderTrackHigh || this.trackHigh; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
602 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
603 if (this.options.selection === 'none') { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
604 this._addClass(this.trackLow, 'hide'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
605 this._addClass(this.trackSelection, 'hide'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
606 this._addClass(this.trackHigh, 'hide'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
607 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
608 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
609 this.handle1 = sliderMinHandle || this.handle1; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
610 this.handle2 = sliderMaxHandle || this.handle2; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
611 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
612 if (updateSlider === true) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
613 // Reset classes |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
614 this._removeClass(this.handle1, 'round triangle'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
615 this._removeClass(this.handle2, 'round triangle hide'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
616 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
617 for (i = 0; i < this.ticks.length; i++) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
618 this._removeClass(this.ticks[i], 'round triangle hide'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
619 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
620 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
621 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
622 var availableHandleModifiers = ['round', 'triangle', 'custom']; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
623 var isValidHandleType = availableHandleModifiers.indexOf(this.options.handle) !== -1; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
624 if (isValidHandleType) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
625 this._addClass(this.handle1, this.options.handle); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
626 this._addClass(this.handle2, this.options.handle); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
627 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
628 for (i = 0; i < this.ticks.length; i++) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
629 this._addClass(this.ticks[i], this.options.handle); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
630 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
631 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
632 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
633 this._state.offset = this._offset(this.sliderElem); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
634 this._state.size = this.sliderElem[this.sizePos]; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
635 this.setValue(this._state.value); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
636 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
637 /****************************************** |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
638 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
639 Bind Event Listeners |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
640 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
641 ******************************************/ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
642 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
643 // Bind keyboard handlers |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
644 this.handle1Keydown = this._keydown.bind(this, 0); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
645 this.handle1.addEventListener("keydown", this.handle1Keydown, false); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
646 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
647 this.handle2Keydown = this._keydown.bind(this, 1); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
648 this.handle2.addEventListener("keydown", this.handle2Keydown, false); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
649 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
650 this.mousedown = this._mousedown.bind(this); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
651 if (this.touchCapable) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
652 // Bind touch handlers |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
653 this.sliderElem.addEventListener("touchstart", this.mousedown, false); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
654 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
655 this.sliderElem.addEventListener("mousedown", this.mousedown, false); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
656 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
657 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
658 // Bind tooltip-related handlers |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
659 if(this.options.tooltip === 'hide') { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
660 this._addClass(this.tooltip, 'hide'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
661 this._addClass(this.tooltip_min, 'hide'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
662 this._addClass(this.tooltip_max, 'hide'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
663 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
664 else if(this.options.tooltip === 'always') { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
665 this._showTooltip(); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
666 this._alwaysShowTooltip = true; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
667 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
668 else { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
669 this.showTooltip = this._showTooltip.bind(this); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
670 this.hideTooltip = this._hideTooltip.bind(this); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
671 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
672 this.sliderElem.addEventListener("mouseenter", this.showTooltip, false); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
673 this.sliderElem.addEventListener("mouseleave", this.hideTooltip, false); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
674 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
675 this.handle1.addEventListener("focus", this.showTooltip, false); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
676 this.handle1.addEventListener("blur", this.hideTooltip, false); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
677 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
678 this.handle2.addEventListener("focus", this.showTooltip, false); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
679 this.handle2.addEventListener("blur", this.hideTooltip, false); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
680 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
681 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
682 if(this.options.enabled) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
683 this.enable(); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
684 } else { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
685 this.disable(); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
686 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
687 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
688 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
689 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
690 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
691 /************************************************* |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
692 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
693 INSTANCE PROPERTIES/METHODS |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
694 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
695 - Any methods bound to the prototype are considered |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
696 part of the plugin's `public` interface |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
697 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
698 **************************************************/ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
699 Slider.prototype = { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
700 _init: function() {}, // NOTE: Must exist to support bridget |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
701 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
702 constructor: Slider, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
703 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
704 defaultOptions: { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
705 id: "", |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
706 min: 0, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
707 max: 10, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
708 step: 1, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
709 precision: 0, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
710 orientation: 'horizontal', |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
711 value: 5, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
712 range: false, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
713 selection: 'before', |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
714 tooltip: 'show', |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
715 tooltip_split: false, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
716 handle: 'round', |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
717 reversed: false, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
718 enabled: true, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
719 formatter: function(val) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
720 if (Array.isArray(val)) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
721 return val[0] + " : " + val[1]; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
722 } else { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
723 return val; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
724 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
725 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
726 natural_arrow_keys: false, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
727 ticks: [], |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
728 ticks_positions: [], |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
729 ticks_labels: [], |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
730 ticks_snap_bounds: 0, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
731 scale: 'linear', |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
732 focus: false, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
733 tooltip_position: null |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
734 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
735 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
736 getElement: function() { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
737 return this.sliderElem; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
738 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
739 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
740 getValue: function() { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
741 if (this.options.range) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
742 return this._state.value; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
743 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
744 else { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
745 return this._state.value[0]; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
746 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
747 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
748 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
749 setValue: function(val, triggerSlideEvent, triggerChangeEvent) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
750 if (!val) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
751 val = 0; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
752 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
753 var oldValue = this.getValue(); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
754 this._state.value = this._validateInputValue(val); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
755 var applyPrecision = this._applyPrecision.bind(this); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
756 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
757 if (this.options.range) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
758 this._state.value[0] = applyPrecision(this._state.value[0]); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
759 this._state.value[1] = applyPrecision(this._state.value[1]); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
760 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
761 this._state.value[0] = Math.max(this.options.min, Math.min(this.options.max, this._state.value[0])); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
762 this._state.value[1] = Math.max(this.options.min, Math.min(this.options.max, this._state.value[1])); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
763 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
764 else { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
765 this._state.value = applyPrecision(this._state.value); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
766 this._state.value = [ Math.max(this.options.min, Math.min(this.options.max, this._state.value))]; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
767 this._addClass(this.handle2, 'hide'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
768 if (this.options.selection === 'after') { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
769 this._state.value[1] = this.options.max; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
770 } else { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
771 this._state.value[1] = this.options.min; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
772 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
773 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
774 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
775 if (this.options.max > this.options.min) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
776 this._state.percentage = [ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
777 this._toPercentage(this._state.value[0]), |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
778 this._toPercentage(this._state.value[1]), |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
779 this.options.step * 100 / (this.options.max - this.options.min) |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
780 ]; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
781 } else { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
782 this._state.percentage = [0, 0, 100]; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
783 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
784 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
785 this._layout(); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
786 var newValue = this.options.range ? this._state.value : this._state.value[0]; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
787 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
788 if(triggerSlideEvent === true) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
789 this._trigger('slide', newValue); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
790 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
791 if( (oldValue !== newValue) && (triggerChangeEvent === true) ) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
792 this._trigger('change', { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
793 oldValue: oldValue, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
794 newValue: newValue |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
795 }); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
796 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
797 this._setDataVal(newValue); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
798 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
799 return this; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
800 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
801 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
802 destroy: function(){ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
803 // Remove event handlers on slider elements |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
804 this._removeSliderEventHandlers(); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
805 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
806 // Remove the slider from the DOM |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
807 this.sliderElem.parentNode.removeChild(this.sliderElem); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
808 /* Show original <input> element */ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
809 this.element.style.display = ""; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
810 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
811 // Clear out custom event bindings |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
812 this._cleanUpEventCallbacksMap(); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
813 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
814 // Remove data values |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
815 this.element.removeAttribute("data"); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
816 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
817 // Remove JQuery handlers/data |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
818 if($) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
819 this._unbindJQueryEventHandlers(); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
820 this.$element.removeData('slider'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
821 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
822 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
823 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
824 disable: function() { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
825 this._state.enabled = false; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
826 this.handle1.removeAttribute("tabindex"); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
827 this.handle2.removeAttribute("tabindex"); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
828 this._addClass(this.sliderElem, 'slider-disabled'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
829 this._trigger('slideDisabled'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
830 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
831 return this; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
832 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
833 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
834 enable: function() { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
835 this._state.enabled = true; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
836 this.handle1.setAttribute("tabindex", 0); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
837 this.handle2.setAttribute("tabindex", 0); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
838 this._removeClass(this.sliderElem, 'slider-disabled'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
839 this._trigger('slideEnabled'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
840 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
841 return this; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
842 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
843 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
844 toggle: function() { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
845 if(this._state.enabled) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
846 this.disable(); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
847 } else { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
848 this.enable(); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
849 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
850 return this; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
851 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
852 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
853 isEnabled: function() { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
854 return this._state.enabled; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
855 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
856 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
857 on: function(evt, callback) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
858 this._bindNonQueryEventHandler(evt, callback); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
859 return this; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
860 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
861 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
862 off: function(evt, callback) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
863 if($) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
864 this.$element.off(evt, callback); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
865 this.$sliderElem.off(evt, callback); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
866 } else { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
867 this._unbindNonQueryEventHandler(evt, callback); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
868 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
869 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
870 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
871 getAttribute: function(attribute) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
872 if(attribute) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
873 return this.options[attribute]; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
874 } else { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
875 return this.options; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
876 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
877 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
878 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
879 setAttribute: function(attribute, value) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
880 this.options[attribute] = value; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
881 return this; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
882 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
883 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
884 refresh: function() { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
885 this._removeSliderEventHandlers(); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
886 createNewSlider.call(this, this.element, this.options); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
887 if($) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
888 // Bind new instance of slider to the element |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
889 $.data(this.element, 'slider', this); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
890 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
891 return this; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
892 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
893 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
894 relayout: function() { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
895 this._layout(); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
896 return this; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
897 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
898 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
899 /******************************+ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
900 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
901 HELPERS |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
902 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
903 - Any method that is not part of the public interface. |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
904 - Place it underneath this comment block and write its signature like so: |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
905 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
906 _fnName : function() {...} |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
907 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
908 ********************************/ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
909 _removeSliderEventHandlers: function() { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
910 // Remove keydown event listeners |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
911 this.handle1.removeEventListener("keydown", this.handle1Keydown, false); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
912 this.handle2.removeEventListener("keydown", this.handle2Keydown, false); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
913 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
914 if (this.showTooltip) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
915 this.handle1.removeEventListener("focus", this.showTooltip, false); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
916 this.handle2.removeEventListener("focus", this.showTooltip, false); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
917 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
918 if (this.hideTooltip) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
919 this.handle1.removeEventListener("blur", this.hideTooltip, false); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
920 this.handle2.removeEventListener("blur", this.hideTooltip, false); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
921 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
922 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
923 // Remove event listeners from sliderElem |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
924 if (this.showTooltip) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
925 this.sliderElem.removeEventListener("mouseenter", this.showTooltip, false); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
926 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
927 if (this.hideTooltip) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
928 this.sliderElem.removeEventListener("mouseleave", this.hideTooltip, false); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
929 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
930 this.sliderElem.removeEventListener("touchstart", this.mousedown, false); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
931 this.sliderElem.removeEventListener("mousedown", this.mousedown, false); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
932 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
933 _bindNonQueryEventHandler: function(evt, callback) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
934 if(this.eventToCallbackMap[evt] === undefined) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
935 this.eventToCallbackMap[evt] = []; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
936 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
937 this.eventToCallbackMap[evt].push(callback); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
938 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
939 _unbindNonQueryEventHandler: function(evt, callback) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
940 var callbacks = this.eventToCallbackMap[evt]; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
941 if(callbacks !== undefined) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
942 for (var i = 0; i < callbacks.length; i++) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
943 if (callbacks[i] === callback) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
944 callbacks.splice(i, 1); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
945 break; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
946 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
947 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
948 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
949 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
950 _cleanUpEventCallbacksMap: function() { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
951 var eventNames = Object.keys(this.eventToCallbackMap); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
952 for(var i = 0; i < eventNames.length; i++) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
953 var eventName = eventNames[i]; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
954 this.eventToCallbackMap[eventName] = null; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
955 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
956 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
957 _showTooltip: function() { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
958 if (this.options.tooltip_split === false ){ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
959 this._addClass(this.tooltip, 'in'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
960 this.tooltip_min.style.display = 'none'; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
961 this.tooltip_max.style.display = 'none'; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
962 } else { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
963 this._addClass(this.tooltip_min, 'in'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
964 this._addClass(this.tooltip_max, 'in'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
965 this.tooltip.style.display = 'none'; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
966 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
967 this._state.over = true; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
968 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
969 _hideTooltip: function() { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
970 if (this._state.inDrag === false && this.alwaysShowTooltip !== true) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
971 this._removeClass(this.tooltip, 'in'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
972 this._removeClass(this.tooltip_min, 'in'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
973 this._removeClass(this.tooltip_max, 'in'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
974 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
975 this._state.over = false; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
976 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
977 _layout: function() { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
978 var positionPercentages; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
979 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
980 if(this.options.reversed) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
981 positionPercentages = [ 100 - this._state.percentage[0], this.options.range ? 100 - this._state.percentage[1] : this._state.percentage[1]]; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
982 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
983 else { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
984 positionPercentages = [ this._state.percentage[0], this._state.percentage[1] ]; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
985 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
986 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
987 this.handle1.style[this.stylePos] = positionPercentages[0]+'%'; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
988 this.handle2.style[this.stylePos] = positionPercentages[1]+'%'; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
989 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
990 /* Position ticks and labels */ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
991 if (Array.isArray(this.options.ticks) && this.options.ticks.length > 0) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
992 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
993 var styleSize = this.options.orientation === 'vertical' ? 'height' : 'width'; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
994 var styleMargin = this.options.orientation === 'vertical' ? 'marginTop' : 'marginLeft'; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
995 var labelSize = this._state.size / (this.options.ticks.length - 1); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
996 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
997 if (this.tickLabelContainer) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
998 var extraMargin = 0; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
999 if (this.options.ticks_positions.length === 0) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1000 if (this.options.orientation !== 'vertical') { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1001 this.tickLabelContainer.style[styleMargin] = -labelSize/2 + 'px'; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1002 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1003 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1004 extraMargin = this.tickLabelContainer.offsetHeight; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1005 } else { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1006 /* Chidren are position absolute, calculate height by finding the max offsetHeight of a child */ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1007 for (i = 0 ; i < this.tickLabelContainer.childNodes.length; i++) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1008 if (this.tickLabelContainer.childNodes[i].offsetHeight > extraMargin) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1009 extraMargin = this.tickLabelContainer.childNodes[i].offsetHeight; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1010 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1011 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1012 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1013 if (this.options.orientation === 'horizontal') { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1014 this.sliderElem.style.marginBottom = extraMargin + 'px'; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1015 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1016 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1017 for (var i = 0; i < this.options.ticks.length; i++) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1018 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1019 var percentage = this.options.ticks_positions[i] || this._toPercentage(this.options.ticks[i]); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1020 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1021 if (this.options.reversed) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1022 percentage = 100 - percentage; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1023 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1024 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1025 this.ticks[i].style[this.stylePos] = percentage + '%'; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1026 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1027 /* Set class labels to denote whether ticks are in the selection */ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1028 this._removeClass(this.ticks[i], 'in-selection'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1029 if (!this.options.range) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1030 if (this.options.selection === 'after' && percentage >= positionPercentages[0]){ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1031 this._addClass(this.ticks[i], 'in-selection'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1032 } else if (this.options.selection === 'before' && percentage <= positionPercentages[0]) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1033 this._addClass(this.ticks[i], 'in-selection'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1034 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1035 } else if (percentage >= positionPercentages[0] && percentage <= positionPercentages[1]) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1036 this._addClass(this.ticks[i], 'in-selection'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1037 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1038 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1039 if (this.tickLabels[i]) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1040 this.tickLabels[i].style[styleSize] = labelSize + 'px'; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1041 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1042 if (this.options.orientation !== 'vertical' && this.options.ticks_positions[i] !== undefined) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1043 this.tickLabels[i].style.position = 'absolute'; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1044 this.tickLabels[i].style[this.stylePos] = percentage + '%'; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1045 this.tickLabels[i].style[styleMargin] = -labelSize/2 + 'px'; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1046 } else if (this.options.orientation === 'vertical') { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1047 this.tickLabels[i].style['marginLeft'] = this.sliderElem.offsetWidth + 'px'; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1048 this.tickLabelContainer.style['marginTop'] = this.sliderElem.offsetWidth / 2 * -1 + 'px'; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1049 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1050 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1051 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1052 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1053 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1054 var formattedTooltipVal; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1055 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1056 if (this.options.range) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1057 formattedTooltipVal = this.options.formatter(this._state.value); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1058 this._setText(this.tooltipInner, formattedTooltipVal); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1059 this.tooltip.style[this.stylePos] = (positionPercentages[1] + positionPercentages[0])/2 + '%'; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1060 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1061 if (this.options.orientation === 'vertical') { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1062 this._css(this.tooltip, 'margin-top', -this.tooltip.offsetHeight / 2 + 'px'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1063 } else { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1064 this._css(this.tooltip, 'margin-left', -this.tooltip.offsetWidth / 2 + 'px'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1065 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1066 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1067 if (this.options.orientation === 'vertical') { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1068 this._css(this.tooltip, 'margin-top', -this.tooltip.offsetHeight / 2 + 'px'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1069 } else { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1070 this._css(this.tooltip, 'margin-left', -this.tooltip.offsetWidth / 2 + 'px'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1071 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1072 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1073 var innerTooltipMinText = this.options.formatter(this._state.value[0]); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1074 this._setText(this.tooltipInner_min, innerTooltipMinText); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1075 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1076 var innerTooltipMaxText = this.options.formatter(this._state.value[1]); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1077 this._setText(this.tooltipInner_max, innerTooltipMaxText); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1078 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1079 this.tooltip_min.style[this.stylePos] = positionPercentages[0] + '%'; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1080 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1081 if (this.options.orientation === 'vertical') { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1082 this._css(this.tooltip_min, 'margin-top', -this.tooltip_min.offsetHeight / 2 + 'px'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1083 } else { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1084 this._css(this.tooltip_min, 'margin-left', -this.tooltip_min.offsetWidth / 2 + 'px'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1085 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1086 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1087 this.tooltip_max.style[this.stylePos] = positionPercentages[1] + '%'; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1088 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1089 if (this.options.orientation === 'vertical') { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1090 this._css(this.tooltip_max, 'margin-top', -this.tooltip_max.offsetHeight / 2 + 'px'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1091 } else { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1092 this._css(this.tooltip_max, 'margin-left', -this.tooltip_max.offsetWidth / 2 + 'px'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1093 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1094 } else { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1095 formattedTooltipVal = this.options.formatter(this._state.value[0]); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1096 this._setText(this.tooltipInner, formattedTooltipVal); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1097 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1098 this.tooltip.style[this.stylePos] = positionPercentages[0] + '%'; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1099 if (this.options.orientation === 'vertical') { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1100 this._css(this.tooltip, 'margin-top', -this.tooltip.offsetHeight / 2 + 'px'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1101 } else { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1102 this._css(this.tooltip, 'margin-left', -this.tooltip.offsetWidth / 2 + 'px'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1103 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1104 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1105 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1106 if (this.options.orientation === 'vertical') { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1107 this.trackLow.style.top = '0'; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1108 this.trackLow.style.height = Math.min(positionPercentages[0], positionPercentages[1]) +'%'; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1109 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1110 this.trackSelection.style.top = Math.min(positionPercentages[0], positionPercentages[1]) +'%'; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1111 this.trackSelection.style.height = Math.abs(positionPercentages[0] - positionPercentages[1]) +'%'; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1112 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1113 this.trackHigh.style.bottom = '0'; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1114 this.trackHigh.style.height = (100 - Math.min(positionPercentages[0], positionPercentages[1]) - Math.abs(positionPercentages[0] - positionPercentages[1])) +'%'; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1115 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1116 else { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1117 this.trackLow.style.left = '0'; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1118 this.trackLow.style.width = Math.min(positionPercentages[0], positionPercentages[1]) +'%'; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1119 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1120 this.trackSelection.style.left = Math.min(positionPercentages[0], positionPercentages[1]) +'%'; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1121 this.trackSelection.style.width = Math.abs(positionPercentages[0] - positionPercentages[1]) +'%'; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1122 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1123 this.trackHigh.style.right = '0'; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1124 this.trackHigh.style.width = (100 - Math.min(positionPercentages[0], positionPercentages[1]) - Math.abs(positionPercentages[0] - positionPercentages[1])) +'%'; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1125 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1126 var offset_min = this.tooltip_min.getBoundingClientRect(); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1127 var offset_max = this.tooltip_max.getBoundingClientRect(); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1128 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1129 if (offset_min.right > offset_max.left) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1130 this._removeClass(this.tooltip_max, 'top'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1131 this._addClass(this.tooltip_max, 'bottom'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1132 this.tooltip_max.style.top = 18 + 'px'; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1133 } else { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1134 this._removeClass(this.tooltip_max, 'bottom'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1135 this._addClass(this.tooltip_max, 'top'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1136 this.tooltip_max.style.top = this.tooltip_min.style.top; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1137 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1138 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1139 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1140 _removeProperty: function(element, prop) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1141 if (element.style.removeProperty) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1142 element.style.removeProperty(prop); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1143 } else { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1144 element.style.removeAttribute(prop); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1145 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1146 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1147 _mousedown: function(ev) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1148 if(!this._state.enabled) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1149 return false; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1150 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1151 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1152 this._state.offset = this._offset(this.sliderElem); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1153 this._state.size = this.sliderElem[this.sizePos]; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1154 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1155 var percentage = this._getPercentage(ev); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1156 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1157 if (this.options.range) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1158 var diff1 = Math.abs(this._state.percentage[0] - percentage); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1159 var diff2 = Math.abs(this._state.percentage[1] - percentage); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1160 this._state.dragged = (diff1 < diff2) ? 0 : 1; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1161 } else { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1162 this._state.dragged = 0; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1163 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1164 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1165 this._state.percentage[this._state.dragged] = percentage; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1166 this._layout(); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1167 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1168 if (this.touchCapable) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1169 document.removeEventListener("touchmove", this.mousemove, false); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1170 document.removeEventListener("touchend", this.mouseup, false); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1171 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1172 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1173 if(this.mousemove){ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1174 document.removeEventListener("mousemove", this.mousemove, false); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1175 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1176 if(this.mouseup){ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1177 document.removeEventListener("mouseup", this.mouseup, false); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1178 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1179 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1180 this.mousemove = this._mousemove.bind(this); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1181 this.mouseup = this._mouseup.bind(this); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1182 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1183 if (this.touchCapable) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1184 // Touch: Bind touch events: |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1185 document.addEventListener("touchmove", this.mousemove, false); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1186 document.addEventListener("touchend", this.mouseup, false); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1187 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1188 // Bind mouse events: |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1189 document.addEventListener("mousemove", this.mousemove, false); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1190 document.addEventListener("mouseup", this.mouseup, false); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1191 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1192 this._state.inDrag = true; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1193 var newValue = this._calculateValue(); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1194 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1195 this._trigger('slideStart', newValue); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1196 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1197 this._setDataVal(newValue); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1198 this.setValue(newValue, false, true); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1199 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1200 this._pauseEvent(ev); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1201 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1202 if (this.options.focus) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1203 this._triggerFocusOnHandle(this._state.dragged); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1204 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1205 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1206 return true; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1207 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1208 _triggerFocusOnHandle: function(handleIdx) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1209 if(handleIdx === 0) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1210 this.handle1.focus(); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1211 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1212 if(handleIdx === 1) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1213 this.handle2.focus(); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1214 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1215 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1216 _keydown: function(handleIdx, ev) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1217 if(!this._state.enabled) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1218 return false; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1219 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1220 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1221 var dir; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1222 switch (ev.keyCode) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1223 case 37: // left |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1224 case 40: // down |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1225 dir = -1; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1226 break; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1227 case 39: // right |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1228 case 38: // up |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1229 dir = 1; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1230 break; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1231 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1232 if (!dir) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1233 return; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1234 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1235 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1236 // use natural arrow keys instead of from min to max |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1237 if (this.options.natural_arrow_keys) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1238 var ifVerticalAndNotReversed = (this.options.orientation === 'vertical' && !this.options.reversed); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1239 var ifHorizontalAndReversed = (this.options.orientation === 'horizontal' && this.options.reversed); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1240 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1241 if (ifVerticalAndNotReversed || ifHorizontalAndReversed) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1242 dir = -dir; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1243 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1244 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1245 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1246 var val = this._state.value[handleIdx] + dir * this.options.step; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1247 if (this.options.range) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1248 val = [ (!handleIdx) ? val : this._state.value[0], |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1249 ( handleIdx) ? val : this._state.value[1]]; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1250 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1251 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1252 this._trigger('slideStart', val); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1253 this._setDataVal(val); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1254 this.setValue(val, true, true); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1255 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1256 this._setDataVal(val); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1257 this._trigger('slideStop', val); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1258 this._layout(); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1259 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1260 this._pauseEvent(ev); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1261 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1262 return false; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1263 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1264 _pauseEvent: function(ev) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1265 if(ev.stopPropagation) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1266 ev.stopPropagation(); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1267 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1268 if(ev.preventDefault) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1269 ev.preventDefault(); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1270 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1271 ev.cancelBubble=true; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1272 ev.returnValue=false; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1273 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1274 _mousemove: function(ev) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1275 if(!this._state.enabled) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1276 return false; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1277 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1278 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1279 var percentage = this._getPercentage(ev); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1280 this._adjustPercentageForRangeSliders(percentage); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1281 this._state.percentage[this._state.dragged] = percentage; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1282 this._layout(); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1283 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1284 var val = this._calculateValue(true); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1285 this.setValue(val, true, true); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1286 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1287 return false; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1288 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1289 _adjustPercentageForRangeSliders: function(percentage) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1290 if (this.options.range) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1291 var precision = this._getNumDigitsAfterDecimalPlace(percentage); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1292 precision = precision ? precision - 1 : 0; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1293 var percentageWithAdjustedPrecision = this._applyToFixedAndParseFloat(percentage, precision); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1294 if (this._state.dragged === 0 && this._applyToFixedAndParseFloat(this._state.percentage[1], precision) < percentageWithAdjustedPrecision) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1295 this._state.percentage[0] = this._state.percentage[1]; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1296 this._state.dragged = 1; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1297 } else if (this._state.dragged === 1 && this._applyToFixedAndParseFloat(this._state.percentage[0], precision) > percentageWithAdjustedPrecision) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1298 this._state.percentage[1] = this._state.percentage[0]; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1299 this._state.dragged = 0; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1300 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1301 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1302 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1303 _mouseup: function() { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1304 if(!this._state.enabled) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1305 return false; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1306 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1307 if (this.touchCapable) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1308 // Touch: Unbind touch event handlers: |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1309 document.removeEventListener("touchmove", this.mousemove, false); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1310 document.removeEventListener("touchend", this.mouseup, false); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1311 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1312 // Unbind mouse event handlers: |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1313 document.removeEventListener("mousemove", this.mousemove, false); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1314 document.removeEventListener("mouseup", this.mouseup, false); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1315 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1316 this._state.inDrag = false; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1317 if (this._state.over === false) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1318 this._hideTooltip(); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1319 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1320 var val = this._calculateValue(true); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1321 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1322 this._layout(); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1323 this._setDataVal(val); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1324 this._trigger('slideStop', val); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1325 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1326 return false; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1327 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1328 _calculateValue: function(snapToClosestTick) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1329 var val; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1330 if (this.options.range) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1331 val = [this.options.min,this.options.max]; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1332 if (this._state.percentage[0] !== 0){ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1333 val[0] = this._toValue(this._state.percentage[0]); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1334 val[0] = this._applyPrecision(val[0]); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1335 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1336 if (this._state.percentage[1] !== 100){ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1337 val[1] = this._toValue(this._state.percentage[1]); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1338 val[1] = this._applyPrecision(val[1]); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1339 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1340 } else { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1341 val = this._toValue(this._state.percentage[0]); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1342 val = parseFloat(val); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1343 val = this._applyPrecision(val); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1344 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1345 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1346 if (snapToClosestTick) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1347 var min = [val, Infinity]; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1348 for (var i = 0; i < this.options.ticks.length; i++) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1349 var diff = Math.abs(this.options.ticks[i] - val); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1350 if (diff <= min[1]) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1351 min = [this.options.ticks[i], diff]; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1352 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1353 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1354 if (min[1] <= this.options.ticks_snap_bounds) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1355 return min[0]; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1356 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1357 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1358 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1359 return val; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1360 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1361 _applyPrecision: function(val) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1362 var precision = this.options.precision || this._getNumDigitsAfterDecimalPlace(this.options.step); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1363 return this._applyToFixedAndParseFloat(val, precision); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1364 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1365 _getNumDigitsAfterDecimalPlace: function(num) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1366 var match = (''+num).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1367 if (!match) { return 0; } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1368 return Math.max(0, (match[1] ? match[1].length : 0) - (match[2] ? +match[2] : 0)); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1369 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1370 _applyToFixedAndParseFloat: function(num, toFixedInput) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1371 var truncatedNum = num.toFixed(toFixedInput); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1372 return parseFloat(truncatedNum); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1373 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1374 /* |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1375 Credits to Mike Samuel for the following method! |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1376 Source: http://stackoverflow.com/questions/10454518/javascript-how-to-retrieve-the-number-of-decimals-of-a-string-number |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1377 */ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1378 _getPercentage: function(ev) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1379 if (this.touchCapable && (ev.type === 'touchstart' || ev.type === 'touchmove')) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1380 ev = ev.touches[0]; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1381 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1382 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1383 var eventPosition = ev[this.mousePos]; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1384 var sliderOffset = this._state.offset[this.stylePos]; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1385 var distanceToSlide = eventPosition - sliderOffset; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1386 // Calculate what percent of the length the slider handle has slid |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1387 var percentage = (distanceToSlide / this._state.size) * 100; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1388 percentage = Math.round(percentage / this._state.percentage[2]) * this._state.percentage[2]; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1389 if (this.options.reversed) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1390 percentage = 100 - percentage; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1391 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1392 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1393 // Make sure the percent is within the bounds of the slider. |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1394 // 0% corresponds to the 'min' value of the slide |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1395 // 100% corresponds to the 'max' value of the slide |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1396 return Math.max(0, Math.min(100, percentage)); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1397 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1398 _validateInputValue: function(val) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1399 if (typeof val === 'number') { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1400 return val; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1401 } else if (Array.isArray(val)) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1402 this._validateArray(val); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1403 return val; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1404 } else { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1405 throw new Error( ErrorMsgs.formatInvalidInputErrorMsg(val) ); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1406 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1407 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1408 _validateArray: function(val) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1409 for(var i = 0; i < val.length; i++) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1410 var input = val[i]; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1411 if (typeof input !== 'number') { throw new Error( ErrorMsgs.formatInvalidInputErrorMsg(input) ); } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1412 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1413 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1414 _setDataVal: function(val) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1415 this.element.setAttribute('data-value', val); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1416 this.element.setAttribute('value', val); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1417 this.element.value = val; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1418 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1419 _trigger: function(evt, val) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1420 val = (val || val === 0) ? val : undefined; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1421 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1422 var callbackFnArray = this.eventToCallbackMap[evt]; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1423 if(callbackFnArray && callbackFnArray.length) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1424 for(var i = 0; i < callbackFnArray.length; i++) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1425 var callbackFn = callbackFnArray[i]; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1426 callbackFn(val); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1427 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1428 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1429 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1430 /* If JQuery exists, trigger JQuery events */ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1431 if($) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1432 this._triggerJQueryEvent(evt, val); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1433 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1434 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1435 _triggerJQueryEvent: function(evt, val) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1436 var eventData = { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1437 type: evt, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1438 value: val |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1439 }; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1440 this.$element.trigger(eventData); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1441 this.$sliderElem.trigger(eventData); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1442 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1443 _unbindJQueryEventHandlers: function() { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1444 this.$element.off(); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1445 this.$sliderElem.off(); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1446 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1447 _setText: function(element, text) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1448 if(typeof element.innerText !== "undefined") { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1449 element.innerText = text; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1450 } else if(typeof element.textContent !== "undefined") { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1451 element.textContent = text; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1452 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1453 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1454 _removeClass: function(element, classString) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1455 var classes = classString.split(" "); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1456 var newClasses = element.className; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1457 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1458 for(var i = 0; i < classes.length; i++) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1459 var classTag = classes[i]; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1460 var regex = new RegExp("(?:\\s|^)" + classTag + "(?:\\s|$)"); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1461 newClasses = newClasses.replace(regex, " "); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1462 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1463 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1464 element.className = newClasses.trim(); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1465 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1466 _addClass: function(element, classString) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1467 var classes = classString.split(" "); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1468 var newClasses = element.className; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1469 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1470 for(var i = 0; i < classes.length; i++) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1471 var classTag = classes[i]; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1472 var regex = new RegExp("(?:\\s|^)" + classTag + "(?:\\s|$)"); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1473 var ifClassExists = regex.test(newClasses); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1474 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1475 if(!ifClassExists) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1476 newClasses += " " + classTag; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1477 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1478 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1479 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1480 element.className = newClasses.trim(); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1481 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1482 _offsetLeft: function(obj){ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1483 return obj.getBoundingClientRect().left; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1484 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1485 _offsetTop: function(obj){ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1486 var offsetTop = obj.offsetTop; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1487 while((obj = obj.offsetParent) && !isNaN(obj.offsetTop)){ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1488 offsetTop += obj.offsetTop; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1489 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1490 return offsetTop; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1491 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1492 _offset: function (obj) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1493 return { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1494 left: this._offsetLeft(obj), |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1495 top: this._offsetTop(obj) |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1496 }; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1497 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1498 _css: function(elementRef, styleName, value) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1499 if ($) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1500 $.style(elementRef, styleName, value); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1501 } else { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1502 var style = styleName.replace(/^-ms-/, "ms-").replace(/-([\da-z])/gi, function (all, letter) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1503 return letter.toUpperCase(); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1504 }); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1505 elementRef.style[style] = value; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1506 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1507 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1508 _toValue: function(percentage) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1509 return this.options.scale.toValue.apply(this, [percentage]); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1510 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1511 _toPercentage: function(value) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1512 return this.options.scale.toPercentage.apply(this, [value]); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1513 }, |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1514 _setTooltipPosition: function(){ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1515 var tooltips = [this.tooltip, this.tooltip_min, this.tooltip_max]; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1516 if (this.options.orientation === 'vertical'){ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1517 var tooltipPos = this.options.tooltip_position || 'right'; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1518 var oppositeSide = (tooltipPos === 'left') ? 'right' : 'left'; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1519 tooltips.forEach(function(tooltip){ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1520 this._addClass(tooltip, tooltipPos); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1521 tooltip.style[oppositeSide] = '100%'; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1522 }.bind(this)); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1523 } else if(this.options.tooltip_position === 'bottom') { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1524 tooltips.forEach(function(tooltip){ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1525 this._addClass(tooltip, 'bottom'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1526 tooltip.style.top = 22 + 'px'; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1527 }.bind(this)); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1528 } else { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1529 tooltips.forEach(function(tooltip){ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1530 this._addClass(tooltip, 'top'); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1531 tooltip.style.top = -this.tooltip.outerHeight - 14 + 'px'; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1532 }.bind(this)); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1533 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1534 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1535 }; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1536 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1537 /********************************* |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1538 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1539 Attach to global namespace |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1540 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1541 *********************************/ |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1542 if($) { |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1543 var namespace = $.fn.slider ? 'bootstrapSlider' : 'slider'; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1544 $.bridget(namespace, Slider); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1545 } |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1546 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1547 })( $ ); |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1548 |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1549 return Slider; |
f82512502b31
Initial commit for query builder, still need to tailor for ISMI purposes
alistair
parents:
diff
changeset
|
1550 })); |