$(function (){
  // 获取元素属性
  function getStyle(el, name) {
    if (el.currentStyle) {
      return el.currentStyle[name];
    } else {
      return getComputedStyle(el, null)[name];
    }
  }
  window.getEleData = function() {
    var Data = {}   // 交互的数据
    // 通过手机内的元素 构建数据
    for (var i = 0, aTmpEdit = document.querySelectorAll('.tmp-editable'); i < aTmpEdit.length; i++) {
      var region = aTmpEdit[i].getAttribute('data-region');
      Data[region] || (Data[region] = []);

      var obj = {
        query: aTmpEdit[i].getAttribute('data-query'),
        editType: aTmpEdit[i].getAttribute('data-edit-type'),
        content: aTmpEdit[i].getAttribute('data-edit-content'),
        size: aTmpEdit[i].getAttribute('data-size')
      };

      aTmpEdit[i].getAttribute('data-index') && (obj.index = aTmpEdit[i].getAttribute('data-index'))

      var types = aTmpEdit[i].getAttribute('data-edit-type');
      switch (types) {
        case 'img':
          obj[types] = aTmpEdit[i].src;
          break;
        case 'bgImg':
          var str = getStyle(aTmpEdit[i], 'backgroundImage')
          str = str.replace('url("', '')
          str = str.replace('")', '')
          obj[types] = str.replace('"', '');
          break;
        case 'bgC':
          obj[types] = getStyle(aTmpEdit[i], 'backgroundImage');
          break;
        case 'bdC':
          obj[types] = getStyle(aTmpEdit[i], 'borderColor');
          break;
        case 'text':
          obj[types] = aTmpEdit[i].innerHTML;
          break;
        case 'color':
          obj[types] = getStyle(aTmpEdit[i], 'color');
          break;
      }
      Data[region].push(obj);
    }
    delete Data.null
    return {
      data: Data,
      version: '1.0'
    }
  }
  window.getEleDataToSend = function () {
    var Data = {}   // 交互的数据
    // 通过手机内的元素 构建数据
    for (var i = 0, aTmpEdit = document.querySelectorAll('.tmp-editable'); i < aTmpEdit.length; i++) {
      var region = aTmpEdit[i].getAttribute('data-region');
      Data[region] || (Data[region] = []);

      var obj = {
        query: aTmpEdit[i].getAttribute('data-query'),
        editType: aTmpEdit[i].getAttribute('data-edit-type'),
      };

      aTmpEdit[i].getAttribute('data-index') && (obj.index = aTmpEdit[i].getAttribute('data-index'))

      var types = aTmpEdit[i].getAttribute('data-edit-type');
      switch (types) {
        case 'img':
          obj[types] = aTmpEdit[i].src;
          break;
        case 'bgImg':
          var str = getStyle(aTmpEdit[i], 'backgroundImage')
          str = str.replace('url("', '')
          str = str.replace('")', '')
          obj[types] = str.replace('"', '');
          break;
        case 'bgC':
          obj[types] = getStyle(aTmpEdit[i], 'backgroundImage');
          break;
        case 'bdC':
          obj[types] = getStyle(aTmpEdit[i], 'borderColor');
          break;
        case 'text':
          obj[types] = aTmpEdit[i].innerHTML;
          break;
        case 'color':
          obj[types] = getStyle(aTmpEdit[i], 'color');
          break;
      }
      Data[region].push(obj);
    }
    delete Data.null
    return {
      data: Data,
      version: '1.0'
    }
  }
})