Slider.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dojox.sketch.Slider"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.sketch.Slider"] = true;
  8. dojo.provide("dojox.sketch.Slider");
  9. dojo.require("dijit.form.HorizontalSlider");
  10. dojo.declare("dojox.sketch.Slider",dojox.sketch._Plugin,{
  11. _initButton: function(){
  12. this.slider=new dijit.form.HorizontalSlider({minimum:5,maximum:100,style:"width:100px;",baseClass:'dijitInline dijitSlider'});
  13. this.slider._movable.node.title='Double Click to "Zoom to Fit"'; //I18N
  14. this.connect(this.slider,'onChange','_setZoom');
  15. this.connect(this.slider.sliderHandle,'ondblclick','_zoomToFit');
  16. },
  17. _zoomToFit: function(){
  18. var r=this.figure.getFit();
  19. this.slider.attr('value',this.slider.maximum<r?this.slider.maximum:(this.slider.minimum>r?this.slider.minimum:r));
  20. },
  21. _setZoom: function(v){
  22. if(v && this.figure){
  23. this.figure.zoom(v);
  24. }
  25. },
  26. reset: function(){
  27. //reset slider to maximum so that onChange will be fired when _zoomToFit is called
  28. this.slider.attr('value',this.slider.maximum);
  29. this._zoomToFit();
  30. },
  31. setToolbar: function(t){
  32. this._initButton();
  33. t.addChild(this.slider);
  34. if(!t._reset2Zoom){
  35. t._reset2Zoom=true;
  36. this.connect(t,'reset','reset');
  37. }
  38. }
  39. });
  40. dojox.sketch.registerTool("Slider", dojox.sketch.Slider);
  41. }