-
+ C6737E3827261A69E975C8C783D5496E7E5C3166318CAA868B8FF3AEC4AA2DEED46FA0C0825CD5DF1E8FE82728E8534B081337C1DCE047C48F0EF0FDB8B47ECF
mp-wp/wp-includes/js/scriptaculous/slider.js
(0 . 0)(1 . 275)
115136 // script.aculo.us slider.js v1.8.0, Tue Nov 06 15:01:40 +0300 2007
115137
115138 // Copyright (c) 2005-2007 Marty Haught, Thomas Fuchs
115139 //
115140 // script.aculo.us is freely distributable under the terms of an MIT-style license.
115141 // For details, see the script.aculo.us web site: http://script.aculo.us/
115142
115143 if (!Control) var Control = { };
115144
115145 // options:
115146 // axis: 'vertical', or 'horizontal' (default)
115147 //
115148 // callbacks:
115149 // onChange(value)
115150 // onSlide(value)
115151 Control.Slider = Class.create({
115152 initialize: function(handle, track, options) {
115153 var slider = this;
115154
115155 if (Object.isArray(handle)) {
115156 this.handles = handle.collect( function(e) { return $(e) });
115157 } else {
115158 this.handles = [$(handle)];
115159 }
115160
115161 this.track = $(track);
115162 this.options = options || { };
115163
115164 this.axis = this.options.axis || 'horizontal';
115165 this.increment = this.options.increment || 1;
115166 this.step = parseInt(this.options.step || '1');
115167 this.range = this.options.range || $R(0,1);
115168
115169 this.value = 0; // assure backwards compat
115170 this.values = this.handles.map( function() { return 0 });
115171 this.spans = this.options.spans ? this.options.spans.map(function(s){ return $(s) }) : false;
115172 this.options.startSpan = $(this.options.startSpan || null);
115173 this.options.endSpan = $(this.options.endSpan || null);
115174
115175 this.restricted = this.options.restricted || false;
115176
115177 this.maximum = this.options.maximum || this.range.end;
115178 this.minimum = this.options.minimum || this.range.start;
115179
115180 // Will be used to align the handle onto the track, if necessary
115181 this.alignX = parseInt(this.options.alignX || '0');
115182 this.alignY = parseInt(this.options.alignY || '0');
115183
115184 this.trackLength = this.maximumOffset() - this.minimumOffset();
115185
115186 this.handleLength = this.isVertical() ?
115187 (this.handles[0].offsetHeight != 0 ?
115188 this.handles[0].offsetHeight : this.handles[0].style.height.replace(/px$/,"")) :
115189 (this.handles[0].offsetWidth != 0 ? this.handles[0].offsetWidth :
115190 this.handles[0].style.width.replace(/px$/,""));
115191
115192 this.active = false;
115193 this.dragging = false;
115194 this.disabled = false;
115195
115196 if (this.options.disabled) this.setDisabled();
115197
115198 // Allowed values array
115199 this.allowedValues = this.options.values ? this.options.values.sortBy(Prototype.K) : false;
115200 if (this.allowedValues) {
115201 this.minimum = this.allowedValues.min();
115202 this.maximum = this.allowedValues.max();
115203 }
115204
115205 this.eventMouseDown = this.startDrag.bindAsEventListener(this);
115206 this.eventMouseUp = this.endDrag.bindAsEventListener(this);
115207 this.eventMouseMove = this.update.bindAsEventListener(this);
115208
115209 // Initialize handles in reverse (make sure first handle is active)
115210 this.handles.each( function(h,i) {
115211 i = slider.handles.length-1-i;
115212 slider.setValue(parseFloat(
115213 (Object.isArray(slider.options.sliderValue) ?
115214 slider.options.sliderValue[i] : slider.options.sliderValue) ||
115215 slider.range.start), i);
115216 h.makePositioned().observe("mousedown", slider.eventMouseDown);
115217 });
115218
115219 this.track.observe("mousedown", this.eventMouseDown);
115220 document.observe("mouseup", this.eventMouseUp);
115221 document.observe("mousemove", this.eventMouseMove);
115222
115223 this.initialized = true;
115224 },
115225 dispose: function() {
115226 var slider = this;
115227 Event.stopObserving(this.track, "mousedown", this.eventMouseDown);
115228 Event.stopObserving(document, "mouseup", this.eventMouseUp);
115229 Event.stopObserving(document, "mousemove", this.eventMouseMove);
115230 this.handles.each( function(h) {
115231 Event.stopObserving(h, "mousedown", slider.eventMouseDown);
115232 });
115233 },
115234 setDisabled: function(){
115235 this.disabled = true;
115236 },
115237 setEnabled: function(){
115238 this.disabled = false;
115239 },
115240 getNearestValue: function(value){
115241 if (this.allowedValues){
115242 if (value >= this.allowedValues.max()) return(this.allowedValues.max());
115243 if (value <= this.allowedValues.min()) return(this.allowedValues.min());
115244
115245 var offset = Math.abs(this.allowedValues[0] - value);
115246 var newValue = this.allowedValues[0];
115247 this.allowedValues.each( function(v) {
115248 var currentOffset = Math.abs(v - value);
115249 if (currentOffset <= offset){
115250 newValue = v;
115251 offset = currentOffset;
115252 }
115253 });
115254 return newValue;
115255 }
115256 if (value > this.range.end) return this.range.end;
115257 if (value < this.range.start) return this.range.start;
115258 return value;
115259 },
115260 setValue: function(sliderValue, handleIdx){
115261 if (!this.active) {
115262 this.activeHandleIdx = handleIdx || 0;
115263 this.activeHandle = this.handles[this.activeHandleIdx];
115264 this.updateStyles();
115265 }
115266 handleIdx = handleIdx || this.activeHandleIdx || 0;
115267 if (this.initialized && this.restricted) {
115268 if ((handleIdx>0) && (sliderValue<this.values[handleIdx-1]))
115269 sliderValue = this.values[handleIdx-1];
115270 if ((handleIdx < (this.handles.length-1)) && (sliderValue>this.values[handleIdx+1]))
115271 sliderValue = this.values[handleIdx+1];
115272 }
115273 sliderValue = this.getNearestValue(sliderValue);
115274 this.values[handleIdx] = sliderValue;
115275 this.value = this.values[0]; // assure backwards compat
115276
115277 this.handles[handleIdx].style[this.isVertical() ? 'top' : 'left'] =
115278 this.translateToPx(sliderValue);
115279
115280 this.drawSpans();
115281 if (!this.dragging || !this.event) this.updateFinished();
115282 },
115283 setValueBy: function(delta, handleIdx) {
115284 this.setValue(this.values[handleIdx || this.activeHandleIdx || 0] + delta,
115285 handleIdx || this.activeHandleIdx || 0);
115286 },
115287 translateToPx: function(value) {
115288 return Math.round(
115289 ((this.trackLength-this.handleLength)/(this.range.end-this.range.start)) *
115290 (value - this.range.start)) + "px";
115291 },
115292 translateToValue: function(offset) {
115293 return ((offset/(this.trackLength-this.handleLength) *
115294 (this.range.end-this.range.start)) + this.range.start);
115295 },
115296 getRange: function(range) {
115297 var v = this.values.sortBy(Prototype.K);
115298 range = range || 0;
115299 return $R(v[range],v[range+1]);
115300 },
115301 minimumOffset: function(){
115302 return(this.isVertical() ? this.alignY : this.alignX);
115303 },
115304 maximumOffset: function(){
115305 return(this.isVertical() ?
115306 (this.track.offsetHeight != 0 ? this.track.offsetHeight :
115307 this.track.style.height.replace(/px$/,"")) - this.alignY :
115308 (this.track.offsetWidth != 0 ? this.track.offsetWidth :
115309 this.track.style.width.replace(/px$/,"")) - this.alignX);
115310 },
115311 isVertical: function(){
115312 return (this.axis == 'vertical');
115313 },
115314 drawSpans: function() {
115315 var slider = this;
115316 if (this.spans)
115317 $R(0, this.spans.length-1).each(function(r) { slider.setSpan(slider.spans[r], slider.getRange(r)) });
115318 if (this.options.startSpan)
115319 this.setSpan(this.options.startSpan,
115320 $R(0, this.values.length>1 ? this.getRange(0).min() : this.value ));
115321 if (this.options.endSpan)
115322 this.setSpan(this.options.endSpan,
115323 $R(this.values.length>1 ? this.getRange(this.spans.length-1).max() : this.value, this.maximum));
115324 },
115325 setSpan: function(span, range) {
115326 if (this.isVertical()) {
115327 span.style.top = this.translateToPx(range.start);
115328 span.style.height = this.translateToPx(range.end - range.start + this.range.start);
115329 } else {
115330 span.style.left = this.translateToPx(range.start);
115331 span.style.width = this.translateToPx(range.end - range.start + this.range.start);
115332 }
115333 },
115334 updateStyles: function() {
115335 this.handles.each( function(h){ Element.removeClassName(h, 'selected') });
115336 Element.addClassName(this.activeHandle, 'selected');
115337 },
115338 startDrag: function(event) {
115339 if (Event.isLeftClick(event)) {
115340 if (!this.disabled){
115341 this.active = true;
115342
115343 var handle = Event.element(event);
115344 var pointer = [Event.pointerX(event), Event.pointerY(event)];
115345 var track = handle;
115346 if (track==this.track) {
115347 var offsets = Position.cumulativeOffset(this.track);
115348 this.event = event;
115349 this.setValue(this.translateToValue(
115350 (this.isVertical() ? pointer[1]-offsets[1] : pointer[0]-offsets[0])-(this.handleLength/2)
115351 ));
115352 var offsets = Position.cumulativeOffset(this.activeHandle);
115353 this.offsetX = (pointer[0] - offsets[0]);
115354 this.offsetY = (pointer[1] - offsets[1]);
115355 } else {
115356 // find the handle (prevents issues with Safari)
115357 while((this.handles.indexOf(handle) == -1) && handle.parentNode)
115358 handle = handle.parentNode;
115359
115360 if (this.handles.indexOf(handle)!=-1) {
115361 this.activeHandle = handle;
115362 this.activeHandleIdx = this.handles.indexOf(this.activeHandle);
115363 this.updateStyles();
115364
115365 var offsets = Position.cumulativeOffset(this.activeHandle);
115366 this.offsetX = (pointer[0] - offsets[0]);
115367 this.offsetY = (pointer[1] - offsets[1]);
115368 }
115369 }
115370 }
115371 Event.stop(event);
115372 }
115373 },
115374 update: function(event) {
115375 if (this.active) {
115376 if (!this.dragging) this.dragging = true;
115377 this.draw(event);
115378 if (Prototype.Browser.WebKit) window.scrollBy(0,0);
115379 Event.stop(event);
115380 }
115381 },
115382 draw: function(event) {
115383 var pointer = [Event.pointerX(event), Event.pointerY(event)];
115384 var offsets = Position.cumulativeOffset(this.track);
115385 pointer[0] -= this.offsetX + offsets[0];
115386 pointer[1] -= this.offsetY + offsets[1];
115387 this.event = event;
115388 this.setValue(this.translateToValue( this.isVertical() ? pointer[1] : pointer[0] ));
115389 if (this.initialized && this.options.onSlide)
115390 this.options.onSlide(this.values.length>1 ? this.values : this.value, this);
115391 },
115392 endDrag: function(event) {
115393 if (this.active && this.dragging) {
115394 this.finishDrag(event, true);
115395 Event.stop(event);
115396 }
115397 this.active = false;
115398 this.dragging = false;
115399 },
115400 finishDrag: function(event, success) {
115401 this.active = false;
115402 this.dragging = false;
115403 this.updateFinished();
115404 },
115405 updateFinished: function() {
115406 if (this.initialized && this.options.onChange)
115407 this.options.onChange(this.values.length>1 ? this.values : this.value, this);
115408 this.event = null;
115409 }
115410 });