/** * ydui main */ !function (window) { "use strict"; var doc = window.document, ydui = {}; /** * 直接绑定FastClick */ $(window).on('load', function () { typeof FastClick == 'function' && FastClick.attach(doc.body); }); var util = ydui.util = { /** * 格式化参数 * @param string */ parseOptions: function (string) { if ($.isPlainObject(string)) { return string; } var start = (string ? string.indexOf('{') : -1), options = {}; if (start != -1) { try { options = (new Function('', 'var json = ' + string.substr(start) + '; return JSON.parse(JSON.stringify(json));'))(); } catch (e) { } } return options; }, /** * 页面滚动方法【移动端】 * @type {{lock, unlock}} * lock:禁止页面滚动, unlock:释放页面滚动 */ pageScroll: function () { var fn = function (e) { e.preventDefault(); e.stopPropagation(); }; var islock = false; return { lock: function () { if (islock)return; islock = true; doc.addEventListener('touchmove', fn); }, unlock: function () { islock = false; doc.removeEventListener('touchmove', fn); } }; }(), /** * 本地存储 */ localStorage: function () { return storage(window.localStorage); }(), /** * Session存储 */ sessionStorage: function () { return storage(window.sessionStorage); }(), /** * 序列化 * @param value * @returns {string} */ serialize: function (value) { if (typeof value === 'string') return value; return JSON.stringify(value); }, /** * 反序列化 * @param value * @returns {*} */ deserialize: function (value) { if (typeof value !== 'string') return undefined; try { return JSON.parse(value); } catch (e) { return value || undefined; } } }; /** * HTML5存储 */ function storage (ls) { return { set: function (key, value) { ls.setItem(key, util.serialize(value)); }, get: function (key) { return util.deserialize(ls.getItem(key)); }, remove: function (key) { ls.removeItem(key); }, clear: function () { ls.clear(); } }; } /** * 判断css3动画是否执行完毕 * @git http://blog.alexmaccaw.com/css-transitions * @param duration */ $.fn.emulateTransitionEnd = function (duration) { var called = false, $el = this; $(this).one('webkitTransitionEnd', function () { called = true; }); var callback = function () { if (!called) $($el).trigger('webkitTransitionEnd'); }; setTimeout(callback, duration); }; if (typeof define === 'function') { define(ydui); } else { window.YDUI = ydui; } }(window); /** * ActionSheet Plugin */ !function (window) { "use strict"; var doc = window.document, $doc = $(doc), $body = $(doc.body), $mask = $('
'); function ActionSheet (element, closeElement) { this.$element = $(element); this.closeElement = closeElement; this.toggleClass = 'actionsheet-toggle'; } ActionSheet.prototype.open = function () { YDUI.device.isIOS && $('.g-scrollview').addClass('g-fix-ios-overflow-scrolling-bug'); var _this = this; $body.append($mask); // 点击遮罩层关闭窗口 $mask.on('click.ydui.actionsheet.mask', function () { _this.close(); }); // 第三方关闭窗口操作 if (_this.closeElement) { $doc.on('click.ydui.actionsheet', _this.closeElement, function () { _this.close(); }); } _this.$element.addClass(_this.toggleClass).trigger('open.ydui.actionsheet'); }; ActionSheet.prototype.close = function () { var _this = this; YDUI.device.isIOS && $('.g-scrollview').removeClass('g-fix-ios-overflow-scrolling-bug'); $mask.off('click.ydui.actionsheet.mask').remove(); _this.$element.removeClass(_this.toggleClass).trigger('close.ydui.actionsheet'); //$doc.off('click.ydui.actionsheet', _this.closeElement); }; function Plugin (option) { var args = Array.prototype.slice.call(arguments, 1); return this.each(function () { var $this = $(this), actionsheet = $this.data('ydui.actionsheet'); if (!actionsheet) { $this.data('ydui.actionsheet', (actionsheet = new ActionSheet(this, option.closeElement))); if (!option || typeof option == 'object') { actionsheet.open(); } } if (typeof option == 'string') { actionsheet[option] && actionsheet[option].apply(actionsheet, args); } }); } $doc.on('click.ydui.actionsheet.data-api', '[data-ydui-actionsheet]', function (e) { e.preventDefault(); var options = window.YDUI.util.parseOptions($(this).data('ydui-actionsheet')), $target = $(options.target), option = $target.data('ydui.actionsheet') ? 'open' : options; Plugin.call($target, option); }); $.fn.actionSheet = Plugin; }(window); /** * 解决:active这个高端洋气的CSS伪类不能使用问题 */ !function (window) { window.document.addEventListener('touchstart', function (event) { /* Do Nothing */ }, false); }(window); /** * CitySelect Plugin */ !function (window) { "use strict"; var $body = $(window.document.body); function CitySelect (element, options) { this.$element = $(element); this.options = $.extend({}, CitySelect.DEFAULTS, options || {}); this.init(); } CitySelect.DEFAULTS = { provance: '', city: '', area: '' }; CitySelect.prototype.init = function () { var _this = this, options = _this.options; if (typeof YDUI_CITYS == 'undefined') { console.error('请在ydui.js前引入ydui.citys.js。下载地址:http://cityselect.ydui.org'); return; } _this.citys = YDUI_CITYS; _this.createDOM(); _this.defaultSet = { provance: options.provance, city: options.city, area: options.area }; }; CitySelect.prototype.open = function () { var _this = this; $body.append(_this.$mask); // 防止火狐浏览器文本框丑丑的一坨小水滴 YDUI.device.isMozilla && _this.$element.blur(); _this.$mask.on('click.ydui.cityselect.mask', function () { _this.close(); }); var $cityElement = _this.$cityElement, defaultSet = _this.defaultSet; $cityElement.find('.cityselect-content').removeClass('cityselect-move-animate cityselect-next cityselect-prev'); _this.loadProvance(); if (defaultSet.provance) { _this.setNavTxt(0, defaultSet.provance); } else { $cityElement.find('.cityselect-nav a').eq(0).addClass('crt').html('请选择'); } if (defaultSet.city) { _this.loadCity(); _this.setNavTxt(1, defaultSet.city) } if (defaultSet.area) { _this.loadArea(); _this.ForwardView(false); _this.setNavTxt(2, defaultSet.area); } $cityElement.addClass('brouce-in'); }; CitySelect.prototype.close = function () { var _this = this; _this.$mask.remove(); _this.$cityElement.removeClass('brouce-in').find('.cityselect-nav a').removeClass('crt').html(''); _this.$itemBox.html(''); }; CitySelect.prototype.createDOM = function () { var _this = this; _this.$mask = $(''); _this.$cityElement = $('' + '