Guest User

Untitled

a guest
Jul 19th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.17 KB | None | 0 0
  1. (function(factory) {
  2. if (typeof define === 'function' && define.amd) {
  3. // AMD. Register as an anonymous module.
  4. define(['jquery', 'moment', 'moment-timezone'], factory);
  5. } else if (typeof module === 'object' && module.exports) {
  6. // Node/CommonJS
  7. module.exports = function(root, jQuery, moment) {
  8. if (jQuery === undefined) {
  9. // require('jQuery') returns a factory that requires window to
  10. // build a jQuery instance, we normalize how we use modules
  11. // that require this pattern but the window provided is a noop
  12. // if it's defined (how jquery works)
  13. if (typeof window !== 'undefined') {
  14. jQuery = require('jquery');
  15. } else {
  16. jQuery = require('jquery')(root);
  17. }
  18. }
  19. if (moment === undefined) {
  20. if (typeof window !== 'undefined') {
  21. moment = require('moment');
  22. } else {
  23. moment = require('moment')(root);
  24. }
  25. }
  26. if (moment.tz === undefined) {
  27. if (typeof window !== 'undefined') {
  28. moment.tz = require('moment-timezone');
  29. } else {
  30. moment.tz = require('moment-timezone')(root);
  31. }
  32. }
  33. factory(jQuery, moment, window, document);
  34. return jQuery;
  35. };
  36. } else {
  37. // Browser globals
  38. factory(jQuery, moment, window, document);
  39. }
  40. }(function($, moment, window, document, undefined) {
  41.  
  42. "use strict";
  43.  
  44. // undefined is used here as the undefined global variable in ECMAScript 3 is
  45. // mutable (ie. it can be changed by someone else). undefined isn't really being
  46. // passed in so we can ensure the value of it is truly undefined. In ES5, undefined
  47. // can no longer be modified.
  48.  
  49. // window and document are passed through as local variables rather than global
  50. // as this (slightly) quickens the resolution process and can be more efficiently
  51. // minified (especially when both are regularly referenced in your plugin).
  52.  
  53. // Create the defaults once
  54. var pluginName = "pluginName",
  55. defaults = {
  56. propertyName: "value"
  57. };
  58.  
  59. // The actual plugin constructor
  60. function Plugin(element, options) {
  61. this.element = element;
  62.  
  63. // jQuery has an extend method which merges the contents of two or
  64. // more objects, storing the result in the first object. The first object
  65. // is generally empty as we don't want to alter the default options for
  66. // future instances of the plugin
  67. this.settings = $.extend({}, defaults, options);
  68. this._defaults = defaults;
  69. this._name = pluginName;
  70. this.init();
  71. }
  72.  
  73. // Avoid Plugin.prototype conflicts
  74. $.extend(Plugin.prototype, {
  75. init: function() {
  76.  
  77. console.log("moment test ---");
  78. console.log("moment.locale(): ", moment.locale());
  79. console.log("moment().format('L'): ", moment().format('L'));
  80. console.log("moment().format('LTS'): ", moment().format('LTS'));
  81. console.log("moment.tz test ---");
  82. console.log("moment.tz.guess();: ", moment.tz.guess());
  83.  
  84. // Place initialization logic here
  85. // You already have access to the DOM element and
  86. // the options via the instance, e.g. this.element
  87. // and this.settings
  88. // you can add more functions like the one below and
  89. // call them like the example below
  90. // this.yourOtherFunction("jQuery Boilerplate");
  91. },
  92. yourOtherFunction: function(text) {
  93.  
  94. // some logic
  95. $(this.element).text(text);
  96. }
  97. });
  98.  
  99. // A really lightweight plugin wrapper around the constructor,
  100. // preventing against multiple instantiations
  101. $.fn[pluginName] = function(options) {
  102. return this.each(function() {
  103. if (!$.data(this, "plugin_" + pluginName)) {
  104. $.data(this, "plugin_" +
  105. pluginName, new Plugin(this, options));
  106. }
  107. });
  108. };
  109. }));
Add Comment
Please, Sign In to add comment