Skip to content

Commit 983847e

Browse files
committed
Add new mode: custombox - like customflip, but based on the android version
1 parent f982c63 commit 983847e

7 files changed

+274
-10
lines changed

build/build.py

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
'../js/jqm-datebox.mode.flipbox.js',
2424
'../js/jqm-datebox.mode.slidebox.js',
2525
'../js/jqm-datebox.mode.customflip.js',
26+
'../js/jqm-datebox.mode.custombox.js',
2627
]
2728
files = {}
2829

demos/mode/custombox.html

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
<title>jQueryMobile - DateBox Demos</title>
7+
<link rel="stylesheet" href="http://code.jquery.com/mobile/latest/jquery.mobile.css" />
8+
<link type="text/css" href="http://dev.jtsage.com/cdn/datebox/latest/jqm-datebox.min.css" rel="stylesheet" />
9+
<link type="text/css" href="http://dev.jtsage.com/cdn/simpledialog/latest/jquery.mobile.simpledialog.min.css" rel="stylesheet" />
10+
<link type="text/css" href="http://dev.jtsage.com/jQM-DateBox/css/demos.css" rel="stylesheet" />
11+
12+
<!-- NOTE: Script load order is significant! -->
13+
14+
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.js"></script>
15+
<script type="text/javascript" src="http://code.jquery.com/mobile/latest/jquery.mobile.js"></script>
16+
<script type="text/javascript" src="http://dev.jtsage.com/jquery.mousewheel.min.js"></script>
17+
<script type="text/javascript" src="http://dev.jtsage.com/cdn/datebox/latest/jqm-datebox.core.min.js"></script>
18+
<script type="text/javascript" src="http://dev.jtsage.com/cdn/datebox/latest/jqm-datebox.mode.custombox.min.js"></script>
19+
20+
<script type="text/javascript" src="http://dev.jtsage.com/cdn/simpledialog/latest/jquery.mobile.simpledialog.min.js"></script>
21+
<script type="text/javascript" src="../extras.js"></script>
22+
<script type="text/javascript" src="http://dev.jtsage.com/gpretty/prettify.js"></script>
23+
<link type="text/css" href="http://dev.jtsage.com/gpretty/prettify.css" rel="stylesheet" />
24+
<script type="text/javascript">
25+
$('div').live('pagecreate', function() {
26+
prettyPrint()
27+
});
28+
</script>
29+
30+
</head>
31+
<body>
32+
<div data-role="page" data-theme="c" id="slideIndex">
33+
<div data-role="header" data-position="fixed">
34+
<h1>jQueryMobile - DateBox</h1>
35+
<a href="../../" rel="external" data-icon="home" data-iconpos="notext">Home</a>
36+
</div>
37+
<div data-role="content" data-theme="c">
38+
<div data-role="collapsible-set" data-mini="true" data-theme="c" data-content-theme="d">
39+
<div data-role="collapsible" data-collapsed="false">
40+
<h2>Custom Box Mode</h2>
41+
<p>Using the custom box mode is as simple as setting the 'mode' option to "custombox", and defining some data.</p>
42+
<script type="text/javascript">
43+
jQuery.extend(jQuery.mobile.datebox.prototype.options, {
44+
'customData': [
45+
{'input': true, 'name':'Letter', 'data':['a','b','c','d','e']},
46+
{'input': true, 'name':'Text', 'data':['some','bull','shtuff','here']}
47+
],
48+
'useNewStyle': true,
49+
'overrideStyleClass': 'ui-icon-dice'
50+
});
51+
</script>
52+
<style>
53+
.ui-icon-dice { background-image: url('../../img/dice.png') !important; background-repeat: no-repeat; background-position: 99% 50%; }
54+
</style>
55+
56+
<div data-role="fieldcontain">
57+
<label for="cf">Custom</label>
58+
<input name="cf" type="date" data-role="datebox" id="cf" data-options='{"mode": "custombox"}' />
59+
</div>
60+
<p>Note: this demo show the "new" style, and a custom icon style. Source below explains their use - basically, it just applies the *extra* style - override background-image to get rid of the calendar icon</p>
61+
62+
<pre class="prettyprint">
63+
&lt;script type="text/javascript"&gt;
64+
jQuery.extend(jQuery.mobile.datebox.prototype.options, {
65+
'customData': [
66+
{'input': true, 'name':'Letter', 'data':['a','b','c','d','e']},
67+
{'input': true, 'name':'Text', 'data':['some','bull','shtuff','here']}
68+
],
69+
'useNewStyle': true,
70+
'overrideStyleClass': 'ui-icon-dice'
71+
});
72+
&lt;/script&gt;
73+
&lt;style&gt;
74+
.ui-icon-dice { background-image: url('../../img/dice.png') !important; background-repeat: no-repeat; background-position: 99% 50%; }
75+
&lt;/style&gt;
76+
77+
&lt;div data-role="fieldcontain"&gt;
78+
&lt;label for="cf"&gt;Custom&lt;/label&gt;
79+
&lt;input name="cf" type="date" data-role="datebox" id="cf" data-options='{"mode": "custombox"}' /&gt;
80+
&lt;/div&gt;
81+
</pre>
82+
83+
</div>
84+
<div data-role="collapsible">
85+
<h2>Theme Options</h2>
86+
<ul data-role="listview" data-inset="true">
87+
<li><h3>themeOptPick</h3><p>Theme swatch for choosen (centered) option</p></li>
88+
<li><h3>themeOpt</h3><p>Theme swatch for other date elements</p></li>
89+
</ul>
90+
</div>
91+
<div data-role="collapsible">
92+
<h2>Data</h2>
93+
<p>The data structure is pretty rigid. It is an array, consisting of objects like the following:</p>
94+
<pre class="prettyprint">{'input': Boolean, 'name': 'The label for the roller', 'data': ['an','array','of','values']}</pre>
95+
<p>If you don't wish to use labels, name must still be present - just leave it an empty string. "Values" can be any valid HTML - customflipbox doesn't care in the least</p>
96+
<p>'input', when set true, lets custombox know the data list is simple strings - otherwise, it will encase in a DIV instead, to preserve formatting.</p>
97+
<p>Return values are a comma-delimeted string of INDEXES. Your data will *never* be passed to the input, it's up to you to interpet it on the backend.</p>
98+
<p>Note: each data list is probably limited to 10 items. If you need more, send me an e-mail, and I'll walk you though raising the limit.</p>
99+
</div>
100+
</div>
101+
102+
</div>
103+
<div data-role="footer" data-position="fixed">
104+
</div>
105+
</div>
106+
</html>

