mobiscroll onbeforeshowpopup,设定值问题,怎么解决

/ codelearning
项目语言:JAVA
权限:read-only(如需更高权限请先加入项目)
codelearning/
Index: mobiscroll.select-2.5.1.js
===================================================================
--- mobiscroll.select-2.5.1.js (revision 0)
+++ mobiscroll.select-2.5.1.js (revision 8)
@@ -0,0 +1,348 @@
+/*jslint eqeq: true, plusplus: true, undef: true, sloppy: true, vars: true, forin: true */
+(function ($) {
var defaults = {
inputClass: '',
invalid: [],
rtl: false,
group: false,
groupLabel: 'Groups'
$.mobiscroll.presetShort('select');
$.mobiscroll.presets.select = function (inst) {
var stg = inst.settings,
s = $.extend({}, defaults, stg),
elm = $(this),
multiple = elm.prop('multiple'),
id = this.id + '_dummy',
option = multiple ? (elm.val() ? elm.val()[0] : $('option', elm).attr('value')) : elm.val(),
group = elm.find('option[value=&' + option + '&]').parent(),
prev = group.index() + '',
gr = prev,
l1 = $('label[for=&' + this.id + '&]').attr('for', id),
l2 = $('label[for=&' + id + '&]'),
label = s.label !== undefined ? s.label : (l2.length ? l2.text() : elm.attr('name')),
invalid = [],
origValues = [],
main = {},
roPre = stg.readonly,
function replace(str) {
return str ? str.replace(/_/, '') : '';
function genWheels() {
wheel = {},
if (s.group) {
if (s.rtl) {
$('optgroup', elm).each(function (index) {
wheel['_' + index] = $(this).attr('label');
w[wg] = {};
w[wg][s.groupLabel] =
wg += (s.rtl ? -1 : 1);
w[wg] = {};
w[wg][label] = {};
$('option', cont).each(function () {
var v = $(this).attr('value');
w[wg][label]['_' + v] = $(this).text();
if ($(this).prop('disabled')) {
invalid.push(v);
function setVal(v, fill) {
var value = [];
if (multiple) {
var sel = [],
for (i in inst._selectedValues) {
sel.push(main[i]);
value.push(i);
input.val(sel.join(', '));
input.val(v);
value = fill ? replace(inst.values[optIdx]) :
if (fill) {
elm.val(value).trigger('change');
// if groups is true and there are no groups fall back to no grouping
if (s.group && !$('optgroup', elm).length) {
if (!s.invalid.length) {
s.invalid =
if (s.group) {
if (s.rtl) {
grIdx = 1;
optIdx = 0;
grIdx = 0;
optIdx = 1;
grIdx = -1;
optIdx = 0;
$('#' + id).remove();
input = $('&input type=&text& id=&' + id + '& class=&' + s.inputClass + '& readonly /&').insertBefore(elm),
$('option', elm).each(function () {
main[$(this).attr('value')] = $(this).text();
if (s.showOnFocus) {
input.focus(function () {
inst.show();
var v = elm.val() || [],
for (i; i & v. i++) {
inst._selectedValues[v[i]] = v[i];
setVal(main[option]);
elm.unbind('.dwsel').bind('change.dwsel', function () {
if (!prevent) {
inst.setSelectVal(multiple ? elm.val() || [] : [elm.val()], true);
}).hide().closest('.ui-field-contain').trigger('create');
inst.setSelectVal = function (d, fill, time) {
option = d[0] || $('option', elm).attr('value');
if (multiple) {
inst._selectedValues = {};
var i = 0;
for (i; i & d. i++) {
inst._selectedValues[d[i]] = d[i];
if (s.group) {
group = elm.find('option[value=&' + option + '&]').parent();
gr = group.index();
inst.temp = s.rtl ? ['_' + option, '_' + group.index()] : ['_' + group.index(), '_' + option];
if (gr !== prev) { // Need to regenerate wheels, if group changed
stg.wheels = genWheels();
inst.changeWheel([optIdx]);
prev = gr + '';
inst.temp = ['_' + option];
inst.setValue(true, fill, time);
// Set input/select values
if (fill) {
var changed = multiple ? true : option !== elm.val();
setVal(main[option], changed);
inst.getSelectVal = function (temp) {
var val = temp ? inst.temp : inst.
return replace(val[optIdx]);
width: 50,
wheels: w,
headerText: false,
multiple: multiple,
anchor: input,
formatResult: function (d) {
return main[replace(d[optIdx])];
parseValue: function () {
var v = elm.val() || [],
if (multiple) {
inst._selectedValues = {};
for (i; i & v. i++) {
inst._selectedValues[v[i]] = v[i];
option = multiple ? (elm.val() ? elm.val()[0] : $('option', elm).attr('value')) : elm.val();
group = elm.find('option[value=&' + option + '&]').parent();
gr = group.index();
prev = gr + '';
return s.group && s.rtl ? ['_' + option, '_' + gr] : s.group ? ['_' + gr, '_' + option] : ['_' + option];
validate: function (dw, i, time) {
if (i === undefined && multiple) {
var v = inst._selectedValues,
for (j in v) {
$('.dwwl' + optIdx + ' .dw-li[data-val=&_' + v[j] + '&]', dw).addClass('dw-msel');
if (i === grIdx) {
gr = replace(inst.temp[grIdx]);
if (gr !== prev) {
group = elm.find('optgroup').eq(gr);
gr = group.index();
option = group.find('option').eq(0).val();
option = option || elm.val();
stg.wheels = genWheels();
if (s.group) {
inst.temp = s.rtl ? ['_' + option, '_' + gr] : ['_' + gr, '_' + option];
stg.readonly = [s.rtl, !s.rtl];
clearTimeout(timer);
timer = setTimeout(function () {
inst.changeWheel([optIdx]);
stg.readonly = roP
prev = gr + '';
}, time * 1000);
stg.readonly = roP
option = replace(inst.temp[optIdx]);
var t = $('.dw-ul', dw).eq(optIdx);
$.each(s.invalid, function (i, v) {
$('.dw-li[data-val=&_' + v + '&]', t).removeClass('dw-v');
onBeforeShow: function (dw) {
stg.wheels = genWheels();
if (s.group) {
inst.temp = s.rtl ? ['_' + option, '_' + group.index()] : ['_' + group.index(), '_' + option];
onMarkupReady: function (dw) {
$('.dwwl' + grIdx, dw).bind('mousedown touchstart', function () {
clearTimeout(timer);
if (multiple) {
dw.addClass('dwms');
$('.dwwl', dw).eq(optIdx).addClass('dwwms');
origValues = {};
for (i in inst._selectedValues) {
origValues[i] = inst._selectedValues[i];
onValueTap: function (li) {
if (multiple && li.hasClass('dw-v') && li.closest('.dw').find('.dw-ul').index(li.closest('.dw-ul')) == optIdx) {
var val = replace(li.attr('data-val'));
if (li.hasClass('dw-msel')) {
delete inst._selectedValues[val];
inst._selectedValues[val] =
li.toggleClass('dw-msel');
if (s.display == 'inline') {
setVal(val, true);
onSelect: function (v) {
setVal(v, true);
if (s.group) {
inst.values =
onCancel: function () {
if (s.group) {
inst.values =
if (multiple) {
inst._selectedValues = {};
for (i in origValues) {
inst._selectedValues[i] = origValues[i];
onChange: function (v) {
if (s.display == 'inline' && !multiple) {
input.val(v);
elm.val(replace(inst.temp[optIdx])).trigger('change');
onClose: function () {
input.blur();
methods: {
setValue: function (d, fill, time) {
return this.each(function () {
var inst = $(this).mobiscroll('getInst');
if (inst) {
if (inst.setSelectVal) {
inst.setSelectVal(d, fill, time);
inst.temp =
inst.setValue(true, fill, time);
getValue: function (temp) {
var inst = $(this).mobiscroll('getInst');
if (inst) {
return inst.getSelectVal ? inst.getSelectVal(temp) : inst.
+})(jQuery);
Index: mobiscroll.android-2.5.1.js
===================================================================
--- mobiscroll.android-2.5.1.js (revision 0)
+++ mobiscroll.android-2.5.1.js (revision 8)
@@ -0,0 +1,12 @@
+(function ($) {
$.mobiscroll.themes.android = {
defaults: {
dateOrder: 'Mddyy',
mode: 'clickpick',
height: 50
+})(jQuery);
Index: mobiscroll.jqm-2.5.1.js
===================================================================
--- mobiscroll.jqm-2.5.1.js (revision 0)
+++ mobiscroll.jqm-2.5.1.js (revision 8)
@@ -0,0 +1,30 @@
+(function ($) {
$.mobiscroll.themes.jqm = {
defaults: {
jqmBorder: 'a',
jqmBody: 'c',
jqmHeader: 'b',
jqmWheel: 'd',
jqmClickPick: 'c',
jqmSet: 'b',
jqmCancel: 'c'
init: function (elm, inst) {
var s = inst.
$('.dw', elm).removeClass('dwbg').addClass('ui-overlay-shadow ui-corner-all ui-body-' + s.jqmBorder);
$('.dwb-s span', elm).attr('data-role', 'button').attr('data-theme', s.jqmSet);
$('.dwb-n span', elm).attr('data-role', 'button').attr('data-theme', s.jqmCancel);
$('.dwb-c span', elm).attr('data-role', 'button').attr('data-theme', s.jqmCancel);
$('.dwwb', elm).attr('data-role', 'button').attr('data-theme', s.jqmClickPick);
$('.dwv', elm).addClass('ui-header ui-bar-' + s.jqmHeader);
$('.dwwr', elm).addClass('ui-body-' + s.jqmBody);
$('.dwpm .dwwl', elm).addClass('ui-body-' + s.jqmWheel);
$('.dwpm .dwl', elm).addClass('ui-body-' + s.jqmBody);
elm.trigger('create');
// Hide on overlay click
$('.dwo', elm).click(function () { inst.cancel(); });
+})(jQuery);
Index: mobiscroll.wp-2.5.2.js
===================================================================
--- mobiscroll.wp-2.5.2.js (revision 0)
+++ mobiscroll.wp-2.5.2.js (revision 8)
@@ -0,0 +1,47 @@
+(function ($) {
$.mobiscroll.themes.wp = {
defaults: {
width: 70,
height: 76,
accent: 'none',
dateOrder: 'mmMMddDDyy',
onAnimStart: function (dw, i, time) {
$('.dwwl' + i, dw).addClass('wpam');
clearTimeout(anim[i]);
anim[i] = setTimeout(function () {
$('.dwwl' + i, dw).removeClass('wpam');
}, time * 1000 + 100);
init: function (elm, inst) {
var click,
anim = {};
$('.dw', elm).addClass('wp-' + inst.settings.accent);
//$('.dwwl', elm).bind('touchstart mousedown DOMMouseScroll mousewheel', function () {
$('.dwwl', elm).delegate('.dw-sel', 'touchstart mousedown DOMMouseScroll mousewheel', function () {
active = $(this).closest('.dwwl').hasClass('wpa');
$('.dwwl', elm).removeClass('wpa');
$(this).closest('.dwwl').addClass('wpa');
}).bind('touchmove mousemove', function () {
}).bind('touchend mouseup', function () {
if (click && active) {
$(this).closest('.dwwl').removeClass('wpa');
$.mobiscroll.themes['wp light'] = $.mobiscroll.themes.
+})(jQuery);
Index: mobiscroll.core-2.5.2-zh.js
===================================================================
--- mobiscroll.core-2.5.2-zh.js (revision 0)
+++ mobiscroll.core-2.5.2-zh.js (revision 8)
@@ -0,0 +1,6 @@
+(function ($) {
$.mobiscroll.i18n.zh = $.extend($.mobiscroll.i18n.zh, {
setText: '完成',
cancelText: '取消'
+})(jQuery);
Index: mobiscroll.core-2.5.2.js
===================================================================
--- mobiscroll.core-2.5.2.js (revision 0)
+++ mobiscroll.core-2.5.2.js (revision 8)
@@ -0,0 +1,1130 @@
+/*jslint eqeq: true, plusplus: true, undef: true, sloppy: true, vars: true, forin: true */
+ * jQuery MobiScroll v2.5.1
+ * Copyright , Acid Media
+ * Licensed under the MIT license.
+(function ($) {
function Scroller(elem, settings) {
ww, // Window width
wh, // Window height
mw, // Modal width
mh, // Modal height
that = this,
ms = $.mobiscroll,
elm = $(e),
s = extend({}, defaults),
pres = {},
warr = [],
pixels = {},
input = elm.is('input'),
// Private functions
function isReadOnly(wh) {
if ($.isArray(s.readonly)) {
var i = $('.dwwl', dw).index(wh);
return s.readonly[i];
function generateWheelItems(i) {
var html = '&div class=&dw-bf&&',
for (j in warr[i]) {
if (l % 20 == 0) {
html += '&/div&&div class=&dw-bf&&';
html += '&div class=&dw-li dw-v& data-val=&' + j + '& style=&height:' + hi + 'line-height:' + hi + '&&&div class=&dw-i&&' + warr[i][j] + '&/div&&/div&';
html += '&/div&';
function setGlobals(t) {
min = $('.dw-li', t).index($('.dw-v', t).eq(0));
max = $('.dw-li', t).index($('.dw-v', t).eq(-1));
index = $('.dw-ul', dw).index(t);
function formatHeader(v) {
var t = s.headerT
return t ? (typeof t === 'function' ? t.call(e, v) : t.replace(/\{value\}/i, v)) : '';
function read() {
that.temp = ((input && that.val !== null && that.val != elm.val()) || that.values === null) ? s.parseValue(elm.val() || '', that) : that.values.slice(0);
that.setValue(true);
function scrollToPos(time, index, manual, dir, orig) {
// Call validation event
if (event('validate', [dw, index, time]) !== false) {
// Set scrollers to position
$('.dw-ul', dw).each(function (i) {
var t = $(this),
cell = $('.dw-li[data-val=&' + that.temp[i] + '&]', t),
cells = $('.dw-li', t),
v = cells.index(cell),
l = cells.length,
sc = i == index || index ===
// Scroll to a valid cell
if (!cell.hasClass('dw-v')) {
var cell1 = cell,
cell2 = cell,
dist1 = 0,
dist2 = 0;
while (v - dist1 &= 0 && !cell1.hasClass('dw-v')) {
cell1 = cells.eq(v - dist1);
while (v + dist2 & l && !cell2.hasClass('dw-v')) {
cell2 = cells.eq(v + dist2);
// If we have direction (+/- or mouse wheel), the distance does not count
if (((dist2 & dist1 && dist2 && dir !== 2) || !dist1 || (v - dist1 & 0) || dir == 1) && cell2.hasClass('dw-v')) {
cell = cell2;
v = v + dist2;
cell = cell1;
v = v - dist1;
if (!(cell.hasClass('dw-sel')) || sc) {
// Set valid value
that.temp[i] = cell.attr('data-val');
// Add selected class to cell
$('.dw-sel', t).removeClass('dw-sel');
cell.addClass('dw-sel');
// Scroll to position
//that.scroll(t, i, v, time);
that.scroll(t, i, v, sc ? time : 0.1, sc ? orig : undefined);
// Reformat value if validation changed something
that.change(manual);
function position(check) {
if (s.display == 'inline' || (ww === $(window).width() && rwh === $(window).height() && check)) {
aw, // anchor width
ah, // anchor height
ap, // anchor position
at, // anchor top
al, // anchor left
arr, // arrow
arrw, // arrow width
arrl, // arrow left
totalw = 0,
st = $(window).scrollTop(),
wr = $('.dwwr', dw),
d = $('.dw', dw),
anchor = s.anchor === undefined ? elm : s.
ww = $(window).width();
rwh = $(window).height();
wh = window.innerH // on iOS we need innerHeight
wh = wh ||
if (/modal|bubble/.test(s.display)) {
$('.dwc', dw).each(function () {
w = $(this).outerWidth(true);
minw = (w & minw) ? w :
w = totalw & ww ? minw :
wr.width(w);
mw = d.outerWidth();
mh = d.outerHeight(true);
if (s.display == 'modal') {
l = (ww - mw) / 2;
t = st + (wh - mh) / 2;
} else if (s.display == 'bubble') {
arr = $('.dw-arrw-i', dw);
ap = anchor.offset();
// horizontal positioning
aw = anchor.outerWidth();
ah = anchor.outerHeight();
l = al - (d.outerWidth(true) - aw) / 2;
l = l & (ww - mw) ? (ww - (mw + 20)) :
l = l &= 0 ? l : 20;
// vertical positioning
t = at - //(mh + 3); // above the input
if ((t & st) || (at & st + wh)) { // if doesn't fit above or the input is out of the screen
d.removeClass('dw-bubble-top').addClass('dw-bubble-bottom');
t = at +// + 3; // below the input
d.removeClass('dw-bubble-bottom').addClass('dw-bubble-top');
//t = t &= st ? t :
// Calculate Arrow position
arrw = arr.outerWidth();
arrl = al + aw / 2 - (l + (mw - arrw) / 2);
// Limit Arrow position to [0, pocw.width] intervall
$('.dw-arr', dw).css({ left: arrl & arrw ? arrw : arrl });
css.width = '100%';
if (s.display == 'top') {
} else if (s.display == 'bottom') {
t = st + wh -
css.top = t & 0 ? 0 :
css.left =
d.css(css);
// If top + modal height & doc height, increase doc height
$('.dw-persp', dw).height(0).height(t + mh & $(document).height() ? t + mh : $(document).height());
// Scroll needed
if (scroll && ((t + mh & st + wh) || (at & st + wh))) {
$(window).scrollTop(t + mh - wh);
function testTouch(e) {
if (e.type === 'touchstart') {
setTimeout(function () {
touch = // Reset if mouse event was not fired
} else if (touch) {
function event(name, args) {
args.push(that);
$.each([theme.defaults, pres, settings], function (i, v) {
if (v[name]) { // Call preset event
ret = v[name].apply(e, args);
function plus(t) {
var p = +t.data('pos'),
val = p + 1;
calc(t, val & max ? min : val, 1, true);
function minus(t) {
var p = +t.data('pos'),
val = p - 1;
calc(t, val & min ? max : val, 2, true);
// Public functions
* Enables the scroller and the associated input.
that.enable = function () {
s.disabled =
if (input) {
elm.prop('disabled', false);
* Disables the scroller and the associated input.
that.disable = function () {
s.disabled =
if (input) {
elm.prop('disabled', true);
* Scrolls target to the specified position
* @param {Object} t - Target wheel jQuery object.
* @param {Number} index - Index of the changed wheel.
* @param {Number} val - Value.
* @param {Number} time - Duration of the animation, optional.
* @param {Number} orig - Original value.
that.scroll = function (t, index, val, time, orig) {
function getVal(t, b, c, d) {
return c * Math.sin(t / d * (Math.PI / 2)) +
function ready() {
clearInterval(iv[index]);
delete iv[index];
t.data('pos', val).closest('.dwwl').removeClass('dwa');
var px = (m - val) * hi,
if (px == pixels[index] && iv[index]) {
if (time && px != pixels[index]) {
// Trigger animation start event
event('onAnimStart', [dw, index, time]);
pixels[index] =
t.attr('style', (prefix + '-transition:all ' + (time ? time.toFixed(3) : 0) + 's ease-') + (has3d ? (prefix + '-transform:translate3d(0,' + px + 'px,0);') : ('top:' + px + '')));
if (iv[index]) {
if (time && orig !== undefined) {
t.closest('.dwwl').addClass('dwa');
iv[index] = setInterval(function () {
t.data('pos', Math.round(getVal(i, orig, val - orig, time)));
if (i &= time) {
t.data('pos', val);
* Gets the selected wheel values, formats it, and set the value of the scroller instance.
* If input parameter is true, populates the associated input element.
* @param {Boolean} sc - Scroll the wheel in position.
* @param {Boolean} fill - Also set the value of the associated input element. Default is true.
* @param {Number} time - Animation time
* @param {Boolean} temp - If true, then only set the temporary value.(only scroll there but not set the value)
that.setValue = function (sc, fill, time, temp) {
if (!$.isArray(that.temp)) {
that.temp = s.parseValue(that.temp + '', that);
if (visible && sc) {
scrollToPos(time);
v = s.formatResult(that.temp);
if (!temp) {
that.values = that.temp.slice(0);
that.val =
if (fill) {
if (input) {
elm.val(v).trigger('change');
that.getValues = function () {
var ret = [],
for (i in that._selectedValues) {
ret.push(that._selectedValues[i]);
* Checks if the current selected values are valid together.
* In case of date presets it checks the number of days in a month.
* @param {Number} time - Animation time
* @param {Number} orig - Original value
* @param {Number} i - Currently changed wheel index, -1 if initial validation.
* @param {Number} dir - Scroll direction
that.validate = function (i, dir, time, orig) {
scrollToPos(time, i, true, dir, orig);
that.change = function (manual) {
v = s.formatResult(that.temp);
if (s.display == 'inline') {
that.setValue(false, manual);
$('.dwv', dw).html(formatHeader(v));
if (manual) {
event('onChange', [v]);
* Changes the values of a wheel, and scrolls to the correct position
that.changeWheel = function (idx, time) {
var i = 0,
for (j in s.wheels) {
for (k in s.wheels[j]) {
if ($.inArray(i, idx) & -1) {
warr[i] = s.wheels[j][k];
$('.dw-ul', dw).eq(i).html(generateWheelItems(i));
if (!nr) {
position();
scrollToPos(time, undefined, true);
* Return true if the scroller is currently visible.
that.isVisible = function () {
that.tap = function (el, handler) {
var startX,
if (s.tap) {
el.bind('touchstart', function (e) {
e.preventDefault();
startX = getCoord(e, 'X');
startY = getCoord(e, 'Y');
}).bind('touchend', function (e) {
// If movement is less than 20px, fire the click event handler
if (Math.abs(getCoord(e, 'X') - startX) & 20 && Math.abs(getCoord(e, 'Y') - startY) & 20) {
handler.call(this, e);
setTimeout(function () {
el.bind('click', function (e) {
if (!tap) {
// If handler was not called on touchend,
handler.call(this, e);
* Shows the scroller instance.
* @param {Boolean} prevAnim - Prevent animation if true
that.show = function (prevAnim) {
if (s.disabled || visible) {
if (s.display == 'top') {
anim = 'slidedown';
if (s.display == 'bottom') {
anim = 'slideup';
// Parse value from input
event('onBeforeShow', [dw]);
// Create wheels
var l = 0,
mAnim = '';
if (anim && !prevAnim) {
mAnim = 'dw-' + anim + ' dw-in';
// Create wheels containers
var html = '&div class=&dw-trans ' + s.theme + ' dw-' + s.display + '&&' + (s.display == 'inline' ? '&div class=&dw dwbg dwi&&&div class=&dwwr&&' : '&div class=&dw-persp&&' + '&div class=&dwo&&&/div&&div class=&dw dwbg ' + mAnim + '&&&div class=&dw-arrw&&&div class=&dw-arrw-i&&&div class=&dw-arr&&&/div&&/div&&/div&&div class=&dwwr&&' + (s.headerText ? '&div class=&dwv&&&/div&' : ''));
for (i = 0; i & s.wheels. i++) {
html += '&div class=&dwc' + (s.mode != 'scroller' ? ' dwpm' : ' dwsc') + (s.showLabel ? '' : ' dwhl') + '&&&div class=&dwwc dwrc&&&table cellpadding=&0& cellspacing=&0&&&tr&';
// Create wheels
for (label in s.wheels[i]) {
warr[l] = s.wheels[i][label];
html += '&td&&div class=&dwwl dwrc dwwl' + l + '&&' + (s.mode != 'scroller' ? '&div class=&dwwb dwwbp& style=&height:' + hi + 'line-height:' + hi + '&&&span&+&/span&&/div&&div class=&dwwb dwwbm& style=&height:' + hi + 'line-height:' + hi + '&&&span&&&/span&&/div&' : '') + '&div class=&dwl&&' + label + '&/div&&div class=&dww& style=&height:' + (s.rows * hi) + 'min-width:' + s.width + '&&&div class=&dw-ul&&';
// Create wheel values
html += generateWheelItems(l);
html += '&/div&&div class=&dwwo&&&/div&&/div&&div class=&dwwol&&&/div&&/div&&/td&';
html += '&/tr&&/table&&/div&&/div&';
html += (s.display != 'inline' ? '&div class=&dwbc' + (s.button3 ? ' dwbc-p' : '') + '&&&span class=&dwb-s&&&span class=&dwb&&' + s.setText + '&/span&&/span&'
'&/div&&/div&' : '') + '&/div&&/div&&/div&';
dw = $(html);
scrollToPos();
event('onMarkupReady', [dw]);
if (s.display != 'inline') {
dw.appendTo('body');
// Remove animation class
setTimeout(function () {
dw.removeClass('dw-trans').find('.dw').removeClass(mAnim);
} else if (elm.is('div')) {
elm.html(dw);
dw.insertAfter(elm);
event('onMarkupInserted', [dw]);
// Theme init
theme.init(dw, that);
if (s.display != 'inline') {
// Init buttons
that.tap($('.dwb-s span', dw), function () {
if (that.hide(false, 'set') !== false) {
that.setValue(false, true);
event('onSelect', [that.val]);
that.tap($('.dwb-c span', dw), function () {
that.cancel();
if (s.button3) {
that.tap($('.dwb-n span', dw), s.button3);
// prevent scrolling if not specified otherwise
if (s.scrollLock) {
dw.bind('touchmove', function (e) {
if (mh &= wh && mw &= ww) {
e.preventDefault();
// Disable inputs to prevent bleed through (Android bug)
$('input,select,button').each(function () {
if (!$(this).prop('disabled')) {
$(this).addClass('dwtd').prop('disabled', true);
// Set position
position();
$(window).bind('resize.dw', function () {
// Sometimes scrollTop is not correctly set, so we wait a little
clearTimeout(debounce);
debounce = setTimeout(function () {
position(true);
dw.delegate('.dwwl', 'DOMMouseScroll mousewheel', function (e) {
if (!isReadOnly(this)) {
e.preventDefault();
e = e.originalE
var delta = e.wheelDelta ? (e.wheelDelta / 120) : (e.detail ? (-e.detail / 3) : 0),
t = $('.dw-ul', this),
p = +t.data('pos'),
val = Math.round(p - delta);
setGlobals(t);
calc(t, val, delta & 0 ? 1 : 2);
}).delegate('.dwb, .dwwb', START_EVENT, function (e) {
// Active button
$(this).addClass('dwb-a');
}).delegate('.dwwb', START_EVENT, function (e) {
e.stopPropagation();
e.preventDefault();
var w = $(this).closest('.dwwl');
if (testTouch(e) && !isReadOnly(w) && !w.hasClass('dwa')) {
// + Button
var t = w.find('.dw-ul'),
func = $(this).hasClass('dwwbp') ? plus :
setGlobals(t);
clearInterval(timer);
timer = setInterval(function () { func(t); }, s.delay);
}).delegate('.dwwl', START_EVENT, function (e) {
// Prevent scroll
e.preventDefault();
// Scroll start
if (testTouch(e) && !move && !isReadOnly(this) && !click) {
$(document).bind(MOVE_EVENT, onMove);
target = $('.dw-ul', this);
scrollable = s.mode != 'clickpick';
pos = +target.data('pos');
setGlobals(target);
moved = iv[index] !== // Don't allow tap, if still moving
start = getCoord(e, 'Y');
startTime = new Date();
that.scroll(target, index, pos, 0.001);
if (scrollable) {
target.closest('.dwwl').addClass('dwa');
event('onShow', [dw, v]);
* Hides the scroller instance.
that.hide = function (prevAnim, btn) {
// If onClose handler returns false, prevent hide
if (!visible || event('onClose', [v, btn]) === false) {
// Re-enable temporary disabled fields
$('.dwtd').prop('disabled', false).removeClass('dwtd');
elm.blur();
// Hide wheels and overlay
if (s.display != 'inline' && anim && !prevAnim) {
dw.addClass('dw-trans').find('.dw').addClass('dw-' + anim + ' dw-out');
setTimeout(function () {
dw.remove();
dw.remove();
pixels = {};
// Stop positioning on window resize
$(window).unbind('.dw');
* Cancel and hide the scroller instance.
that.cancel = function () {
if (that.hide(false, 'cancel') !== false) {
event('onCancel', [that.val]);
* Scroller initialization.
that.init = function (ss) {
// Get theme defaults
theme = extend({ defaults: {}, init: empty }, ms.themes[ss.theme || s.theme]);
// Get language defaults
lang = ms.i18n[ss.lang || s.lang];
extend(settings, ss); // Update original user settings
extend(s, theme.defaults, lang, settings);
that.settings =
// Unbind all events (if re-init)
elm.unbind('.dw');
var preset = ms.presets[s.preset];
if (preset) {
pres = preset.call(e, that);
extend(s, pres, settings); // Load preset settings
extend(methods, pres.methods); // Extend core methods
// Set private members
m = Math.floor(s.rows / 2);
if (elm.data('dwro') !== undefined) {
e.readOnly = bool(elm.data('dwro'));
if (visible) {
that.hide();
if (s.display == 'inline') {
that.show();
if (input && s.showOnFocus) {
// Set element readonly, save original state
elm.data('dwro', e.readOnly);
e.readOnly =
// Init show datewheel
elm.bind('focus.dw', function () { that.show(); });
that.trigger = function (name, params) {
return event(name, params);
that.values =
that.val =
that.temp =
that._selectedValues = {}; // [];
that.init(settings);
function testProps(props) {
for (i in props) {
if (mod[props[i]] !== undefined) {
function testPrefix() {
var prefixes = ['Webkit', 'Moz', 'O', 'ms'],
for (p in prefixes) {
if (testProps([prefixes[p] + 'Transform'])) {
return '-' + prefixes[p].toLowerCase();
return '';
function getInst(e) {
return scrollers[e.id];
function getCoord(e, c) {
var org = e.originalEvent,
ct = e.changedT
return ct || (org && org.changedTouches) ? (org ? org.changedTouches[0]['page' + c] : ct[0]['page' + c]) : e['page' + c];
function bool(v) {
return (v === true || v == 'true');
function constrain(val, min, max) {
val = val & max ? max :
val = val & min ? min :
function calc(t, val, dir, anim, orig) {
val = constrain(val, min, max);
var cell = $('.dw-li', t).eq(val),
o = orig === undefined ? val : orig,
idx = index,
time = anim ? (val == o ? 0.1 : Math.abs((val - o) * 0.1)) : 0;
// Set selected scroller value
inst.temp[idx] = cell.attr('data-val');
inst.scroll(t, idx, val, time, orig);
setTimeout(function () {
// Validate
inst.validate(idx, dir, time, orig);
function init(that, method, args) {
if (methods[method]) {
return methods[method].apply(that, Array.prototype.slice.call(args, 1));
if (typeof method === 'object') {
return methods.init.call(that, method);
var scrollers = {},
empty = function () { },
inst, // Current instance
date = new Date(),
uuid = date.getTime(),
startTime,
scrollable,
mod = document.createElement('modernizr').style,
has3d = testProps(['perspectiveProperty', 'WebkitPerspective', 'MozPerspective', 'OPerspective', 'msPerspective']),
prefix = testPrefix(),
extend = $.extend,
START_EVENT = 'touchstart mousedown',
MOVE_EVENT = 'touchmove mousemove',
END_EVENT = 'touchend mouseup',
onMove = function (e) {
if (scrollable) {
e.preventDefault();
stop = getCoord(e, 'Y');
inst.scroll(target, index, constrain(pos + (start - stop) / h, min - 1, max + 1));
defaults = {
// Options
width: 70,
height: 40,
delay: 300,
disabled: false,
readonly: false,
showOnFocus: true,
showLabel: true,
wheels: [],
theme: '',
headerText: '{value}',
display: 'modal',
mode: 'scroller',
preset: '',
lang: 'en-US',
setText: 'Set',
scrollLock: true,
tap: true,
formatResult: function (d) {
return d.join(' ');
parseValue: function (value, inst) {
var w = inst.settings.wheels,
val = value.split(' '),
for (i = 0; i & w. i++) {
for (l in w[i]) {
if (w[i][l][val[j]] !== undefined) {
ret.push(val[j]);
for (v in w[i][l]) { // Select first value from wheel
ret.push(v);
methods = {
init: function (options) {
if (options === undefined) {
options = {};
return this.each(function () {
if (!this.id) {
uuid += 1;
this.id = 'scoller' +
scrollers[this.id] = new Scroller(this, options);
enable: function () {
return this.each(function () {
var inst = getInst(this);
if (inst) {
inst.enable();
disable: function () {
return this.each(function () {
var inst = getInst(this);
if (inst) {
inst.disable();
isDisabled: function () {
var inst = getInst(this[0]);
if (inst) {
return inst.settings.
isVisible: function () {
var inst = getInst(this[0]);
if (inst) {
return inst.isVisible();
option: function (option, value) {
return this.each(function () {
var inst = getInst(this);
if (inst) {
var obj = {};
if (typeof option === 'object') {
obj[option] =
inst.init(obj);
setValue: function (d, fill, time, temp) {
return this.each(function () {
var inst = getInst(this);
if (inst) {
inst.temp =
inst.setValue(true, fill, time, temp);
getInst: function () {
return getInst(this[0]);
getValue: function () {
var inst = getInst(this[0]);
if (inst) {
return inst.
getValues: function () {
var inst = getInst(this[0]);
if (inst) {
return inst.getValues();
show: function () {
var inst = getInst(this[0]);
if (inst) {
return inst.show();
hide: function () {
return this.each(function () {
var inst = getInst(this);
if (inst) {
inst.hide();
destroy: function () {
return this.each(function () {
var inst = getInst(this);
if (inst) {
inst.hide();
$(this).unbind('.dw');
delete scrollers[this.id];
if ($(this).is('input')) {
this.readOnly = bool($(this).data('dwro'));
$(document).bind(END_EVENT, function (e) {
if (move) {
var time = new Date() - startTime,
val = constrain(pos + (start - stop) / h, min - 1, max + 1),
ttop = target.offset().
if (time & 300) {
speed = (stop - start) /
dist = (speed * speed) / (2 * 0.0006);
if (stop - start & 0) {
dist = stop -
tindex = Math.round(pos - dist / h);
if (!dist && !moved) { // this is a &tap&
var idx = Math.floor((stop - ttop) / h),
li = $('.dw-li', target).eq(idx),
if (inst.trigger('onValueTap', [li]) !== false) {
li.addClass('dw-hl'); // Highlight
setTimeout(function () {
li.removeClass('dw-hl');
if (scrollable) {
calc(target, tindex, 0, true, Math.round(val));
$(document).unbind(MOVE_EVENT, onMove);
if (click) {
clearInterval(timer);
$('.dwb-a').removeClass('dwb-a');
}).bind('mouseover mouseup mousedown click', function (e) { // Prevent standard behaviour on body click
if (tap) {
e.stopPropagation();
e.preventDefault();
$.fn.mobiscroll = function (method) {
extend(this, $.mobiscroll.shorts);
return init(this, method, arguments);
$.mobiscroll = $.mobiscroll || {
* Set settings for all instances.
* @param {Object} o - New default settings.
setDefaults: function (o) {
extend(defaults, o);
presetShort: function (name) {
this.shorts[name] = function (method) {
return init(this, extend(method, { preset: name }), arguments);
shorts: {},
presets: {},
themes: {},
$.scroller = $.scroller || $.
$.fn.scroller = $.fn.scroller || $.fn.
+})(jQuery);
Index: mobiscroll.ios-2.5.1.js
===================================================================
--- mobiscroll.ios-2.5.1.js (revision 0)
+++ mobiscroll.ios-2.5.1.js (revision 8)
@@ -0,0 +1,15 @@
+(function ($) {
$.mobiscroll.themes.ios = {
defaults: {
dateOrder: 'MMdyy',
height: 30,
width: 55,
headerText: false,
showLabel: false,
useShortLabels: true
+})(jQuery);
Index: mobiscroll.datetime-2.5.1-zh.js
===================================================================
--- mobiscroll.datetime-2.5.1-zh.js (revision 0)
+++ mobiscroll.datetime-2.5.1-zh.js (revision 8)
@@ -0,0 +1,18 @@
+(function ($) {
$.mobiscroll.i18n.zh = $.extend($.mobiscroll.i18n.zh, {
dateFormat: 'yy-mm-dd',
dateOrder: 'yymmdd',
dayNames: ['周日', '周一;', '周二;', '周三', '周四', '周五', '周六'],
dayNamesShort: ['日', '一', '二', '三', '四', '五', '六'],
dayText: '日',
hourText: '时',
minuteText: '分',
monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
monthNamesShort: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
monthText: '月',
secText: '秒',
timeFormat: 'HH:ii',
timeWheels: 'HHii',
yearText: '年'
+})(jQuery);
Index: mobiscroll.list-2.5.1.js
===================================================================
--- mobiscroll.list-2.5.1.js (revision 0)
+++ mobiscroll.list-2.5.1.js (revision 8)
@@ -0,0 +1,394 @@
+/*jslint eqeq: true, plusplus: true, undef: true, sloppy: true, vars: true, forin: true */
+(function ($) {
var ms = $.mobiscroll,
defaults = {
invalid: [],
showInput: true,
inputClass: ''
function (inst) {
var s = $.extend({}, defaults, inst.settings),
elm = $(this),
id = this.id + '_dummy',
timer = {},
wa = s.wheelArray || createWheelArray(elm),
labels = generateLabels(lvl),
currWheelVector = [],
fwv = firstWheelVector(wa),
w = generateWheelsFromVector(fwv, lvl);
* Disables the invalid items on the wheels
* @param {Object} dw - the jQuery mobiscroll object
* @param {Number} nrWheels - the number of the current wheels
* @param {Array} whArray - The wheel array objects containing the wheel tree
* @param {Array} whVector - the wheel vector containing the current keys
function setDisabled(dw, nrWheels, whArray, whVector) {
var i = 0;
while (i & nrWheels) {
var currWh = $('.dwwl' + i, dw),
inv = getInvalidKeys(whVector, i, whArray);
$.each(inv, function (i, v) {
$('.dw-li[data-val=&' + v + '&]', currWh).removeClass('dw-v');
* Returns the invalid keys of one wheel as an array
* @param {Array} whVector - the wheel vector used to search for the wheel in the wheel array
* @param {Number} index - index of the wheel in the wheel vector, that we are interested in
* @param {Array} whArray - the wheel array we are searching in
* @return {Array} - list of invalid keys
function getInvalidKeys(whVector, index, whArray) {
var i = 0,
whObjA = whArray,
invalids = [];
while (i & index) {
var ii = whVector[i];
//whObjA = whObjA[ii].
for (n in whObjA) {
if (whObjA[n].key == ii) {
whObjA = whObjA[n].
while (i & whObjA.length) {
if (whObjA[i].invalid) {
invalids.push(whObjA[i].key);
* Creates a Boolean vector with true values (except one) that can be used as the readonly vector
* n - the length of the vector
* i - the index of the value that's going to be false
function createROVector(n, i) {
var a = [];
while (n) {
* Creates a labels vector, from values if they are defined, otherwise from numbers
* l - the length of the vector
function generateLabels(l) {
var a = [],
for (i = 0; i & i++) {
a[i] = s.labels && s.labels[i] ? s.labels[i] :
* Creates the wheel array from the vector provided
* wv - wheel vector containing the values that should be selected on the wheels
* l - the length of the wheel array
function generateWheelsFromVector(wv, l, index) {
var i = 0, j, obj, chInd,
if (l) { // if length is defined we need to generate that many wheels (even if they are empty)
for (j = 0; j & j++) {
w[j] = {};
w[j][labels[j]] = {}; // each wheel will have a label generated by the generateLabels method
while (i & wv.length) { // we generate the wheels until the length of the wheel vector
w[i] = {};
w[i][labels[i]] = getWheelFromObjA(wtObjA);
while (j & wtObjA.length && chInd === undefined) {
if (wtObjA[j].key == wv[i] && ((index !== undefined && i &= index) || index === undefined)) {
if (chInd !== undefined && wtObjA[chInd].children) {
wtObjA = wtObjA[chInd].
} else if ((obj = getFirstValidItemObjOrInd(wtObjA)) && obj.children) {
wtObjA = obj.
* Returns the first valid Wheel Node Object or its index from a Wheel Node Object Array
* getInd - if it is true then the return value is going to be the index, otherwise the object itself
function getFirstValidItemObjOrInd(wtObjA, getInd) {
if (!wtObjA) {
var i = 0,
while (i & wtObjA.length) {
if (!(obj = wtObjA[i++]).invalid) {
return getInd ? i - 1 :
function getWheelFromObjA(objA) {
var wheel = {},
while (j & objA.length) {
wheel[objA[j].key] = objA[j++].
* Hides the last i number of wheels
* i - the last number of wheels that has to be hidden
function hideWheels(dw, i) {
$('.dwc', dw).css('display', '').slice(i).hide();
* Generates the first wheel vector from the wheeltree
* wt - the wheel tree object
* uses the lvl global variable to determine the length of the vector
function firstWheelVector(wa) {
var t = [],
ndObjA = wa,
ok = true,
while (ok) {
obj = getFirstValidItemObjOrInd(ndObjA);
t[i++] = obj.
if (ok = obj.children) {
ndObjA = obj.
* Calculates the level of a wheel vector and the new wheel vector, depending on current wheel vector and the index of the changed wheel
* wv - current wheel vector
* index - index of the changed wheel
function calcLevelOfVector2(wv, index) {
var t = [],
ndObjA = wa,
next = false,
childName,
if (wv[lvl] !== undefined && lvl &= index) {
childName = wv[lvl];
while (i & ndObjA.length && chInd === undefined) {
if (ndObjA[i].key == wv[lvl] && !ndObjA[i].invalid) {
chInd = getFirstValidItemObjOrInd(ndObjA, true);
childName = ndObjA[chInd].
next = chInd !== undefined ? ndObjA[chInd].children :
t[lvl] = childN
while (next) {
ndObjA = ndObjA[chInd].
if (wv[lvl] !== undefined && lvl &= index) {
childName = wv[lvl];
while (i & ndObjA.length && chInd === undefined) {
if (ndObjA[i].key == wv[lvl] && !ndObjA[i].invalid) {
chInd = getFirstValidItemObjOrInd(ndObjA, true);
chInd = chInd === false ? undefined : chI
childName = ndObjA[chInd].
next = chInd !== undefined && getFirstValidItemObjOrInd(ndObjA[chInd].children) ? ndObjA[chInd].children :
t[lvl] = childN
lvl: lvl + 1,
nVector: t
}; // return the calculated level and the wheel vector as an object
function createWheelArray(ul) {
var wheelArray = [];
lvl = lvl & ilvl++ ? lvl :
ul.children('li').each(function (index) {
var that = $(this),
c = that.clone();
c.children('ul,ol').remove();
var v = c.html().replace(/^\s\s*/, '').replace(/\s\s*$/, ''),
inv = that.data('invalid') ? true : false,
wheelObj = {
key: that.data('val') || index,
invalid: inv,
children: null
nest = that.children('ul,ol');
if (nest.length) {
wheelObj.children = createWheelArray(nest);
wheelArray.push(wheelObj);
return wheelA
$('#' + id).remove(); // Remove input if exists
if (s.showInput) {
input = $('&input type=&text& id=&' + id + '& value=&& class=&' + s.inputClass + '& readonly /&').insertBefore(elm);
inst.settings.anchor = // give the core the input element for the bubble positioning
if (s.showOnFocus) {
input.focus(function () {
inst.show();
if (!s.wheelArray) {
elm.hide().closest('.ui-field-contain').trigger('create');
width: 50,
wheels: w,
headerText: false,
onBeforeShow: function (dw) {
var t = inst.
currWheelVector = t.slice(0);
inst.settings.wheels = generateWheelsFromVector(t, lvl, lvl);
onSelect: function (v, inst) {
if (input) {
input.val(v);
onChange: function (v, inst) {
if (input && s.display == 'inline') {
input.val(v);
onClose: function () {
if (input) {
input.blur();
onShow: function (dw) {
$('.dwwl', dw).bind('mousedown touchstart', function () {
clearTimeout(timer[$('.dwwl', dw).index(this)]);
validate: function (dw, index, time) {
var t = inst.
if ((index !== undefined && currWheelVector[index] != t[index]) || (index === undefined && !prevent)) {
inst.settings.wheels = generateWheelsFromVector(t, null, index);
var args = [],
i = (index || 0) + 1,
o = calcLevelOfVector2(t, index);
if (index !== undefined) {
inst.temp = o.nVector.slice(0);
while (i & o.lvl) {
args.push(i++);
hideWheels(dw, o.lvl);
currWheelVector = inst.temp.slice(0);
if (args.length) {
inst.settings.readonly = createROVector(lvl, index);
clearTimeout(timer[index]);
timer[index] = setTimeout(function () {
inst.changeWheel(args);
inst.settings.readonly =
}, time * 1000);
setDisabled(dw, o.lvl, wa, inst.temp);
var o = calcLevelOfVector2(t, t.length);
setDisabled(dw, o.lvl, wa, t);
hideWheels(dw, o.lvl);
$.each(['list', 'image', 'treelist'], function (i, v) {
ms.presets[v] =
ms.presetShort(v);
+})(jQuery);
Index: mobiscroll.datetime-2.5.1.js
===================================================================
--- mobiscroll.datetime-2.5.1.js (revision 0)
+++ mobiscroll.datetime-2.5.1.js (revision 8)
@@ -0,0 +1,657 @@
+/*jslint eqeq: true, plusplus: true, undef: true, sloppy: true, vars: true, forin: true */
+(function ($) {
var ms = $.mobiscroll,
date = new Date(),
defaults = {
dateFormat: 'mm/dd/yy',
dateOrder: 'mmddy',
timeWheels: 'hhiiA',
timeFormat: 'hh:ii A',
startYear: date.getFullYear() - 100,
endYear: date.getFullYear() + 1,
monthNames: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
monthNamesShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
dayNames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
dayNamesShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
shortYearCutoff: '+10',
monthText: 'Month',
dayText: 'Day',
yearText: 'Year',
hourText: 'Hours',
minuteText: 'Minutes',
secText: 'Seconds',
ampmText: '&',
nowText: 'Now',
showNow: false,
stepHour: 1,
stepMinute: 1,
stepSecond: 1,
separator: ' '
preset = function (inst) {
var that = $(this),
html5def = {},
// Force format for html5 date inputs (experimental)
if (that.is('input')) {
switch (that.attr('type')) {
case 'date':
format = 'yy-mm-dd';
case 'datetime':
format = 'yy-mm-ddTHH:ii:ssZ';
case 'datetime-local':
format = 'yy-mm-ddTHH:ii:ss';
case 'month':
format = 'yy-mm';
html5def.dateOrder = 'mmyy';
case 'time':
format = 'HH:ii:ss';
// Check for min/max attributes
var min = that.attr('min'),
max = that.attr('max');
if (min) {
html5def.minDate = ms.parseDate(format, min);
if (max) {
html5def.maxDate = ms.parseDate(format, max);
// Set year-month-day order
var s = $.extend({}, defaults, html5def, inst.settings),
offset = 0,
wheels = [],
f = { y: 'getFullYear', m: 'getMonth', d: 'getDate', h: getHour, i: getMinute, s: getSecond, a: getAmPm },
p = s.preset,
dord = s.dateOrder,
tord = s.timeWheels,
regen = dord.match(/D/),
ampm = tord.match(/a/i),
hampm = tord.match(/h/),
hformat = p == 'datetime' ? s.dateFormat + s.separator + s.timeFormat : p == 'time' ? s.timeFormat : s.dateFormat,
defd = new Date(),
stepH = s.stepHour,
stepM = s.stepMinute,
stepS = s.stepSecond,
mind = s.minDate || new Date(s.startYear, 0, 1),
maxd = s.maxDate || new Date(s.endYear, 11, 31, 23, 59, 59);
inst.settings =
format = format ||
if (p.match(/date/i)) {
// Determine the order of year, month, day wheels
$.each(['y', 'm', 'd'], function (j, v) {
i = dord.search(new RegExp(v, 'i'));
if (i & -1) {
ord.push({ o: i, v: v });
ord.sort(function (a, b) { return a.o & b.o ? 1 : -1; });
$.each(ord, function (i, v) {
var w = {};
for (k = 0; k & 3; k++) {
if (k == o.y) {
w[s.yearText] = {};
var start = mind.getFullYear(),
end = maxd.getFullYear();
for (i = i &= i++) {
w[s.yearText][i] = dord.match(/yy/i) ? i : (i + '').substr(2, 2);
} else if (k == o.m) {
w[s.monthText] = {};
for (i = 0; i & 12; i++) {
var str = dord.replace(/[dy]/gi, '').replace(/mm/, i & 9 ? '0' + (i + 1) : i + 1).replace(/m/, (i + 1));
w[s.monthText][i] = str.match(/MM/) ? str.replace(/MM/, '&span class=&dw-mon&&' + s.monthNames[i] + '&/span&') : str.replace(/M/, '&span class=&dw-mon&&' + s.monthNamesShort[i] + '&/span&');
} else if (k == o.d) {
w[s.dayText] = {};
for (i = 1; i & 32; i++) {
w[s.dayText][i] = dord.match(/dd/i) && i & 10 ? '0' + i :
wheels.push(w);
if (p.match(/time/i)) {
// Determine the order of hours, minutes, seconds wheels
$.each(['h', 'i', 's', 'a'], function (i, v) {
i = tord.search(new RegExp(v, 'i'));
if (i & -1) {
ord.push({ o: i, v: v });
ord.sort(function (a, b) {
return a.o & b.o ? 1 : -1;
$.each(ord, function (i, v) {
o[v.v] = offset +
for (k = k & offset + 4; k++) {
if (k == o.h) {
w[s.hourText] = {};
for (i = 0; i & (hampm ? 12 : 24); i += stepH) {
w[s.hourText][i] = hampm && i == 0 ? 12 : tord.match(/hh/i) && i & 10 ? '0' + i :
} else if (k == o.i) {
w[s.minuteText] = {};
for (i = 0; i & 60; i += stepM) {
w[s.minuteText][i] = tord.match(/ii/) && i & 10 ? '0' + i :
} else if (k == o.s) {
w[s.secText] = {};
for (i = 0; i & 60; i += stepS) {
w[s.secText][i] = tord.match(/ss/) && i & 10 ? '0' + i :
} else if (k == o.a) {
var upper = tord.match(/A/);
w[s.ampmText] = { 0: upper ? 'AM' : 'am', 1: upper ? 'PM' : 'pm' };
wheels.push(w);
function get(d, i, def) {
if (o[i] !== undefined) {
return +d[o[i]];
if (def !== undefined) {
return defd[f[i]] ? defd[f[i]]() : f[i](defd);
function step(v, st) {
return Math.floor(v / st) *
function getHour(d) {
var hour = d.getHours();
hour = hampm && hour &= 12 ? hour - 12 :
return step(hour, stepH);
function getMinute(d) {
return step(d.getMinutes(), stepM);
function getSecond(d) {
return step(d.getSeconds(), stepS);
function getAmPm(d) {
return ampm && d.getHours() & 11 ? 1 : 0;
function getDate(d) {
var hour = get(d, 'h', 0);
return new Date(get(d, 'y'), get(d, 'm'), get(d, 'd', 1), get(d, 'a') ? hour + 12 : hour, get(d, 'i', 0), get(d, 's', 0));
inst.setDate = function (d, fill, time, temp) {
// Set wheels
for (i in o) {
this.temp[o[i]] = d[f[i]] ? d[f[i]]() : f[i](d);
this.setValue(true, fill, time, temp);
inst.getDate = function (d) {
return getDate(d);
button3Text: s.showNow ? s.nowText : undefined,
button3: s.showNow ? function () { inst.setDate(new Date(), false, 0.3, true); } : undefined,
wheels: wheels,
headerText: function (v) {
return ms.formatDate(hformat, getDate(inst.temp), s);
* Builds a date object from the wheel selections and formats it to the given date/time format
* @param {Array} d - An array containing the selected wheel values
* @return {String} - The formatted date string
formatResult: function (d) {
return ms.formatDate(format, getDate(d), s);
* Builds a date object from the input value and returns an array to set wheel values
* @return {Array} - An array containing the wheel values to set
parseValue: function (val) {
var d = new Date(),
result = [];
d = ms.parseDate(format, val, s);
} catch (e) {
// Set wheels
for (i in o) {
result[o[i]] = d[f[i]] ? d[f[i]]() : f[i](d);
* Validates the selected date to be in the minDate / maxDate range and sets unselectable values to disabled
* @param {Object} dw - jQuery object containing the generated html
* @param {Integer} [i] - Index of the changed wheel, not set for initial validation
validate: function (dw, i) {
var temp = inst.temp, //.slice(0),
mins = { y: mind.getFullYear(), m: 0, d: 1, h: 0, i: 0, s: 0, a: 0 },
maxs = { y: maxd.getFullYear(), m: 11, d: 31, h: step(hampm ? 11 : 23, stepH), i: step(59, stepM), s: step(59, stepS), a: 1 },
minprop = true,
$.each(['y', 'm', 'd', 'a', 'h', 'i', 's'], function (x, i) {
if (o[i] !== undefined) {
var min = mins[i],
max = maxs[i],
maxdays = 31,
val = get(temp, i),
t = $('.dw-ul', dw).eq(o[i]),
if (i == 'd') {
y = get(temp, 'y');
m = get(temp, 'm');
maxdays = 32 - new Date(y, m, 32).getDate();
if (regen) {
$('.dw-li', t).each(function () {
var that = $(this),
d = that.data('val'),
w = new Date(y, m, d).getDay(),
str = dord.replace(/[my]/gi, '').replace(/dd/, d & 10 ? '0' + d : d).replace(/d/, d);
$('.dw-i', that).html(str.match(/DD/) ? str.replace(/DD/, '&span class=&dw-day&&' + s.dayNames[w] + '&/span&') : str.replace(/D/, '&span class=&dw-day&&' + s.dayNamesShort[w] + '&/span&'));
if (minprop && mind) {
min = mind[f[i]] ? mind[f[i]]() : f[i](mind);
if (maxprop && maxd) {
max = maxd[f[i]] ? maxd[f[i]]() : f[i](maxd);
if (i != 'y') {
var i1 = $('.dw-li', t).index($('.dw-li[data-val=&' + min + '&]', t)),
i2 = $('.dw-li', t).index($('.dw-li[data-val=&' + max + '&]', t));
$('.dw-li', t).removeClass('dw-v').slice(i1, i2 + 1).addClass('dw-v');
if (i == 'd') { // Hide days not in month
$('.dw-li', t).removeClass('dw-h').slice(maxdays).addClass('dw-h');
if (val & min) {
if (val & max) {
if (minprop) {
minprop = val ==
if (maxprop) {
maxprop = val ==
// Disable some days
if (s.invalid && i == 'd') {
var idx = [];
// Disable exact dates
if (s.invalid.dates) {
$.each(s.invalid.dates, function (i, v) {
if (v.getFullYear() == y && v.getMonth() == m) {
idx.push(v.getDate() - 1);
// Disable days of week
if (s.invalid.daysOfWeek) {
var first = new Date(y, m, 1).getDay(),
$.each(s.invalid.daysOfWeek, function (i, v) {
for (j = v - j & j += 7) {
if (j &= 0) {
idx.push(j);
// Disable days of month
if (s.invalid.daysOfMonth) {
$.each(s.invalid.daysOfMonth, function (i, v) {
v = (v + '').split('/');
if (v[1]) {
if (v[0] - 1 == m) {
idx.push(v[1] - 1);
idx.push(v[0] - 1);
$.each(idx, function (i, v) {
$('.dw-li', t).eq(v).removeClass('dw-v');
// Set modified value
temp[o[i]] =
methods: {
* Returns the currently selected date.
* @param {Boolean} temp - If true, return the currently shown date on the picker, otherwise the last selected one
* @return {Date}
getDate: function (temp) {
var inst = $(this).mobiscroll('getInst');
if (inst) {
return inst.getDate(temp ? inst.temp : inst.values);
* Sets the selected date
* @param {Date} d - Date to select.
* @param {Boolean} [fill] - Also set the value of the associated input element. Default is true.
* @return {Object} - jQuery object to maintain chainability
setDate: function (d, fill, time, temp) {
if (fill == undefined) {
return this.each(function () {
var inst = $(this).mobiscroll('getInst');
if (inst) {
inst.setDate(d, fill, time, temp);
$.each(['date', 'time', 'datetime'], function (i, v) {
ms.presets[v] =
ms.presetShort(v);
* Format a date into a string value with a specified format.
* @param {String} format - Output format.
* @param {Date} date - Date to format.
* @param {Object} settings - Settings.
* @return {String} - Returns the formatted date string.
ms.formatDate = function (format, date, settings) {
if (!date) {
var s = $.extend({}, defaults, settings),
look = function (m) { // Check whether a format character is doubled
var n = 0;
while (i + 1 & format.length && format.charAt(i + 1) == m) {
f1 = function (m, val, len) { // Format a number, with leading zero if necessary
var n = '' +
if (look(m)) {
while (n.length & len) {
n = '0' +
f2 = function (m, val, s, l) { // Format a name, short or long as requested
return (look(m) ? l[val] : s[val]);
output = '',
for (i = 0; i & format. i++) {
if (literal) {
if (format.charAt(i) == &'& && !look(&'&)) {
output += format.charAt(i);
switch (format.charAt(i)) {
case 'd':
output += f1('d', date.getDate(), 2);
case 'D':
output += f2('D', date.getDay(), s.dayNamesShort, s.dayNames);
case 'o':
output += f1('o', (date.getTime() - new Date(date.getFullYear(), 0, 0).getTime()) / );
case 'm':
output += f1('m', date.getMonth() + 1, 2);
case 'M':
output += f2('M', date.getMonth(), s.monthNamesShort, s.monthNames);
case 'y':
output += (look('y') ? date.getFullYear() : (date.getYear() % 100 & 10 ? '0' : '') + date.getYear() % 100);
case 'h':
var h = date.getHours();
output += f1('h', (h & 12 ? (h - 12) : (h == 0 ? 12 : h)), 2);
case 'H':
output += f1('H', date.getHours(), 2);
case 'i':
output += f1('i', date.getMinutes(), 2);
case 's':
output += f1('s', date.getSeconds(), 2);
case 'a':
output += date.getHours() & 11 ? 'pm' : 'am';
case 'A':
output += date.getHours() & 11 ? 'PM' : 'AM';
case &'&:
if (look(&'&)) {
output += &'&;
output += format.charAt(i);
* Extract a date from a string value with a specified format.
* @param {String} format - Input format.
* @param {String} value - String to parse.
* @param {Object} settings - Settings.
* @return {Date} - Returns the extracted date.
ms.parseDate = function (format, value, settings) {
var def = new Date();
if (!format || !value) {
value = (typeof value == 'object' ? value.toString() : value + '');
var s = $.extend({}, defaults, settings),
shortYearCutoff = s.shortYearCutoff,
year = def.getFullYear(),
month = def.getMonth() + 1,
day = def.getDate(),
hours = def.getHours(),
minutes = def.getMinutes(),
seconds = 0, //def.getSeconds(),
ampm = -1,
literal = false, // Check whether a format character is doubled
lookAhead = function (match) {
var matches = (iFormat + 1 & format.length && format.charAt(iFormat + 1) == match);
if (matches) {
iFormat++;
getNumber = function (match) { // Extract a number from the string value
lookAhead(match);
var size = (match == '@' ? 14 : (match == '!' ? 20 : (match == 'y' ? 4 : (match == 'o' ? 3 : 2)))),
digits = new RegExp('^\\d{1,' + size + '}'),
num = value.substr(iValue).match(digits);
if (!num) {
//throw 'Missing number at position ' + iV
iValue += num[0].
return parseInt(num[0], 10);
getName = function (match, s, l) { // Extract a name from the string value and convert to an index
var names = (lookAhead(match) ? l : s),
for (i = 0; i & names. i++) {
if (value.substr(iValue, names[i].length).toLowerCase() == names[i].toLowerCase()) {
iValue += names[i].
return i + 1;
//throw 'Unknown name at position ' + iV
checkLiteral = function () {
//if (value.charAt(iValue) != format.charAt(iFormat))
//throw 'Unexpected literal at position ' + iV
iValue = 0,
for (iFormat = 0; iFormat & format. iFormat++) {
if (literal) {
if (format.charAt(iFormat) == &'& && !lookAhead(&'&)) {
checkLiteral();
switch (format.charAt(iFormat)) {
case 'd':
day = getNumber('d');
case 'D':
getName('D', s.dayNamesShort, s.dayNames);
case 'o':
doy = getNumber('o');
case 'm':
month = getNumber('m');
case 'M':
month = getName('M', s.monthNamesShort, s.monthNames);
case 'y':
year = getNumber('y');
case 'H':
hours = getNumber('H');
case 'h':
hours = getNumber('h');
case 'i':
minutes = getNumber('i');
case 's':
seconds = getNumber('s');
case 'a':
ampm = getName('a', ['am', 'pm'], ['am', 'pm']) - 1;
case 'A':
ampm = getName('A', ['am', 'pm'], ['am', 'pm']) - 1;
case &'&:
if (lookAhead(&'&)) {
checkLiteral();
checkLiteral();
if (year & 100) {
year += new Date().getFullYear() - new Date().getFullYear() % 100 +
(year &= (typeof shortYearCutoff != 'string' ? shortYearCutoff : new Date().getFullYear() % 100 + parseInt(shortYearCutoff, 10)) ? 0 : -100);
if (doy & -1) {
month = 1;
var dim = 32 - new Date(year, month - 1, 32).getDate();
if (day &= dim) {
} while (true);
hours = (ampm == -1) ? hours : ((ampm && hours & 12) ? (hours + 12) : (!ampm && hours == 12 ? 0 : hours));
var date = new Date(year, month - 1, day, hours, minutes, seconds);
if (date.getFullYear() != year || date.getMonth() + 1 != month || date.getDate() != day) {
throw 'Invalid date';
+})(jQuery);
Index: mobiscroll.android-ics-2.5.2.js
===================================================================
--- mobiscroll.android-ics-2.5.2.js (revision 0)
+++ mobiscroll.android-ics-2.5.2.js (revision 8)
@@ -0,0 +1,18 @@
+(function ($) {
var theme = {
defaults: {
dateOrder: 'Mddyy',
mode: 'mixed',
width: 70,
height: 36,
showLabel: false,
useShortLabels: true
$.mobiscroll.themes['android-ics'] =
$.mobiscroll.themes['android-ics light'] =
+})(jQuery);
(C)&&2013&&Alibaba&&Inc.&&All&&rights&&resvered.
Powered by

我要回帖

更多关于 pagebeforeshow 的文章

 

随机推荐