Advertisement
Guest User

Untitled

a guest
Sep 5th, 2015
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.93 KB | None | 0 0
  1. /**
  2. * jQRangeSlider
  3. * A javascript slider selector that supports dates
  4. *
  5. * Copyright (C) Guillaume Gautreau 2012
  6. * Dual licensed under the MIT or GPL Version 2 licenses.
  7. *
  8. */
  9.  
  10. (function ($, undefined) {
  11. "use strict";
  12.  
  13. $.fn.dateRangeSlider = function() {
  14. $.widget("ui.dateRangeSlider", $.ui.rangeSlider, {
  15. options: {
  16. bounds: {min: new Date(2010,0,1).valueOf(), max: new Date(2012,0,1).valueOf()},
  17. defaultValues: {min: new Date(2010,1,11).valueOf(), max: new Date(2011,1,11).valueOf()}
  18. },
  19.  
  20. _create: function(){
  21. $.ui.rangeSlider.prototype._create.apply(this);
  22.  
  23. this.element.addClass("ui-dateRangeSlider");
  24. },
  25.  
  26. destroy: function(){
  27. this.element.removeClass("ui-dateRangeSlider");
  28. $.ui.rangeSlider.prototype.destroy.apply(this);
  29. },
  30.  
  31. _setDefaultValues: function(){
  32. this._values = {
  33. min: this.options.defaultValues.min.valueOf(),
  34. max: this.options.defaultValues.max.valueOf()
  35. };
  36. },
  37.  
  38. _setRulerParameters: function(){
  39. this.ruler.ruler({
  40. min: new Date(this.options.bounds.min.valueOf()),
  41. max: new Date(this.options.bounds.max.valueOf()),
  42. scales: this.options.scales
  43. });
  44. },
  45.  
  46. _setOption: function(key, value){
  47. if ((key === "defaultValues" || key === "bounds") && typeof value !== "undefined" && value !== null && this._isValidDate(value.min) && this._isValidDate(value.max)){
  48. $.ui.rangeSlider.prototype._setOption.apply(this, [key, {min:value.min.valueOf(), max:value.max.valueOf()}]);
  49. }else{
  50. $.ui.rangeSlider.prototype._setOption.apply(this, this._toArray(arguments));
  51. }
  52. },
  53.  
  54. _handleType: function(){
  55. return "dateRangeSliderHandle";
  56. },
  57.  
  58. option: function(key){
  59. if (key === "bounds" || key === "defaultValues"){
  60. var result = $.ui.rangeSlider.prototype.option.apply(this, arguments);
  61.  
  62. return {min:new Date(result.min), max:new Date(result.max)};
  63. }
  64.  
  65. return $.ui.rangeSlider.prototype.option.apply(this, this._toArray(arguments));
  66. },
  67.  
  68. _defaultFormatter: function(value){
  69. var month = value.getMonth() + 1,
  70. day = value.getDate();
  71.  
  72. return "" + value.getFullYear() + "-" + (month < 10 ? "0" + month : month) + "-" + (day < 10 ? "0" + day : day);
  73. },
  74.  
  75. _getFormatter: function(){
  76. var formatter = this.options.formatter;
  77.  
  78. if (this.options.formatter === false || this.options.formatter === null){
  79. formatter = this._defaultFormatter;
  80. }
  81.  
  82. return (function(formatter){
  83. return function(value){
  84. return formatter(new Date(value));
  85. };
  86. }(formatter));
  87. },
  88.  
  89. values: function(min, max){
  90. var values = null;
  91.  
  92. if (this._isValidDate(min) && this._isValidDate(max))
  93. {
  94. values = $.ui.rangeSlider.prototype.values.apply(this, [min.valueOf(), max.valueOf()]);
  95. }else{
  96. values = $.ui.rangeSlider.prototype.values.apply(this, this._toArray(arguments));
  97. }
  98.  
  99. return {min: new Date(values.min), max: new Date(values.max)};
  100. },
  101.  
  102. min: function(min){
  103. if (this._isValidDate(min)){
  104. return new Date($.ui.rangeSlider.prototype.min.apply(this, [min.valueOf()]));
  105. }
  106.  
  107. return new Date($.ui.rangeSlider.prototype.min.apply(this));
  108. },
  109.  
  110. max: function(max){
  111. if (this._isValidDate(max)){
  112. return new Date($.ui.rangeSlider.prototype.max.apply(this, [max.valueOf()]));
  113. }
  114.  
  115. return new Date($.ui.rangeSlider.prototype.max.apply(this));
  116. },
  117.  
  118. bounds: function(min, max){
  119. var result;
  120.  
  121. if (this._isValidDate(min) && this._isValidDate(max)) {
  122. result = $.ui.rangeSlider.prototype.bounds.apply(this, [min.valueOf(), max.valueOf()]);
  123. } else {
  124. result = $.ui.rangeSlider.prototype.bounds.apply(this, this._toArray(arguments));
  125. }
  126.  
  127. return {min: new Date(result.min), max: new Date(result.max)};
  128. },
  129.  
  130. _isValidDate: function(value){
  131. return typeof value !== "undefined" && value instanceof Date;
  132. },
  133.  
  134. _toArray: function(argsObject){
  135. return Array.prototype.slice.call(argsObject);
  136. }
  137. });
  138. }
  139. }(jQuery));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement