123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- !function(window) {
- "use strict";
- var doc = window.document
- , ydui = {};
- $(window).on('load', function() {
- typeof FastClick == 'function' && FastClick.attach(doc.body);
- });
- var util = ydui.util = {
- 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;
- },
- };
- if (typeof define === 'function') {
- define(ydui);
- } else {
- window.YDUI = ydui;
- }
- }(window);
- !function(window) {
- "use strict";
- var doc = window.document
- , $doc = $(doc)
- , $body = $(doc.body)
- , $mask = $('<div class="mask-black"></div>');
- 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');
- }
- ;
- 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);
- !function(window) {
- window.document.addEventListener('touchstart', function(event) {/* Do Nothing */
- }, false);
- }(window);
- !function(window) {
- var doc = window.document
- , ydui = window.YDUI
- , ua = window.navigator && window.navigator.userAgent || '';
- var ipad = !!ua.match(/(iPad).*OS\s([\d_]+)/)
- , ipod = !!ua.match(/(iPod)(.*OS\s([\d_]+))?/)
- , iphone = !ipad && !!ua.match(/(iPhone\sOS)\s([\d_]+)/);
- ydui.device = {};
- }(window);
|