layer.js 3.6 KB

1234567
  1. !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;}
  2. 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){}}
  3. 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';}
  4. 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();});}
  5. _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();}}
  6. if(typeof option=='string'){actionsheet[option]&&actionsheet[option].apply(actionsheet,args);}});}
  7. $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){},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);$(function(){$('#ClickMe').click(function(){$('#code').center();$('#goodcover').show();$('#code').fadeIn();});$('#closebt').click(function(){$('#code').hide();$('#goodcover').hide();});$('#goodcover').click(function(){$('#code').hide();$('#goodcover').hide();});jQuery.fn.center=function(loaded){var obj=this;body_width=parseInt($(window).width());body_height=parseInt($(window).height());block_width=parseInt(obj.width());block_height=parseInt(obj.height());left_position=parseInt((body_width/2.6)-(block_width/2.6)+$(window).scrollLeft());if(body_width<block_width){left_position=0+$(window).scrollLeft();};top_position=parseInt((body_height/2)-(block_height/2)+$(window).scrollTop());if(body_height<block_height){top_position=0+$(window).scrollTop();};if(!loaded){obj.css({'position':'absolute'});obj.css({'top':($(window).height()-$('#code').height())*0.5,'left':left_position});$(window).bind('resize',function(){obj.center(!loaded);});$(window).bind('scroll',function(){obj.center(!loaded);});}else{obj.stop();obj.css({'position':'absolute'});obj.animate({'top':top_position},20,'linear');}}})