├── .gitignore ├── AUTHORS ├── LICENSE ├── README.md ├── cron ├── img │ ├── disk.png │ └── loading.gif ├── jquery-cron-min.js ├── jquery-cron.css └── jquery-cron.js ├── gentleSelect ├── img │ └── expand.png ├── jquery-gentleSelect-min.js ├── jquery-gentleSelect.css └── jquery-gentleSelect.js └── index.html /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.pyc 3 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Shawn Chin 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010 Shawn Chin 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # jQuery plugin: cron 2 | 3 | jquery-cron is a [jQuery] plugin for 4 | presenting a simplified interface for users to specify cron entries. 5 | 6 | Check out the [jquery-cron] website for more information. 7 | 8 | There is much to be done on the flexibility and robustness front, 9 | and we welcome contributions and bug fixes. Feel free to fork 10 | and send us pull requests! 11 | 12 | ## Dependencies 13 | 14 | * [jQuery] 15 | * [jquery-gentleSelect] (optional) 16 | 17 | ## Usage 18 | 19 | To use this plugin, one simply needs to load [jQuery] 20 | and the JS/CSS scripts for jquery-cron, then attach it an empty `
` 21 | on DOM ready: 22 | 23 | $(document).ready(function() { 24 | $('#selector').cron(); 25 | }); 26 | 27 | 28 | For more options, see the [jquery-cron] website. 29 | 30 | 31 | ## Others 32 | 33 | Copyright (c) 2010-2013, Shawn Chin. 34 | 35 | This project is licensed under the [MIT license]. 36 | 37 | [jQuery]: http://jquery.com "jQuery" 38 | [jquery-cron]: http://shawnchin.github.io/jquery-cron "jquery-cron" 39 | [jquery-gentleSelect]: http://shawnchin.github.io/jquery-gentleSelect "jquery-gentleSelect" 40 | [MIT License]: http://www.opensource.org/licenses/mit-license.php "MIT License" 41 | -------------------------------------------------------------------------------- /cron/img/disk.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shawnchin/jquery-cron/59a6e7c38b56ef9b58441364145b8ce26a9a50a3/cron/img/disk.png -------------------------------------------------------------------------------- /cron/img/loading.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shawnchin/jquery-cron/59a6e7c38b56ef9b58441364145b8ce26a9a50a3/cron/img/loading.gif -------------------------------------------------------------------------------- /cron/jquery-cron-min.js: -------------------------------------------------------------------------------- 1 | (function(e){var n={initial:"* * * * *",minuteOpts:{minWidth:100,itemWidth:30,columns:4,rows:undefined,title:"Minutes Past the Hour"},timeHourOpts:{minWidth:100,itemWidth:20,columns:2,rows:undefined,title:"Time: Hour"},domOpts:{minWidth:100,itemWidth:30,columns:undefined,rows:10,title:"Day of Month"},monthOpts:{minWidth:100,itemWidth:100,columns:2,rows:undefined,title:undefined},dowOpts:{minWidth:100,itemWidth:undefined,columns:undefined,rows:undefined,title:undefined},timeMinuteOpts:{minWidth:100,itemWidth:20,columns:4,rows:undefined,title:"Time: Minute"},effectOpts:{openSpeed:400,closeSpeed:400,openEffect:"slide",closeEffect:"slide",hideOnMouseOut:true},url_set:undefined,customValues:undefined,onChange:undefined,useGentleSelect:false};var y="";for(var u=0;u<60;u++){var t=(u<10)?"0":"";y+="\n"}var d="";for(var u=0;u<24;u++){var t=(u<10)?"0":"";d+="\n"}var v="";for(var u=1;u<32;u++){if(u==1||u==21||u==31){var c="st"}else{if(u==2||u==22){var c="nd"}else{if(u==3||u==23){var c="rd"}else{var c="th"}}}v+="\n"}var h="";var l=["January","February","March","April","May","June","July","August","September","October","November","December"];for(var u=0;u"+l[u]+"\n"}var s="";var g=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];for(var u=0;u"+g[u]+"\n"}var r="";var b=["minute","hour","day","week","month","year"];for(var u=0;u"+b[u]+"\n"}var p={minute:[],hour:["mins"],day:["time"],week:["dow","time"],month:["dom","time"],year:["dom","month","time"]};var w={minute:/^(\*\s){4}\*$/,hour:/^\d{1,2}\s(\*\s){3}\*$/,day:/^(\d{1,2}\s){2}(\*\s){2}\*$/,week:/^(\d{1,2}\s){2}(\*\s){2}\d{1,2}$/,month:/^(\d{1,2}\s){3}\*\s\*$/,year:/^(\d{1,2}\s){4}\*$/};function a(i){if(typeof i=="undefined"){return false}else{return true}}function q(i){return(!a(i)||typeof i=="object")}function z(A,j){if(a(j.customValues)){for(key in j.customValues){if(A==j.customValues[key]){return key}}}var E=/^((\d{1,2}|\*)\s){4}(\d{1,2}|\*)$/;if(typeof A!="string"||!E.test(A)){e.error("cron: invalid initial value");return undefined}var C=A.split(" ");var D=[0,0,1,1,0];var G=[59,23,31,12,6];for(var B=0;B=D[B]){continue}e.error("cron: invalid value found (col "+(B+1)+") in "+o.initial);return undefined}for(var H in w){if(w[H].test(A)){return H}}e.error("cron: valid but unsupported cron format. sorry.");return undefined}function f(j,i){if(!a(z(i.initial,i))){return true}if(!q(i.customValues)){return true}if(a(i.customValues)){for(key in i.customValues){if(w.hasOwnProperty(key)){e.error("cron: reserved keyword '"+key+"' should not be used as customValues key.");return true}}}return false}function k(B){var i=B.data("block");var j=hour=day=month=dow="*";var A=i.period.find("select").val();switch(A){case"minute":break;case"hour":j=i.mins.find("select").val();break;case"day":j=i.time.find("select.cron-time-min").val();hour=i.time.find("select.cron-time-hour").val();break;case"week":j=i.time.find("select.cron-time-min").val();hour=i.time.find("select.cron-time-hour").val();dow=i.dow.find("select").val();break;case"month":j=i.time.find("select.cron-time-min").val();hour=i.time.find("select.cron-time-hour").val();day=i.dom.find("select").val();break;case"year":j=i.time.find("select.cron-time-min").val();hour=i.time.find("select.cron-time-hour").val();day=i.dom.find("select").val();month=i.month.find("select").val();break;default:return A}return[j,hour,day,month,dow].join(" ")}var x={init:function(i){var G=i?i:{};var B=e.extend([],n,G);var j=e.extend({},n.effectOpts,G.effectOpts);e.extend(B,{minuteOpts:e.extend({},n.minuteOpts,j,G.minuteOpts),domOpts:e.extend({},n.domOpts,j,G.domOpts),monthOpts:e.extend({},n.monthOpts,j,G.monthOpts),dowOpts:e.extend({},n.dowOpts,j,G.dowOpts),timeHourOpts:e.extend({},n.timeHourOpts,j,G.timeHourOpts),timeMinuteOpts:e.extend({},n.timeMinuteOpts,j,G.timeMinuteOpts)});if(f(this,B)){return this}var C=[],A="",D=B.customValues;if(a(D)){for(var F in D){A+="\n"}}C.period=e("Every ").appendTo(this).data("root",this);var E=C.period.find("select");E.bind("change.cron",m.periodChanged).data("root",this);if(B.useGentleSelect){E.gentleSelect(j)}C.dom=e(" on the ").appendTo(this).data("root",this);E=C.dom.find("select").data("root",this);if(B.useGentleSelect){E.gentleSelect(B.domOpts)}C.month=e(" of ").appendTo(this).data("root",this);E=C.month.find("select").data("root",this);if(B.useGentleSelect){E.gentleSelect(B.monthOpts)}C.mins=e(" at minutes past the hour ").appendTo(this).data("root",this);E=C.mins.find("select").data("root",this);if(B.useGentleSelect){E.gentleSelect(B.minuteOpts)}C.dow=e(" on ").appendTo(this).data("root",this);E=C.dow.find("select").data("root",this);if(B.useGentleSelect){E.gentleSelect(B.dowOpts)}C.time=e(" at :" + custom_periods 310 | + str_opt_period + " ") 311 | .appendTo(this) 312 | .data("root", this); 313 | 314 | var select = block["period"].find("select"); 315 | select.bind("change.cron", event_handlers.periodChanged) 316 | .data("root", this); 317 | if (o.useGentleSelect) select.gentleSelect(eo); 318 | 319 | block["dom"] = $("" 320 | + " on the ") 322 | .appendTo(this) 323 | .data("root", this); 324 | 325 | select = block["dom"].find("select").data("root", this); 326 | if (o.useGentleSelect) select.gentleSelect(o.domOpts); 327 | 328 | block["month"] = $("" 329 | + " of ") 331 | .appendTo(this) 332 | .data("root", this); 333 | 334 | select = block["month"].find("select").data("root", this); 335 | if (o.useGentleSelect) select.gentleSelect(o.monthOpts); 336 | 337 | block["mins"] = $("" 338 | + " at minutes past the hour ") 340 | .appendTo(this) 341 | .data("root", this); 342 | 343 | select = block["mins"].find("select").data("root", this); 344 | if (o.useGentleSelect) select.gentleSelect(o.minuteOpts); 345 | 346 | block["dow"] = $("" 347 | + " on ") 349 | .appendTo(this) 350 | .data("root", this); 351 | 352 | select = block["dow"].find("select").data("root", this); 353 | if (o.useGentleSelect) select.gentleSelect(o.dowOpts); 354 | 355 | block["time"] = $("" 356 | + " at : .... 20 | * 21 | */ 22 | (function($) { 23 | 24 | var defaults = { 25 | minWidth : 100, // only applies if columns and itemWidth not set 26 | itemWidth : undefined, 27 | columns : undefined, 28 | rows : undefined, 29 | title : undefined, 30 | prompt : "Make A Selection", 31 | maxDisplay: 0, // set to 0 for unlimited 32 | openSpeed : 400, 33 | closeSpeed : 400, 34 | openEffect : "slide", 35 | closeEffect : "slide", 36 | hideOnMouseOut : true 37 | } 38 | 39 | function defined(obj) { 40 | if (typeof obj == "undefined") { return false; } 41 | else { return true; } 42 | } 43 | 44 | function hasError(c, o) { 45 | if (defined(o.columns) && defined(o.rows)) { 46 | $.error("gentleSelect: You cannot supply both 'rows' and 'columns'"); 47 | return true; 48 | } 49 | if (defined(o.columns) && !defined(o.itemWidth)) { 50 | $.error("gentleSelect: itemWidth must be supplied if 'columns' is specified"); 51 | return true; 52 | } 53 | if (defined(o.rows) && !defined(o.itemWidth)) { 54 | $.error("gentleSelect: itemWidth must be supplied if 'rows' is specified"); 55 | return true; 56 | } 57 | if (!defined(o.openSpeed) || typeof o.openSpeed != "number" && 58 | (typeof o.openSpeed == "string" && (o.openSpeed != "slow" && o.openSpeed != "fast"))) { 59 | $.error("gentleSelect: openSpeed must be an integer or \"slow\" or \"fast\""); 60 | return true; 61 | } 62 | if (!defined(o.closeSpeed) || typeof o.closeSpeed != "number" && 63 | (typeof o.closeSpeed == "string" && (o.closeSpeed != "slow" && o.closeSpeed != "fast"))) { 64 | $.error("gentleSelect: closeSpeed must be an integer or \"slow\" or \"fast\""); 65 | return true; 66 | } 67 | if (!defined(o.openEffect) || (o.openEffect != "fade" && o.openEffect != "slide")) { 68 | $.error("gentleSelect: openEffect must be either 'fade' or 'slide'!"); 69 | return true; 70 | } 71 | if (!defined(o.closeEffect)|| (o.closeEffect != "fade" && o.closeEffect != "slide")) { 72 | $.error("gentleSelect: closeEffect must be either 'fade' or 'slide'!"); 73 | return true; 74 | } 75 | if (!defined(o.hideOnMouseOut) || (typeof o.hideOnMouseOut != "boolean")) { 76 | $.error("gentleSelect: hideOnMouseOut must be supplied and either \"true\" or \"false\"!"); 77 | return true; 78 | } 79 | return false; 80 | } 81 | 82 | function optionOverrides(c, o) { 83 | if (c.attr("multiple")) { 84 | o.hideOnMouseOut = true; // must be true or dialog will never hide 85 | } 86 | } 87 | 88 | function getSelectedAsText(elemList, opts) { 89 | // If no items selected, return prompt 90 | if (elemList.length < 1) { return opts.prompt; } 91 | 92 | // Truncate if exceed maxDisplay 93 | if (opts.maxDisplay != 0 && elemList.length > opts.maxDisplay) { 94 | var arr = elemList.slice(0, opts.maxDisplay).map(function(){return $(this).text();}); 95 | arr.push("..."); 96 | } else { 97 | var arr = elemList.map(function(){return $(this).text();}); 98 | } 99 | return arr.get().join(", "); 100 | } 101 | 102 | var methods = { 103 | init : function(options) { 104 | var o = $.extend({}, defaults, options); 105 | 106 | if (hasError(this, o)) { return this; }; // check for errors 107 | optionOverrides(this, o); // 108 | this.hide(); // hide original select box 109 | 110 | // initialise to replace select box 111 | label_text = getSelectedAsText(this.find(":selected"), o); 112 | var label = $("" + label_text + "") 113 | .insertBefore(this) 114 | .bind("mouseenter.gentleselect", event_handlers.labelHoverIn) 115 | .bind("mouseleave.gentleselect", event_handlers.labelHoverOut) 116 | .bind("click.gentleselect", event_handlers.labelClick) 117 | .data("root", this); 118 | this.data("label", label) 119 | .data("options", o); 120 | 121 | // generate list of options 122 | var ul = $("
    "); 123 | this.find("option").each(function() { 124 | var li = $("
  • " + $(this).text() + "
  • ") 125 | .data("value", $(this).attr("value")) 126 | .data("name", $(this).text()) 127 | .appendTo(ul); 128 | if ($(this).attr("selected")) { li.addClass("selected"); } 129 | }); 130 | 131 | // build dialog box 132 | var dialog = $("
    ") 133 | .append(ul) 134 | .insertAfter(label) 135 | .bind("click.gentleselect", event_handlers.dialogClick) 136 | .bind("mouseleave.gentleselect", event_handlers.dialogHoverOut) 137 | .data("label", label) 138 | .data("root", this); 139 | this.data("dialog", dialog); 140 | 141 | // if to be displayed in columns 142 | if (defined(o.columns) || defined(o.rows)) { 143 | 144 | // Update CSS 145 | ul.css("float", "left") 146 | .find("li").width(o.itemWidth).css("float","left"); 147 | 148 | var f = ul.find("li:first"); 149 | var actualWidth = o.itemWidth 150 | + parseInt(f.css("padding-left")) 151 | + parseInt(f.css("padding-right")); 152 | var elemCount = ul.find("li").length; 153 | if (defined(o.columns)) { 154 | var cols = parseInt(o.columns); 155 | var rows = Math.ceil(elemCount / cols); 156 | } else { 157 | var rows = parseInt(o.rows); 158 | var cols = Math.ceil(elemCount / rows); 159 | } 160 | dialog.width(actualWidth * cols); 161 | 162 | // add padding 163 | for (var i = 0; i < (rows * cols) - elemCount; i++) { 164 | $("
  •  
  • ").appendTo(ul); 165 | } 166 | 167 | // reorder elements 168 | var ptr = []; 169 | var idx = 0; 170 | ul.find("li").each(function() { 171 | if (idx < rows) { 172 | ptr[idx] = $(this); 173 | } else { 174 | var p = idx % rows; 175 | $(this).insertAfter(ptr[p]); 176 | ptr[p] = $(this); 177 | } 178 | idx++; 179 | }); 180 | } else if (typeof o.minWidth == "number") { 181 | dialog.css("min-width", o.minWidth); 182 | } 183 | 184 | if (defined(o.title)) { 185 | $("
    " + o.title + "
    ").prependTo(dialog); 186 | } 187 | 188 | // ESC key should hide all dialog boxes 189 | $(document).bind("keyup.gentleselect", event_handlers.keyUp); 190 | 191 | return this; 192 | }, 193 | 194 | // if select box was updated externally, we need to bring everything 195 | // else up to speed. 196 | update : function() { 197 | var opts = this.data("options"); 198 | 199 | // Update li with selected data 200 | var v = (this.attr("multiple")) ? this.val() : [this.val()]; 201 | $("li", this.data("dialog")).each(function() { 202 | var $li = $(this); 203 | var isSelected = ($.inArray($li.data("value"), v) != -1); 204 | $li.toggleClass("selected", isSelected); 205 | }); 206 | 207 | // Update label 208 | var label = getSelectedAsText(this.find(":selected"), opts); 209 | this.data("label").text(label); 210 | 211 | return this; 212 | } 213 | }; 214 | 215 | var event_handlers = { 216 | 217 | labelHoverIn : function() { 218 | $(this).addClass('gentleselect-label-highlight'); 219 | }, 220 | 221 | labelHoverOut : function() { 222 | $(this).removeClass('gentleselect-label-highlight'); 223 | }, 224 | 225 | labelClick : function() { 226 | var $this = $(this); 227 | var pos = $this.position(); 228 | var root = $this.data("root"); 229 | var opts = root.data("options"); 230 | var dialog = root.data("dialog") 231 | .css("top", pos.top + $this.height()) 232 | .css("left", pos.left + 1); 233 | if (opts.openEffect == "fade") { 234 | dialog.fadeIn(opts.openSpeed); 235 | } else { 236 | dialog.slideDown(opts.openSpeed); 237 | } 238 | }, 239 | 240 | dialogHoverOut : function() { 241 | var $this = $(this); 242 | if ($this.data("root").data("options").hideOnMouseOut) { 243 | $this.hide(); 244 | } 245 | }, 246 | 247 | dialogClick : function(e) { 248 | var clicked = $(e.target); 249 | var $this = $(this); 250 | var root = $this.data("root"); 251 | var opts = root.data("options"); 252 | if (!root.attr("multiple")) { 253 | if (opts.closeEffect == "fade") { 254 | $this.fadeOut(opts.closeSpeed); 255 | } else { 256 | $this.slideUp(opts.closeSpeed); 257 | } 258 | } 259 | 260 | if (clicked.is("li") && !clicked.hasClass("gentleselect-dummy")) { 261 | var value = clicked.data("value"); 262 | var name = clicked.data("name"); 263 | var label = $this.data("label") 264 | 265 | if ($this.data("root").attr("multiple")) { 266 | clicked.toggleClass("selected"); 267 | var s = $this.find("li.selected"); 268 | label.text(getSelectedAsText(s, opts)); 269 | var v = s.map(function(){ return $(this).data("value"); }); 270 | // update actual selectbox and trigger change event 271 | root.val(v.get()).trigger("change"); 272 | } else { 273 | $this.find("li.selected").removeClass("selected"); 274 | clicked.addClass("selected"); 275 | label.text(clicked.data("name")); 276 | // update actual selectbox and trigger change event 277 | root.val(value).trigger("change"); 278 | } 279 | } 280 | }, 281 | 282 | keyUp : function(e) { 283 | if (e.keyCode == 27 ) { // ESC 284 | $(".gentleselect-dialog").hide(); 285 | } 286 | } 287 | }; 288 | 289 | $.fn.gentleSelect = function(method) { 290 | if (methods[method]) { 291 | return methods[method].apply(this, Array.prototype.slice.call(arguments, 1)); 292 | } else if (typeof method === 'object' || ! method) { 293 | return methods.init.apply(this, arguments); 294 | } else { 295 | $.error( 'Method ' + method + ' does not exist on jQuery.gentleSelect' ); 296 | } 297 | }; 298 | 299 | 300 | })(jQuery); 301 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | jquery-cron : a jQuery plugin 6 | 7 | 8 | 9 | 10 | 11 | 12 | 30 | 73 | 74 | 75 |
    76 |

    jQuery plugin: cron

    77 | 78 |

    Introduction

    79 |

    80 | jquery-cron is a jQuery plugin for 81 | presenting a simplified interface for users to specify cron entries. 82 |

    83 | 84 |

    85 | Instead of having to specify the five elements of a cron entry (minute, 86 | hour, day of month, month, day of week), jquery-cron provides a simpler 87 | interface for users to enter the more common combinations. For example: 88 |

    89 | 90 |
    91 |
    92 |

    Generated cron entry:

    93 |
    94 | 95 | Or, with useGentleSelect enabled: 96 | 97 |
    98 |
    99 |

    Generated cron entry:

    100 |
    101 | 102 |

    103 | In addition, the customValues 104 | option can be used to provide a list of canned cron entries. This allow users to 105 | cater for common use cases as well as enable more complex cron entries. 106 |

    107 | 108 |

    109 | There is much room for improvements and we welcome contributions 110 | and bug fixes. Feel free to fork the project 111 | and send us pull requests! 112 |

    113 | 114 |

    Download

    115 | 119 | 120 |

    TODO

    121 |
      122 |
    • Support multiple entries per field
    • 123 |
    • implement option to add CSS class (simplify customisation)
    • 124 |
    • make the AJAX POST functionality more generic
    • 125 |
    126 |

    Usage

    127 | 128 |

    129 | To use this plugin, one simply needs to load jQuery 130 | and the JS/CSS scripts for jquery-cron: 131 |

    132 | 133 |
    134 | <script type="text/javascript"
    135 |         src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
    136 | 
    137 | <script type="text/javascript" src="cron/jquery-cron.js"></script>
    138 | 
    139 | <link type="text/css" href="cron/jquery-cron.css" rel="stylesheet" />
    140 | 
    141 |

    If used with useGentleSelect you'll also need:

    142 |
    143 | <script type="text/javascript" src="gentleSelect/jquery-gentleSelect.js"></script>
    144 | <link type="text/css" href="gentleSelect/jquery-gentleSelect.css" rel="stylesheet" />
    145 | 
    146 |

    147 | then attach it to an empty <div> on DOM ready: 148 |

    149 |
    150 | <script type="text/javascript">
    151 | $(document).ready(function() {
    152 |     $('#selector').cron(); // apply cron with default options
    153 | });
    154 | </script>
    155 | <!--- somewhere within <body> -->
    156 | <div id='selector'></div>
    157 | 
    158 | 159 |

    160 | There are several ways one can utilise the generated cron entry: 161 |

      162 |
    1. 163 | Interrogating the object : 164 | See value method and onChange option. 165 |
    2. 166 | 167 |
    3. 168 | AJAX POST : 169 | See the url_set option. 170 |
    4. 171 | 172 |
    5. 173 | embed in existing form (not recommended) : 174 | The UI is rendered as a series of <select> boxes within the <div>. 175 | Therefore, one can (in theory) embed the whole <div> within a form and on submission 176 | interrogate the appropriate fields. The generated fiels will have the names: 177 |
        178 |
      • cron-period : possible values are "minute, hour, day, week, month, year"
      • 179 |
      • cron-mins : only relevant when cron-period = "hour"
      • 180 |
      • cron-time-hour : only relevant when cron-period = "day, week, month, year"
      • 181 |
      • cron-time-min : only relevant when cron-period = "day, week, month, year"
      • 182 |
      • cron-dom : only relevant when cron-period = "month, year"
      • 183 |
      • cron-month : only relevant when cron-period = "year"
      • 184 |
      • cron-dow : only relevant when cron-period = "week"
      • 185 |
      186 |
    6. 187 |
    188 |

    189 | 190 |

    Options

    191 | 192 |

    initial

    193 |

    194 | The initial option allows you the set the initial cron value. If an initialll value is not set, 195 | a default value of "* * * * *" is used. 196 |

    197 | 198 |

    199 | After the object has been set up, you can still update the value using 200 | the value method. 201 |

    202 | 203 |

    url_set

    204 |

    205 | You can asynchronously submit the current value to you backend script by specifying then 206 | the URL using the url_set option. 207 |

    208 | 209 |

    210 | If this option is set, a "save" icon will appear when changes are made allowing users 211 | to submit their changes to the backend for processing. 212 |

    213 | 214 |

    215 | jquery-cron will submit the values {"cron": ??} using a POST request via AJAX. 216 | If a non-error HTTP response is received, the save is considered to be successfule and 217 | the "save" icon will be hidden until the next change is made. 218 |

    219 | 220 | 221 |

    onChange

    222 |

    223 | You can set a callback function using the onChange option. The function will be called 224 | each time the value changes. 225 | For instance, the example in the introduction is implemented as using: 226 |

    227 | 228 |
    229 | $('#example1').cron({
    230 |     initial: "42 3 * * 5",
    231 |     onChange: function() {
    232 |         $('#example1-val').text($(this).cron("value"));
    233 |     }
    234 | });
    235 | 236 |

    useGentleSelect

    237 |

    Tells the plugin to use gentleSelect to show dropdown options instead of the default select inputs. 238 |

    239 | 240 |
    241 | $('#example1').cron({
    242 |     initial: "42 3 * * 5",
    243 |     onChange: function() {
    244 |         $('#example1-val').text($(this).cron("value"));
    245 |     },
    246 |     useGentleSelect: true // default: false
    247 | });
    248 | 249 |
    250 |
    251 |

    Generated cron entry:

    252 |
    253 | 254 |

    effectOpts

    255 |

    256 | You can change the effects used when displaying/hiding the selection menu by changing the 257 | parameters in effectOpts. These values will be used as the default options for gentleSelect. 258 |

    259 | 260 |

    261 | The following parameters can be set: 262 |

    269 |

    270 | 271 |

    272 | For example, the following uses the fade effect with a slower animation speed: 273 |

    274 | 275 |

    276 |

    277 |
    278 | $('#example2').cron({
    279 |     initial: "42 3 * * 5",
    280 |     effectOpts: {
    281 |         openEffect: "fade",
    282 |         openSpeed: "slow"
    283 |     }
    284 | });
    285 |

    286 | 287 |

    Customising individual select boxes

    288 |

    289 | It is possible to customise each of the generated select boxes by sending additional 290 | options to its instance of gentleSelect. 291 | All attributes 292 | support by jquery-gentleSelect can be specified. 293 |

    294 | 295 |

    296 | The following are the options to use for each select menu: 297 |

      298 |
    • minuteOpts - Minutes past the hour (hourly)
    • 299 |
    • timeMinuteOpts - Time:Minute (daily, weekly, monthly, yearly)
    • 300 |
    • timeHourOpts - Time:Hour (daily, weekly, monthly, yearly)
    • 301 |
    • dowOpts - Day of week (weekly)
    • 302 |
    • domOpts - Day of month (monthly, yearly)
    • 303 |
    • monthOpts - Month (yearly)
    • 304 |
    305 |

    306 | 307 |

    308 | For example, to change the title of the "Day of Month" select box which appears for monthly and yearly crons: 309 |

    310 | $('#selector').cron({
    311 |     initial: "42 3 * * 5",
    312 |     domOpts: {
    313 |         title: "N-th day of the month"
    314 |     }
    315 | });
    316 | 
    317 | 318 |

    319 | 320 |

    Adding custom values

    321 |

    322 | Additional entries can be included in the period selection using the customValues 323 | option. This allows you to specify more complex cron entries that is not currently expressible 324 | using the current setup. 325 |

    326 |

    327 | For example, the following adds two additional entries to the selection: 328 |

    329 | $('#selector').cron({
    330 |     initial: "*/5 * * * *",
    331 |     customValues: {
    332 |         "5 Minutes" : "*/5 * * * *",
    333 |         "2 Hours on Weekends" : "0 */2 * * 5,6"
    334 |     }
    335 | });
    336 | 
    337 |

    338 | 339 |
    340 |
    341 |

    Generated cron entry:

    342 |
    343 | 344 |

    345 | Caveats: 346 |

      347 |
    • 348 | At present, cron entries specified in customValues are not validated. 349 | It is down to the implementer to ensure that provided values are as required. 350 |
    • 351 |
    • 352 | The value method can be used to retrieve 353 | custom cron values. However, it cannot be used to set custom values. 354 |
    • 355 |
    356 |

    357 |

    Methods

    358 |

    value

    359 |

    360 | The value method enables you to set/get the current cron value. 361 |

    362 | 363 |
    364 | // Initialise a cron objecy
    365 | var cron_field = $('#selector').cron();
    366 | 
    367 | // Updating the value of an existing cron object
    368 | cron_field.cron("value", "12 23 * * *");
    369 | 
    370 | // calling the method with the extra argument returns the current value
    371 | var current_value = cron_field.cron("value")
    372 | 
    373 | 374 |
    375 | 381 | Fork me on GitHub 382 | 383 | 384 | 385 | --------------------------------------------------------------------------------