Friends

类调用支持fn调用方式

$.fn.huiCalendar = function(options){
  var args = Array.prototype.slice.call(arguments, 1); 
  var res = this; 

  this.each(function(i, _element) { 
    var element = $(_element);
    var calendar = element.data('huiCalendar');
    var singleRes; 

    if (typeof options === 'string') {
      if (calendar && $.isFunction(calendar[options])) {
        singleRes = calendar[options].apply(calendar, args);
        if (!i) {
          res = singleRes; 
        }
        if (options === 'destroy') { 
          element.removeData('huiCalendar');
        }
      }
    }

    else if (!calendar) {
      calendar = new HuiCalendar(element, options);
      element.data('huiCalendar', calendar);
    }
  });

  return res;
};
Written on September 2, 2015