layer.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. !function(window) {
  2. "use strict";
  3. var doc = window.document
  4. , ydui = {};
  5. $(window).on('load', function() {
  6. typeof FastClick == 'function' && FastClick.attach(doc.body);
  7. });
  8. var util = ydui.util = {
  9. parseOptions: function(string) {
  10. if ($.isPlainObject(string)) {
  11. return string;
  12. }
  13. var start = (string ? string.indexOf('{') : -1)
  14. , options = {};
  15. if (start != -1) {
  16. try {
  17. options = (new Function('','var json = ' + string.substr(start) + '; return JSON.parse(JSON.stringify(json));'))();
  18. } catch (e) {}
  19. }
  20. return options;
  21. },
  22. };
  23. if (typeof define === 'function') {
  24. define(ydui);
  25. } else {
  26. window.YDUI = ydui;
  27. }
  28. }(window);
  29. !function(window) {
  30. "use strict";
  31. var doc = window.document
  32. , $doc = $(doc)
  33. , $body = $(doc.body)
  34. , $mask = $('<div class="mask-black"></div>');
  35. function ActionSheet(element, closeElement) {
  36. this.$element = $(element);
  37. this.closeElement = closeElement;
  38. this.toggleClass = 'actionsheet-toggle';
  39. }
  40. ActionSheet.prototype.open = function() {
  41. YDUI.device.isIOS && $('.g-scrollview').addClass('g-fix-ios-overflow-scrolling-bug');
  42. var _this = this;
  43. $body.append($mask);
  44. $mask.on('click.ydui.actionsheet.mask', function() {
  45. _this.close();
  46. });
  47. if (_this.closeElement) {
  48. $doc.on('click.ydui.actionsheet', _this.closeElement, function() {
  49. _this.close();
  50. });
  51. }
  52. _this.$element.addClass(_this.toggleClass).trigger('open.ydui.actionsheet');
  53. }
  54. ;
  55. ActionSheet.prototype.close = function() {
  56. var _this = this;
  57. YDUI.device.isIOS && $('.g-scrollview').removeClass('g-fix-ios-overflow-scrolling-bug');
  58. $mask.off('click.ydui.actionsheet.mask').remove();
  59. _this.$element.removeClass(_this.toggleClass).trigger('close.ydui.actionsheet');
  60. }
  61. ;
  62. function Plugin(option) {
  63. var args = Array.prototype.slice.call(arguments, 1);
  64. return this.each(function() {
  65. var $this = $(this)
  66. , actionsheet = $this.data('ydui.actionsheet');
  67. if (!actionsheet) {
  68. $this.data('ydui.actionsheet', (actionsheet = new ActionSheet(this,option.closeElement)));
  69. if (!option || typeof option == 'object') {
  70. actionsheet.open();
  71. }
  72. }
  73. if (typeof option == 'string') {
  74. actionsheet[option] && actionsheet[option].apply(actionsheet, args);
  75. }
  76. });
  77. }
  78. $doc.on('click.ydui.actionsheet.data-api', '[data-ydui-actionsheet]', function(e) {
  79. e.preventDefault();
  80. var options = window.YDUI.util.parseOptions($(this).data('ydui-actionsheet'))
  81. , $target = $(options.target)
  82. , option = $target.data('ydui.actionsheet') ? 'open' : options;
  83. Plugin.call($target, option);
  84. });
  85. $.fn.actionSheet = Plugin;
  86. }(window);
  87. !function(window) {
  88. window.document.addEventListener('touchstart', function(event) {/* Do Nothing */
  89. }, false);
  90. }(window);
  91. !function(window) {
  92. var doc = window.document
  93. , ydui = window.YDUI
  94. , ua = window.navigator && window.navigator.userAgent || '';
  95. var ipad = !!ua.match(/(iPad).*OS\s([\d_]+)/)
  96. , ipod = !!ua.match(/(iPod)(.*OS\s([\d_]+))?/)
  97. , iphone = !ipad && !!ua.match(/(iPhone\sOS)\s([\d_]+)/);
  98. ydui.device = {};
  99. }(window);