diff --git a/cron/jquery-cron.js b/cron/jquery-cron.js index 02721cc..05f679a 100644 --- a/cron/jquery-cron.js +++ b/cron/jquery-cron.js @@ -90,9 +90,11 @@ closeEffect : "slide", hideOnMouseOut : true }, + displayPeriods: ['minute', 'hour', 'day', 'week', 'month', 'year'], url_set : undefined, customValues : undefined, onChange: undefined, // callback function each time value changes + displayTime: true, useGentleSelect: false }; @@ -139,23 +141,6 @@ str_opt_dow += "\n"; } - // options for period - var str_opt_period = ""; - var periods = ["minute", "hour", "day", "week", "month", "year"]; - for (var i = 0; i < periods.length; i++) { - str_opt_period += "\n"; - } - - // display matrix - var toDisplay = { - "minute" : [], - "hour" : ["mins"], - "day" : ["time"], - "week" : ["dow", "time"], - "month" : ["dom", "time"], - "year" : ["dom", "month", "time"] - }; - var combinations = { "minute" : /^(\*\s){4}\*$/, // "* * * * *" "hour" : /^\d{1,2}\s(\*\s){3}\*$/, // "? * * * *" @@ -296,6 +281,23 @@ // error checking if (hasError(this, o)) { return this; } + // options for period + var str_opt_period = ""; + var periods = o.displayPeriods + for (var i = 0; i < periods.length; i++) { + str_opt_period += "\n"; + } + + // display matrix + var toDisplay = { + "minute" : [], + "hour" : ["mins"], + "day" : o.displayTime ? ["time"] : [], + "week" : o.displayTime ? ["dow", "time"] : ["dow"], + "month" : o.displayTime ? ["dom", "time"] : ["dom"], + "year" : o.displayTime ? ["dom", "month", "time"] : ["dom", "month"] + }; + // ---- define select boxes in the right order ----- var block = [], custom_periods = "", cv = o.customValues; @@ -375,7 +377,7 @@ .end(); this.find("select").bind("change.cron-callback", event_handlers.somethingChanged); - this.data("options", o).data("block", block); // store options and block pointer + this.data("options", o).data("block", block).data("toDisplay", toDisplay); // store options and block pointer this.data("current_value", o.initial); // remember base value to detect changes return methods["value"].call(this, o.initial); // set initial value @@ -405,7 +407,7 @@ }; // update appropriate select boxes - var targets = toDisplay[t]; + var targets = this.data("toDisplay")[t]; for (var i = 0; i < targets.length; i++) { var tgt = targets[i]; if (tgt == "time") { @@ -435,6 +437,7 @@ periodChanged : function() { var root = $(this).data("root"); var block = root.data("block"), + toDisplay = root.data("toDisplay"), opt = root.data("options"); var period = $(this).val(); diff --git a/index.html b/index.html index 7180030..2fc6575 100644 --- a/index.html +++ b/index.html @@ -68,6 +68,16 @@ }, useGentleSelect: true }); + $('#example4').cron({ + displayPeriods: ['day', 'week', 'month'], + }); + $('#example5').cron({ + displayPeriods: ['day', 'week', 'month'], + displayTime: false, + onChange: function() { + $('#example5-val').text($(this).cron("value")); + } + }); }); @@ -354,6 +364,42 @@

Adding custom values

+ +

Removing default periods

+

+ If you do not need certain periods to be displayed in the drop down, you can specify which periods to + display with the displayPeriods option. +

+

+ For example, you can limit display periods to day, week, and month with the following: +

+$('#selector').cron({
+    displayPeriods: ['day', 'week', 'month']
+});
+    
+

+
+
+
+ +

Disabling time selection

+

+ Time selection can also be disabled with the displayTime option. This will only have an effect on the + periods that have time selection. +

+

+ For example, the following disables time selection: +

+$('#selector').cron({
+    displayPeriods: ['day', 'week', 'month'],
+    displayTime: false
+});
+    
+
+
+

Generated cron entry:

+
+

Methods

value