Fandom

TOR Wiki

Holo:Featured Articles/Day 104

4,474pages on
this wiki
Add New Page
Talk0 Share

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.


YAHOO.util.Event.onDOMReady(function() {

   var Ex     = YAHOO.namespace('example'),
       Dom    = YAHOO.util.Dom,
       Event  = YAHOO.util.Event,
       Slider = YAHOO.widget.Slider;
   // Apply some patches to DualSlider's prototype before instantiation
   // Patch to support vertical DualSliders with wide thumbs
   YAHOO.widget.DualSlider.prototype.updateValue=function(silent){var min=this.minSlider.getValue(),max=this.maxSlider.getValue(),changed=false;if(min!=this.minVal||max!=this.maxVal){changed=true;var mint=this.minSlider.thumb,maxt=this.maxSlider.thumb,dim=this.isHoriz?'x':'y';var thumbInnerWidth=this.minSlider.thumbCenterPoint[dim]+this.maxSlider.thumbCenterPoint[dim];var minConstraint=Math.max(max-thumbInnerWidth-this.minRange,0);var maxConstraint=Math.min(-min-thumbInnerWidth-this.minRange,0);if(this.isHoriz){minConstraint=Math.min(minConstraint,maxt.rightConstraint);mint.setXConstraint(mint.leftConstraint,minConstraint,mint.tickSize);maxt.setXConstraint(maxConstraint,maxt.rightConstraint,maxt.tickSize);}else{minConstraint=Math.min(minConstraint,maxt.bottomConstraint);mint.setYConstraint(mint.leftConstraint,minConstraint,mint.tickSize);maxt.setYConstraint(maxConstraint,maxt.bottomConstraint,maxt.tickSize);}}this.minVal=min;this.maxVal=max;if(changed&&!silent){this.fireEvent("change",this);}};
   // Patch to support selecting the right Slider when A) one is locked, or
   // B) displayed after instantiation in hidden container
   YAHOO.widget.DualSlider.prototype.selectActiveSlider=function(e){var min=this.minSlider,max=this.maxSlider,minLocked=min.isLocked(),maxLocked=max.isLocked(),d;if(minLocked&&!maxLocked){this.activeSlider=max;}else if(!minLocked&&maxLocked){this.activeSlider=min;}else{if(this.isHoriz){d=YAHOO.util.Event.getPageX(e)-min.thumb.initPageX-min.thumbCenterPoint.x;}else{d=YAHOO.util.Event.getPageY(e)-min.thumb.initPageY-min.thumbCenterPoint.y;}this.activeSlider=d*2>max.getValue()+min.getValue()?max:min;}};


   /*******************************************************************/
   /* Solution #1: Instantiate when container is displayed            */
   /* Pros: No special code or prototype changes (except DualSlider   */
   /*       bug patches).                                             */
   /* Cons: May be sub-optimal for application code.                  */
   /*******************************************************************/
   var report1      = document.getElementById('report1'),
       report_dual1 = document.getElementById('report_dual1');
   Event.on('show1','click', function (e) {
       Event.stopEvent(e); // Cancel link click
       // Display the container
       Dom.removeClass('container1','hide');
       // Instantiate the Sliders
       Ex.slider1 = Slider.getHorizSlider('slider1','thumb1',0,200);
       
       Ex.dual1 = Slider.getHorizDualSlider('dual1','min1','max1',200);
       // One last DualSlider patch to support background clicks when min or
       // max Slider is locked
       Ex.dual1.maxSlider.onMouseDown = function (e) {
           if (Ex.dual1.minSlider.isLocked()) {
               Ex.dual1._handleMouseDown(e);
           } else {
               Event.stopEvent(e);
           }
       };
       Ex.slider1.subscribe('change', function (v) {
           report1.innerHTML = v;
       });
       Ex.dual1.subscribe('change', function (ds) {
           report_dual1.innerHTML = ds.minVal + ' - ' + ds.maxVal;
       });
       // Immediately report values (on 'ready' event for DualSlider)
       report1.innerHTML = Ex.slider1.getValue();
       Ex.dual1.subscribe('ready',function () {
           report_dual1.innerHTML = Ex.dual1.minVal + ' - ' + Ex.dual1.maxVal;
       });
       // Remove the unhide link
       this.parentNode.removeChild(this);
   });


   /*******************************************************************/
   /* Solution #2: Reset internal references on container display     */
   /* Pros: getValue reports correctly immediately after reset,       */
   /*       correctly fixes DualSlider state and UI.                  */
   /* Cons: getValue reports NaN until displayed+reset, Extra code in */
   /*       display handler.  May as well instantiate on display.     */
   /*******************************************************************/
   var report2      = document.getElementById('report2'),
       report_dual2 = document.getElementById('report_dual2');
   // Instantiate Slider
   Ex.slider2 = YAHOO.widget.Slider.getHorizSlider('slider2','thumb2',0,200);


   // Instantiate DualSlider
   Ex.dual2 = YAHOO.widget.Slider.getHorizDualSlider('dual2','min2','max2',200);
   // DualSlider patch for min or max Slider lock
   Ex.dual2.maxSlider.onMouseDown = function (e) {
       if (Ex.dual2.minSlider.isLocked()) {
           Ex.dual2._handleMouseDown(e);
       } else {
           Event.stopEvent(e);
       }
   };
   Ex.slider2.subscribe('change',function (v) {
       report2.innerHTML = v;
   });
   Ex.dual2.subscribe('change',function (ds) {
       report_dual2.innerHTML = ds.minVal + ' - ' + ds.maxVal;
   });
   Event.on('show2','click', function (e) {
       Event.stopEvent(e);
       // Show the container
       Dom.removeClass('container2','hide');
       // Reset internal reference points
       Ex.slider2.thumb.resetConstraints();
       Ex.slider2.setStartSliderState();
       // Reposition the max thumb at 0, then do the same reset for each
       // of DualSlider's Sliders
       Dom.setStyle('max2','left','0px');
       Ex.dual2.minSlider.thumb.resetConstraints();
       Ex.dual2.minSlider.setStartSliderState();
       Ex.dual2.maxSlider.thumb.resetConstraints();
       Ex.dual2.maxSlider.setStartSliderState();
       // Move thumbs to their initial values
       Ex.dual2.setValues(0,200,true,true,false);
       // Immediately report values
       report2.innerHTML = Ex.slider2.getValue();
       report_dual2.innerHTML = Ex.dual2.minVal + ' - ' + Ex.dual2.maxVal;
       // Remove the unhide link
       this.parentNode.removeChild(this);
   });


   /*******************************************************************/
   /* Solution #3: Patch Slider's verifyOffset method                 */
   /* Pros: One prototype change, no reinitialization code on display */
   /*       for Slider instances.                                     */
   /* Cons: getValue reports NaN until setValue or UI interaction,    */
   /*       inadequate for DualSlider.                                */
   /*******************************************************************/
   var report3      = document.getElementById('report3'),
       report_dual3 = document.getElementById('report_dual3');
   Slider.prototype.verifyOffset=function(checkPos){var newPos=YAHOO.util.Dom.getXY(this.getEl());if(newPos){if(isNaN(this.baselinePos[0])){this.setThumbCenterPoint();this.thumb.startOffset=this.thumb.getOffsetFromParent(newPos);}if(newPos[0]!=this.baselinePos[0]||newPos[1]!=this.baselinePos[1]){this.thumb.resetConstraints();this.baselinePos=newPos;return false;}}return true;};
   // Instantiate Slider
   Ex.slider3 = YAHOO.widget.Slider.getHorizSlider('slider3','thumb3',0,200);
   // Instantiate DualSlider
   Ex.dual3 = YAHOO.widget.Slider.getHorizDualSlider('dual3','min3','max3',200);
   // DualSlider patch for min or max Slider lock
   Ex.dual3.maxSlider.onMouseDown = function (e) {
       if (Ex.dual3.minSlider.isLocked()) {
           Ex.dual3._handleMouseDown(e);
       } else {
           Event.stopEvent(e);
       }
   };
   Ex.slider3.subscribe('change',function (v) {
       report3.innerHTML = v;
   });
   Ex.dual3.subscribe('change',function (ds) {
       report_dual3.innerHTML = ds.minVal + ' - ' + ds.maxVal;
   });
   Event.on('show3','click',function (e) {
       Event.stopEvent(e);
       Dom.removeClass('container3','hide');
       // Immediately report values
       report3.innerHTML = Ex.slider3.getValue();
       report_dual3.innerHTML = Ex.dual3.minVal + ' - ' + Ex.dual3.maxVal;
       // Remove the unhide link
       this.parentNode.removeChild(this);
   });

});

Also on Fandom

Random Wiki