pikaday.jquery.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*!
  2. * Pikaday jQuery plugin.
  3. *
  4. * Copyright © 2013 David Bushell | BSD & MIT license | https://github.com/dbushell/Pikaday
  5. */
  6. (function (root, factory)
  7. {
  8. 'use strict';
  9. if (typeof exports === 'object') {
  10. // CommonJS module
  11. factory(require('jquery'), require('../pikaday'));
  12. } else if (typeof define === 'function' && define.amd) {
  13. // AMD. Register as an anonymous module.
  14. define(['jquery', 'pikaday'], factory);
  15. } else {
  16. // Browser globals
  17. factory(root.jQuery, root.Pikaday);
  18. }
  19. }(this, function ($, Pikaday)
  20. {
  21. 'use strict';
  22. $.fn.pikaday = function()
  23. {
  24. var args = arguments;
  25. if (!args || !args.length) {
  26. args = [{ }];
  27. }
  28. return this.each(function()
  29. {
  30. var self = $(this),
  31. plugin = self.data('pikaday');
  32. if (!(plugin instanceof Pikaday)) {
  33. if (typeof args[0] === 'object') {
  34. var options = $.extend({}, args[0]);
  35. options.field = self[0];
  36. self.data('pikaday', new Pikaday(options));
  37. }
  38. } else {
  39. if (typeof args[0] === 'string' && typeof plugin[args[0]] === 'function') {
  40. plugin[args[0]].apply(plugin, Array.prototype.slice.call(args,1));
  41. if (args[0] === 'destroy') {
  42. self.removeData('pikaday');
  43. }
  44. }
  45. }
  46. });
  47. };
  48. }));