tips.js 1018 Bytes
/**
 * Created by TaoHuang on 2016/7/1.
 */

var $ = require('yoho-jquery'),
    Handlebars = require('yoho-handlebars');

(function ($) {

    var tpl = '<div class="tips">' +
        '<div class="triangle"></div>' +
        '<div class="rectangle"> {{content}}</div>' +
        '</div>';

    var tplFn = Handlebars.compile(tpl);

    var isInit = false;

    var methods = {
        show: function () {
            if (isInit) {
                this.find('.rectangle').text(arguments[0]);
            } else {
                _isInit = true;
                this.append(tplFn({content:arguments[0]}));
            }
        },
        hide: function () {
            this.find('.tips').remove();
        }
    };

    $.fn.tips = function (method) {

        // 方法调用
        if (methods[method]) {
            return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
        } else {
            $.error('Method' + method + 'does not exist on jQuery.tooltip');
        }

    };

})($);