Lutsman
11/26/2016 - 3:15 PM

export object to $.fn

export object to $.fn

  let jTour = null;

  $.fn.jTour = function () {
    let _ = this;
    let options = arguments[0] || {};
    let args = Array.prototype.slice.call(arguments, 1);

    if (!_.length) return;

    if (!jTour) {
      $.jTour = jTour = new JTourController({});
    }

    if (typeof options === 'object') {
      jTour.addElement(_, options);

      for (let i = 0; i < _.length; i++) {
        _[i].jTour = jTour;
      }
    } else {
      for (let i = 0; i < _.length; i++) {
        let result = _[i].jTour[options].call(_[i].jTour, args);

        if (typeof result !== 'undefined') return result;
      }

    }

    return _;
  };
  $.fn.myPlugin = function () {
    let _ = this;
    let options = arguments[0] || {};
    let args = Array.prototype.slice.call(arguments, 1);

    for (let i = 0; i < _.length; i++) {
      if (typeof options === 'object') {
        options.block = _[i];
        _[i].myPlugin = new Controller(options);
      } else {
        let result = _[i].myPlugin[options].call(_[i].myPlugin, args);

        if (typeof result !== 'undefined') return result;
      }
    }

    return _;
  };
$.fn.myObj = function () {
        var options = typeof arguments[0] === 'object' ? arguments[0] : {};
        
        $(this).each(function () {
            options.myOption = this;
            
            var controller = new myController(options);
            controller.init();
        });
    };
'use strict';

(function (factory) {
  if (typeof define === 'function' && define.amd) {
    // AMD (Register as an anonymous module)
    define(['jquery'], factory);
  } else if (typeof exports === 'object') {
    // Node/CommonJS
    module.exports = factory(require('jquery'));
  } else {
    // Browser globals
    factory(jQuery);
  }
}(function ($) {}));