Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding ability to exclude periods from the cron period selection #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cron/jquery-cron-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 9 additions & 7 deletions cron/jquery-cron.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

var defaults = {
initial : "* * * * *",
periods: ["minute", "hour", "day", "week", "month", "year"],
minuteOpts : {
minWidth : 100, // only applies if columns and itemWidth not set
itemWidth : 30,
Expand Down Expand Up @@ -139,13 +140,6 @@
str_opt_dow += "<option value='"+i+"'>" + days[i] + "</option>\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 += "<option value='"+periods[i]+"'>" + periods[i] + "</option>\n";
}

// display matrix
var toDisplay = {
"minute" : [],
Expand Down Expand Up @@ -285,6 +279,7 @@
var o = $.extend([], defaults, options);
var eo = $.extend({}, defaults.effectOpts, options.effectOpts);
$.extend(o, {
periods : options.periods && options.periods.length > 0 ? options.periods : defaults.periods,
minuteOpts : $.extend({}, defaults.minuteOpts, eo, options.minuteOpts),
domOpts : $.extend({}, defaults.domOpts, eo, options.domOpts),
monthOpts : $.extend({}, defaults.monthOpts, eo, options.monthOpts),
Expand All @@ -295,6 +290,13 @@

// error checking
if (hasError(this, o)) { return this; }

// options for period
var str_opt_period = "";
var periods = o.periods;
$.each(periods, function (index, value) {
str_opt_period += "<option value='" + value + "'>" + value + "</option>\n";
})

// ---- define select boxes in the right order -----

Expand Down
24 changes: 24 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@
},
useGentleSelect: true
});
$('#example5').cron({
periods: ["day", "year"],
useGentleSelect: true
});
});
</script>
</head>
Expand Down Expand Up @@ -354,6 +358,26 @@ <h3 id='option-customvalues'>Adding custom values</h3>
</li>
</ul>
</p>

<h3 id='option-customvalues'>Specify periods to display</h3>
<p>
The list of selectable cron periods can be specified using the <tt>periods</tt>
option. This allows you to specify an array of periods to display.
</p>
<p>
For example, the following displays only day and year period selections:
<pre>
$('#selector').cron({
periods: ["day", "year"]
});
</pre>
</p>

<div class='example'>
<div id='example5'></div>
<p><span class='example-text' id='example5-val'></span></p>
</div>

<h2>Methods</h2>
<h3 id='method-value'>value</h3>
<p>
Expand Down