/**
 * 弹框提示
 * @author: xuqi<qi.xu@yoho.cn>
 * @date: 2015/10/10
 */
let $ = require('yoho-jquery');

let $tip, tipItime;

/**
 * 初始化提示框
 */
(function() {
  let tipHtml = '<div id="yoho-tip" class="yoho-tip"></div>';

  // 插入提示HTML
  $('body').append(tipHtml);

  $tip = $('#yoho-tip');
  $tip.on('touchend', function() {
    $tip.hide();

    // 清除Timeout
    clearTimeout(tipItime);
  });
}());

/**
 * 显示提示
 */
function show(con, dur) {
  let content, duration;

  if (typeof con === 'undefined') {
    return;
  }

  content = con.toString();
  duration = (dur && dur > 0) ? dur : 2000;

  $tip.html(content).show();

  tipItime = setTimeout(function() {
    if ($tip.css('display') === 'block') {
      $tip.hide();
    }
  }, duration);
}

exports.show = show;