select2.amd.full.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. define('select2/utils',[], function () {
  2. var Utils = {};
  3. Utils.Extend = function (ChildClass, SuperClass) {
  4. var __hasProp = {}.hasOwnProperty
  5. function BaseConstructor () {
  6. this.constructor = ChildClass;
  7. }
  8. for (var key in SuperClass) {
  9. if (__hasProp.call(SuperClass, key)) {
  10. ChildClass[key] = SuperClass[key];
  11. }
  12. }
  13. BaseConstructor.prototype = SuperClass.prototype;
  14. ChildClass.prototype = new BaseConstructor();
  15. ChildClass.__super__ = SuperClass.prototype;
  16. return ChildClass;
  17. };
  18. var Observable = function () {
  19. this.listeners = {};
  20. };
  21. Observable.prototype.on = function (event, callback) {
  22. if (event in this.listeners) {
  23. this.listeners[event].push(callback);
  24. } else {
  25. this.listeners[event] = [callback];
  26. }
  27. };
  28. Observable.prototype.trigger = function (event) {
  29. if (event in this.listeners) {
  30. this.invoke(this.listeners[event], util.shift(arguments));
  31. }
  32. if ("*" in this.listeners) {
  33. this.invoke(this.listeners["*"], arguments);
  34. }
  35. };
  36. Observable.prototype.invoke = function (listeners, params) {
  37. for (var i = 0, len = listeners.length; i < len; i++) {
  38. listeners[i].apply(this, params);
  39. }
  40. };
  41. Utils.Observable = Observable;
  42. return Utils;
  43. });
  44. define('select2/adapters/select',[
  45. "../utils"
  46. ], function (Utils) {
  47. function SelectAdapter (element, options) {
  48. this.element = element;
  49. }
  50. Utils.Extend(SelectAdapter, Utils.Observable);
  51. return SelectAdapter;
  52. });
  53. define('select2/options',[
  54. "./adapters/select"
  55. ], function (SelectAdapter) {
  56. function Options (options) {
  57. this.options = options;
  58. this.DataAdapter = SelectAdapter;
  59. }
  60. return Options;
  61. })
  62. ;
  63. define('select2/core',[
  64. "jquery",
  65. "./options",
  66. "./utils"
  67. ], function ($, Options, Utils) {
  68. var Select2 = function (element, options) {
  69. this.element = element;
  70. this.options = new Options(options);
  71. this.adapter = new this.options.DataAdapter(element, options);
  72. };
  73. Utils.Extend(Select2, Utils.Observable);
  74. return Select2;
  75. });