source: uKadecot/trunk/tools/EcnlControllerUI/EcnlCtrlUI/js/jqm-datebox/jqm-datebox.mode.durationbox.js@ 108

Last change on this file since 108 was 108, checked in by coas-nagasima, 9 years ago

MIMEプロパティの変更

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/javascript
File size: 8.1 KB
Line 
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 /* DurationBox Mode */
8
9(function($) {
10 $.extend( $.mobile.datebox.prototype.options, {
11 themeButton: 'a',
12 themeInput: 'a',
13 useSetButton: true,
14 repButton: true,
15 durationSteppers: {'d': 1, 'h': 1, 'i': 1, 's': 1}
16 });
17 $.extend( $.mobile.datebox.prototype, {
18 _durbox_run: function() {
19 var w = this;
20 w.drag.didRun = true;
21 w._offset(w.drag.target[0], w.drag.target[1], false);
22 w._durbox_run_update();
23 w.runButton = setTimeout(function() {w._durbox_run();}, 100);
24 },
25 _durbox_run_update: function () {
26 var w = this, i, cDur = [],
27 ival = {'d': 60*60*24, 'h': 60*60, 'i': 60};
28
29 i = w.theDate.getEpoch() - w.initDate.getEpoch();
30 if ( i<0 ) { i = 0; w.theDate.setTime(w.initDate.getTime()); }
31 w.lastDuration = i; // Let the number of seconds be sort of public.
32
33 // DAYS
34 cDur[0] = parseInt( i / ival.d,10); i = i % ival.d;
35 // HOURS
36 cDur[1] = parseInt( i / ival.h, 10); i = i % ival.h;
37 // MINS AND SECS
38 cDur[2] = parseInt( i / ival.i, 10);
39 cDur[3] = i % ival.i;
40
41 w.d.divIn.find('input').each(function () {
42 switch ( $(this).parent().jqmData('field') ) {
43 case 'd':
44 $(this).val(cDur[0]); break;
45 case 'h':
46 $(this).val(cDur[1]); break;
47 case 'i':
48 $(this).val(cDur[2]); break;
49 case 's':
50 $(this).val(cDur[3]); break;
51 }
52 });
53 },
54 _durbox_valid: function (num) {
55 if ( num.toString().search(/^[0-9]+$/) === 0 ) { return parseInt(num,10); }
56 return 0;
57 },
58 _durbox_enter: function (item) {
59 var w = this,
60 t = w.initDate.getEpoch();
61
62 w.d.intHTML.find('input').each( function() {
63 switch ( $(this).parent().jqmData('field') ) {
64 case 'd':
65 t += (60*60*24) * w._durbox_valid($(this).val()); break;
66 case 'h':
67 t += (60*60) * w._durbox_valid($(this).val()); break;
68 case 'i':
69 t += (60) * w._durbox_valid($(this).val()); break;
70 case 's':
71 t += w._durbox_valid($(this).val()); break;
72 }
73 });
74 w.theDate.setTime( t * 1000 );
75 w.refresh();
76 }
77 });
78 $.extend( $.mobile.datebox.prototype._build, {
79 'durationbox': function () {
80 var w = this,
81 g = this.drag,
82 o = this.options, i, y, cDur = [0,0,0,0], tmp,
83 ival = {'d': 60*60*24, 'h': 60*60, 'i': 60},
84 uid = 'ui-datebox-',
85 divBase = $("<div>"),
86 divPlus = $('<fieldset>'),
87 divIn = divBase.clone().addClass('ui-datebox-dboxin'),
88 divMinus = divPlus.clone(),
89 inBase = $("<input type='"+w.inputType+"' />").addClass('ui-input-text ui-corner-all ui-shadow-inset ui-body-'+o.themeInput),
90 butBase = $("<div><a href='#'> </a></div>"),
91 butPTheme = {theme: o.themeButton, icon: 'plus', iconpos: 'bottom', corners:true, shadow:true},
92 butMTheme = $.extend({}, butPTheme, {icon: 'minus', iconpos: 'top'});
93
94 if ( typeof w.d.intHTML !== 'boolean' ) {
95 w.d.intHTML.empty().remove();
96 }
97
98 w.d.headerText = ((w._grabLabel() !== false)?w._grabLabel():w.__('titleDateDialogLabel'));
99 w.d.intHTML = $('<span>');
100
101 if ( w.inputType !== 'number' ) { inBase.attr('pattern', '[0-9]*'); }
102
103 w.fldOrder = w.__('durationOrder');
104
105 for(i=0; i<=w.fldOrder.length; i++) {
106 switch (w.fldOrder[i]) {
107 case 'd':
108 case 'h':
109 case 'i':
110 case 's':
111 y = $.inArray(w.fldOrder[i], ['d','h','i','s']);
112 $('<div>').jqmData('field', w.fldOrder[i]).addClass('ui-block-'+['a','b','c','d'][i]).append(inBase.clone()).appendTo(divIn).prepend('<label>'+w.__('durationLabel')[y]+'</label>');
113 w._makeEl(butBase, {'attr': {'field':w.fldOrder[i]}}).addClass('ui-block-'+['a','b','c','d'][i]).buttonMarkup(butPTheme).appendTo(divPlus);
114 w._makeEl(butBase, {'attr': {'field':w.fldOrder[i]}}).addClass('ui-block-'+['a','b','c','d'][i]).buttonMarkup(butMTheme).appendTo(divMinus);
115 break;
116 }
117 }
118
119 i = w.theDate.getEpoch() - w.initDate.getEpoch();
120 if ( i<0 ) { i = 0; w.theDate.setTime(w.initDate.getTime()); }
121 w.lastDuration = i; // Let the number of seconds be sort of public.
122
123 // DAYS
124 cDur[0] = parseInt( i / ival.d,10); i = i % ival.d;
125 // HOURS
126 cDur[1] = parseInt( i / ival.h, 10); i = i % ival.h;
127 // MINS AND SECS
128 cDur[2] = parseInt( i / ival.i, 10);
129 cDur[3] = i % ival.i;
130
131 divIn.find('input').each(function () {
132 switch ( $(this).parent().jqmData('field') ) {
133 case 'd':
134 $(this).val(cDur[0]); break;
135 case 'h':
136 $(this).val(cDur[1]); break;
137 case 'i':
138 $(this).val(cDur[2]); break;
139 case 's':
140 $(this).val(cDur[3]); break;
141 }
142 });
143
144 w.d.divIn = divIn;
145
146 divPlus.addClass('ui-grid-'+['a','b','c'][w.fldOrder.length-2]).appendTo(w.d.intHTML);
147 divIn.addClass('ui-grid-'+['a','b','c'][w.fldOrder.length-2]).appendTo(w.d.intHTML);
148 divMinus.addClass('ui-grid-'+['a','b','c'][w.fldOrder.length-2]).appendTo(w.d.intHTML);
149
150 if (o.mobVer >= 140) {
151 divMinus.find('div').css({'min-height': '2.3em'});
152 divPlus.find('div').css({'min-height': '2.3em'});
153 }
154
155 if ( o.useSetButton || o.useClearButton ) {
156 y = $('<div>', {'class':uid+'controls'});
157
158 if ( o.useSetButton ) {
159 $('<a href="#">'+w.__('setDurationButtonLabel')+'</a>')
160 .appendTo(y).buttonMarkup({theme: o.theme, icon: 'check', iconpos: 'left', corners:true, shadow:true})
161 .on(o.clickEventAlt, function(e) {
162 e.preventDefault();
163 w.d.input.trigger('datebox', {'method':'set', 'value':w._formatter(w.__fmt(),w.theDate), 'date':w.theDate});
164 w.d.input.trigger('datebox', {'method':'close'});
165 });
166 }
167 if ( o.useClearButton ) {
168 $('<a href="#">'+w.__('clearButton')+'</a>')
169 .appendTo(y).buttonMarkup({theme: o.theme, icon: 'delete', iconpos: 'left', corners:true, shadow:true})
170 .on(o.clickEventAlt, function(e) {
171 e.preventDefault();
172 w.d.input.val('');
173 w.d.input.trigger('datebox',{'method':'clear'});
174 w.d.input.trigger('datebox',{'method':'close'});
175 });
176 }
177 if ( o.useCollapsedBut ) {
178 y.addClass('ui-datebox-collapse');
179 }
180 y.appendTo(w.d.intHTML);
181 }
182
183 if ( o.repButton === false ) {
184 divPlus.on(o.clickEvent, 'div', function(e) {
185 e.preventDefault();
186 w._offset($(this).jqmData('field'), o.durationSteppers[$(this).jqmData('field')]);
187 });
188 divMinus.on(o.clickEvent, 'div', function(e) {
189 e.preventDefault();
190 w._offset($(this).jqmData('field'), o.durationSteppers[$(this).jqmData('field')]*-1);
191 });
192 }
193
194 divIn.on('change', 'input', function() { w._durbox_enter($(this)); });
195
196 if ( w.wheelExists ) { // Mousewheel operation, if plugin is loaded
197 divIn.on('mousewheel', 'input', function(e,d) {
198 e.preventDefault();
199 w._offset($(this).parent().jqmData('field'), ((d<0)?-1:1)*o.durationSteppers[$(this).parent().jqmData('field')]);
200 });
201 }
202
203 if ( o.repButton === true ) {
204 divPlus.on(w.drag.eStart, 'div', function(e) {
205 tmp = [$(this).jqmData('field'), o.durationSteppers[$(this).jqmData('field')]];
206 w.drag.move = true;
207 w._dbox_delta = 1;
208 w._offset(tmp[0], tmp[1], false);
209 w._durbox_run_update();
210 if ( !w.runButton ) {
211 w.drag.target = tmp;
212 w.runButton = setTimeout(function() {w._durbox_run();}, 500);
213 }
214 });
215
216 divMinus.on(w.drag.eStart, 'div', function(e) {
217 tmp = [$(this).jqmData('field'), o.durationSteppers[$(this).jqmData('field')]*-1];
218 w.drag.move = true;
219 w._dbox_delta = -1;
220 w._offset(tmp[0], tmp[1], false);
221 w._durbox_run_update();
222 if ( !w.runButton ) {
223 w.drag.target = tmp;
224 w.runButton = setTimeout(function() {w._durbox_run();}, 500);
225 }
226 });
227
228 divPlus.on(g.eEndA, function(e) {
229 if ( g.move ) {
230 e.preventDefault();
231 clearTimeout(w.runButton);
232 w.runButton = false;
233 g.move = false;
234 }
235 });
236 divMinus.on(g.eEndA, function(e) {
237 if ( g.move ) {
238 e.preventDefault();
239 clearTimeout(w.runButton);
240 w.runButton = false;
241 g.move = false;
242 }
243 });
244 }
245 }
246 });
247})( jQuery );
Note: See TracBrowser for help on using the repository browser.