/*!
 @Name:layer mobile v2.0.0 弹层组件移动版
 @Author:贤心
 @Site:http://layer.layui.com/mobie/
 @License:MIT
    
 */
layui.define(function(exports){
  
  "use strict";
  var win = window, doc = document, query = 'querySelectorAll', claname = 'getElementsByClassName', S = function(s){
    return doc[query](s);
  };
  //默认配置
  var config = {
    type: 0
    ,shade: true
    ,shadeClose: true
    ,fixed: true
    ,anim: 'scale' //默认动画类型
  };
  var ready = {
    extend: function(obj){
      var newobj = JSON.parse(JSON.stringify(config));
      for(var i in obj){
        newobj[i] = obj[i];
      }
      return newobj;
    }, 
    timer: {}, end: {}
  };
  //点触事件
  ready.touch = function(elem, fn){
    elem.addEventListener('click', function(e){
      fn.call(this, e);
    }, false);
  };
  var index = 0, classs = ['layui-m-layer'], Layer = function(options){
    var that = this;
    that.config = ready.extend(options);
    that.view();
  };
  Layer.prototype.view = function(){
    var that = this, config = that.config, layerbox = doc.createElement('div');
    that.id = layerbox.id = classs[0] + index;
    layerbox.setAttribute('class', classs[0] + ' ' + classs[0]+(config.type || 0));
    layerbox.setAttribute('index', index);
    
    //标题区域
    var title = (function(){
      var titype = typeof config.title === 'object';
      return config.title
      ? '
'+ (titype ? config.title[0] : config.title)  +'
'
      : '';
    }());
    
    //按钮区域
    var button = (function(){
      typeof config.btn === 'string' && (config.btn = [config.btn]);
      var btns = (config.btn || []).length, btndom;
      if(btns === 0 || !config.btn){
        return '';
      }
      btndom = ''+ config.btn[0] +''
      if(btns === 2){
        btndom = ''+ config.btn[1] +'' + btndom;
      }
      return ''+ btndom + '
';
    }());
    
    if(!config.fixed){
      config.top = config.hasOwnProperty('top') ?  config.top : 100;
      config.style = config.style || '';
      config.style += ' top:'+ ( doc.body.scrollTop + config.top) + 'px';
    }
    
    if(config.type === 2){
      config.content = ''+ (config.content||'') +'
';
    }
    
    if(config.skin) config.anim = 'up';
    if(config.skin === 'msg') config.shade = false;
    
    layerbox.innerHTML = (config.shade ? '' : '')
    +''
      +'
'
        +'
'
          + title
          +'
'+ config.content +'
'
          + button
        +'
'
      +'
'
    +'