demos/mode/customflipbox.html

+6-5
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ <h2>Custom Flip Mode</h2>
4242
<script type="text/javascript">
4343
jQuery.extend(jQuery.mobile.datebox.prototype.options, {
4444
'customData': [
45-
{'name':'Letter', 'data':['a','b','c','d','e']},
46-
{'name':'Text', 'data':['some','bull','shtuff','here']}
45+
{'input': true, 'name':'Letter', 'data':['a','b','c','d','e']},
46+
{'input': true, 'name':'Text', 'data':['some','bull','shtuff','here']}
4747
],
4848
'useNewStyle': true,
4949
'overrideStyleClass': 'ui-icon-dice'
@@ -63,8 +63,8 @@ <h2>Custom Flip Mode</h2>
6363
&lt;script type="text/javascript"&gt;
6464
jQuery.extend(jQuery.mobile.datebox.prototype.options, {
6565
'customData': [
66-
{'name':'Letter', 'data':['a','b','c','d','e']},
67-
{'name':'Text', 'data':['some','bull','shtuff','here']}
66+
{'input': true, 'name':'Letter', 'data':['a','b','c','d','e']},
67+
{'input': true, 'name':'Text', 'data':['some','bull','shtuff','here']}
6868
],
6969
'useNewStyle': true,
7070
'overrideStyleClass': 'ui-icon-dice'
@@ -91,8 +91,9 @@ <h2>Theme Options</h2>
9191
<div data-role="collapsible">
9292
<h2>Data</h2>
9393
<p>The data structure is pretty rigid. It is an array, consisting of objects like the following:</p>
94-
<pre class="prettyprint">{'name': 'The label for the roller', 'data': ['an','array','of','values']}</pre>
94+
<pre class="prettyprint">{'input': Boolean, 'name': 'The label for the roller', 'data': ['an','array','of','values']}</pre>
9595
<p>If you don't wish to use labels, name must still be present - just leave it an empty string. "Values" can be any valid HTML - customflipbox doesn't care in the least</p>
96+
<p>'input' is not used in this mode, it need not be present.</p>
9697
<p>Return values are a comma-delimeted string of INDEXES. Your data will *never* be passed to the input, it's up to you to interpet it on the backend.</p>
9798
<p>Note: each data list is probably limited to 10 items. If you need more, send me an e-mail, and I'll walk you though raising the limit.</p>
9899
</div>

index.html

+6-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<script type="text/javascript" src="http://dev.jtsage.com/cdn/datebox/latest/jqm-datebox.mode.durationbox.min.js"></script>
2222
<script type="text/javascript" src="http://dev.jtsage.com/cdn/datebox/latest/jqm-datebox.mode.slidebox.min.js"></script>
2323
<script type="text/javascript" src="http://dev.jtsage.com/cdn/datebox/latest/jqm-datebox.mode.customflip.min.js"></script>
24+
<script type="text/javascript" src="http://dev.jtsage.com/cdn/datebox/latest/jqm-datebox.mode.custombox.min.js"></script>
2425
<script type="text/javascript" src="http://dev.jtsage.com/cdn/datebox/i18n/jquery.mobile.datebox.i18n.en_US.utf8.js"></script>
2526

2627
<script type="text/javascript" src="http://dev.jtsage.com/cdn/simpledialog/latest/jquery.mobile.simpledialog.min.js"></script>
@@ -81,8 +82,10 @@ <h3>Modes Available</h3>
8182
<input name="mode4" id="mode4" type="text" data-role="datebox" data-options='{"mode":"slidebox", "useNewStyle":true}' />
8283
<label for="mode5">DurationBox</label>
8384
<input name="mode5" id="mode5" type="text" data-role="datebox" data-options='{"mode":"durationbox", "useNewStyle":true}' />
84-
<label for="mode6">CustomFlip</label>
85-
<input name="mode6" id="mode6" type="text" data-role="datebox" data-options='{"mode":"customflip", "useNewStyle":true}' />
85+
<label for="mode6">CustomBox</label>
86+
<input name="mode6" id="mode6" type="text" data-role="datebox" data-options='{"mode":"custombox", "useNewStyle":true}' />
87+
<label for="mode7">CustomFlip</label>
88+
<input name="mode7" id="mode7" type="text" data-role="datebox" data-options='{"mode":"customflip", "useNewStyle":true}' />
8689
</div>
8790
</div>
8891
<div data-role="collapsible">
@@ -95,6 +98,7 @@ <h3>Mode Options w/ Demos</h3>
9598
<li><a href="demos/mode/timebox.html">Time Mode</a></li>
9699
<li><a href="demos/mode/timeflipbox.html">Time Flip Mode</a></li>
97100
<li><a href="demos/mode/durationbox.html">Duration Mode</a></li>
101+
<li><a href="demos/mode/custombox.html">Custom Box Mode (ext)</a></li>
98102
<li><a href="demos/mode/customflipbox.html">Custom Flip Mode (ext)</a></li>
99103
</ul>
100104
</div>

js/jqm-datebox.mode.custombox.js

+147
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
/*
2+
* jQuery Mobile Framework : plugin to provide a date and time picker.
3+
* Copyright (c) JTSage
4+
* CC 3.0 Attribution. May be relicensed without permission/notification.
5+
* https://github.com/jtsage/jquery-mobile-datebox
6+
*/
7+
8+
(function($) {
9+
$.extend( $.mobile.datebox.prototype.options, {
10+
themeButton: 'a',
11+
themeInput: 'e',
12+
useSetButton: true,
13+
customData: [
14+
{'input': true, 'name':'Letter', 'data':['a','b','c','d','e']},
15+
{'input': true, 'name':'Text', 'data':['some','bull','shtuff','here']},
16+
{'input': false, 'name':'Image', 'data':['<img src="img/slot1.png" />','<img src="img/slot2.png" />','<img src="img/slot3.png" />','<img src="img/slot4.png" />']}
17+
],
18+
customDefault: [0,0,0],
19+
customFormat: false,
20+
customboxlang: {
21+
// This structure interfaces with __() -> if it exists, strings are looked up here after i8n fails,
22+
// and before going to 'default' - the name syntax is <mode>lang
23+
'customSet':'Looks Good'
24+
}
25+
26+
});
27+
$.extend( $.mobile.datebox.prototype, {
28+
_cbox_offset: function (fld,amount) {
29+
// This is *not* an automatic override, used below specificly.
30+
var w = this, x,
31+
o = this.options;
32+
33+
tmp = (w.customCurrent[fld] + amount) % o.customData[fld]['data'].length;
34+
if ( tmp < 0 ) { tmp = o.customData[fld]['data'].length + tmp; }
35+
36+
w.customCurrent[fld] = tmp;
37+
if ( o.useImmediate ) { w.d.input.trigger('datebox', {'method':'set', 'value':w._formatter(o.customFormat,w.customCurrent), 'date':w.customCurrent}); }
38+
w.refresh();
39+
}
40+
});
41+
$.extend( $.mobile.datebox.prototype._parser, {
42+
// If this stucture exists, it is called instead of the usual date input parser.
43+
// The name of the structure is the same as the mode name - it recieves a string
44+
// as the input, which is the current value of the input element, pre-sanitized
45+
'custombox' : function ( str ) {
46+
return ( str.length < 1 || ! str.match(/,/) ) ? this.options.customDefault : str.split(",");
47+
}
48+
});
49+
$.extend( $.mobile.datebox.prototype._customformat, {
50+
// If this stucture exists, the formatter will call it when it encounters a special string
51+
// %X<whatever> - it recieves the single letter operater, and the current "date" value
52+
'custombox' : function ( oper, val ) {
53+
return val[oper-1];
54+
}
55+
});
56+
$.extend( $.mobile.datebox.prototype._build, {
57+
'custombox': function () {
58+
var w = this,
59+
o = this.options, i, y, tmp, cnt = -2,
60+
uid = 'ui-datebox-',
61+
divBase = $("<div>"),
62+
divPlus = $('<fieldset>'),
63+
divIn = divBase.clone(),
64+
divMinus = divPlus.clone(),
65+
customCurrent = this._makeDate(this.d.input.val()),
66+
inBase = $("<input type='text' />").addClass('ui-input-text ui-corner-all ui-shadow-inset ui-body-'+o.themeInput),
67+
inDiv = $("<div>").addClass('ui-input-text ui-corner-all ui-shadow-inset ui-body-'+o.themeInput).css({'padding':'.4em','margin':'.5em 0','text-align':'center'}),
68+
butBase = $("<div>"),
69+
butPTheme = {theme: o.themeButton, icon: 'plus', iconpos: 'bottom', corners:true, shadow:true},
70+
butMTheme = $.extend({}, butPTheme, {icon: 'minus', iconpos: 'top'});
71+
72+
if ( typeof w.customCurrent === "undefined" ) { w.customCurrent = customCurrent; }
73+
74+
if ( o.customFormat === false ) {
75+
tmp = [];
76+
for ( i = 0; i<o.customData.length; i++ ) {
77+
tmp.push('%X'+(i+1));
78+
}
79+
o.customFormat = tmp.join(',');
80+
}
81+
82+
if ( typeof w.d.intHTML !== 'boolean' ) {
83+
w.d.intHTML.empty().remove();
84+
}
85+
86+
w.d.headerText = ((w._grabLabel() !== false)?w._grabLabel():((o.mode==='datebox')?w.__('titleDateDialogLabel'):w.__('titleTimeDialogLabel')));
87+
w.d.intHTML = $('<span>');
88+
89+
90+
for(i=0; i<o.customData.length; i++) {
91+
tmp = ['a','b','c','d','e','f'][i];
92+
if ( o.customData[i]['input'] === true ) {
93+
$('<div>').append(inBase.clone().attr('value', o.customData[i]['data'][w.customCurrent[i]])).addClass('ui-block-'+tmp).appendTo(divIn);
94+
} else {
95+
$('<div>').append(inDiv.clone().html(o.customData[i]['data'][w.customCurrent[i]])).addClass('ui-block-'+tmp).appendTo(divIn);
96+
}
97+
w._makeEl(butBase, {'attr': {'field':i, 'amount':1}}).addClass('ui-block-'+tmp).buttonMarkup(butPTheme).appendTo(divPlus);
98+
w._makeEl(butBase, {'attr': {'field':i, 'amount':1}}).addClass('ui-block-'+tmp).buttonMarkup(butMTheme).appendTo(divMinus);
99+
cnt++;
100+
}
101+
102+
divPlus.addClass('ui-grid-'+['a','b','c','d','e'][cnt]).appendTo(w.d.intHTML);
103+
divIn.addClass('ui-datebox-dboxin').addClass('ui-grid-'+['a','b','c','d','e'][cnt]).appendTo(w.d.intHTML);
104+
divMinus.addClass('ui-grid-'+['a','b','c','d','e'][cnt]).appendTo(w.d.intHTML);
105+
106+
if ( o.useSetButton || o.useClearButton ) {
107+
y = $('<div>', {'class':uid+'controls'});
108+
109+
if ( o.useSetButton ) {
110+
$('<a href="#">'+w.__('customSet')+'</a>')
111+
.appendTo(y).buttonMarkup({theme: o.theme, icon: 'check', iconpos: 'left', corners:true, shadow:true})
112+
.on(o.clickEventAlt, function(e) {
113+
e.preventDefault();
114+
w.d.input.trigger('datebox', {'method':'set', 'value':w._formatter(o.customFormat,w.customCurrent), 'date':w.customCurrent});
115+
w.d.input.trigger('datebox', {'method':'close'});
116+
});
117+
}
118+
if ( o.useClearButton ) {
119+
$('<a href="#">'+w.__('clearButton')+'</a>')
120+
.appendTo(y).buttonMarkup({theme: o.theme, icon: 'delete', iconpos: 'left', corners:true, shadow:true})
121+
.on(o.clickEventAlt, function(e) {
122+
e.preventDefault();
123+
w.d.input.val('');
124+
w.d.input.trigger('datebox',{'method':'clear'});
125+
w.d.input.trigger('datebox',{'method':'close'});
126+
});
127+
}
128+
if ( o.useCollapsedBut ) {
129+
y.addClass('ui-datebox-collapse');
130+
}
131+
y.appendTo(w.d.intHTML);
132+
}
133+
134+
divIn.on('change', 'input', function() { w.refresh(); });
135+
136+
divPlus.on(o.clickEvent, 'div', function(e) {
137+
e.preventDefault();
138+
w._cbox_offset($(this).jqmData('field'), $(this).jqmData('amount'));
139+
});
140+
divMinus.on(o.clickEvent, 'div', function(e) {
141+
e.preventDefault();
142+
w._cbox_offset($(this).jqmData('field'), $(this).jqmData('amount')*-1);
143+
});
144+
145+
}
146+
});
147+
})( jQuery );

js/jqm-datebox.mode.customflip.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
themeOpt: 'd',
1313
useSetButton: true,
1414
customData: [
15-
{'name':'Letter', 'data':['a','b','c','d','e']},
16-
{'name':'Text', 'data':['some','bull','shtuff','here']},
17-
{'name':'Image', 'data':['<img src="img/slot1.png" />','<img src="img/slot2.png" />','<img src="img/slot3.png" />','<img src="img/slot4.png" />']}
15+
{'input': true, 'name':'Letter', 'data':['a','b','c','d','e']},
16+
{'input': true, 'name':'Text', 'data':['some','bull','shtuff','here']},
17+
{'input': false, 'name':'Image', 'data':['<img src="img/slot1.png" />','<img src="img/slot2.png" />','<img src="img/slot3.png" />','<img src="img/slot4.png" />']}
1818
],
1919
customDefault: [0,0,0],
2020
customFormat: false,

tests/dev.html

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<script type="text/javascript" src="../js/jqm-datebox.mode.durationbox.js"></script>
2424
<script type="text/javascript" src="../js/jqm-datebox.mode.slidebox.js"></script>
2525
<script type="text/javascript" src="../js/jqm-datebox.mode.customflip.js"></script>
26+
<script type="text/javascript" src="../js/jqm-datebox.mode.custombox.js"></script>
2627
<script type="text/javascript" src="./jquery.mobile.datebox.i18n.en_US.utf8.js"></script>
2728
<script type="text/javascript">
2829
jQuery.extend(jQuery.mobile.datebox.prototype.options, {
@@ -41,6 +42,10 @@
4142
<h1>jQueryMobile - Dev Page</h1>
4243
</div>
4344
<div data-role="content">
45+
<div data-role="fieldcontain">
46+
<label for="c2">custom box</label>
47+
<input name="c2" type="text" data-role="datebox" data-options='{"mode": "custombox", "overrideStyleClass":"ui-icon-dice"}' id="c2" />
48+
</div>
4449
<div data-role="fieldcontain">
4550
<label for="c1">custom flip</label>
4651
<input name="c1" type="text" data-role="datebox" data-options='{"mode": "customflip", "overrideStyleClass":"ui-icon-dice"}' id="c1" />

0 commit comments

Comments
 (0)