You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

79 lines
1.5 KiB

  1. define([
  2. 'ui/uiBase',
  3. 'js/events'
  4. ], function (
  5. uiBase,
  6. events
  7. ) {
  8. return {
  9. uis: [],
  10. root: '',
  11. init: function (root) {
  12. if (root)
  13. this.root = root + '/';
  14. events.on('onKeyDown', this.events.onKeyDown.bind(this));
  15. },
  16. build: function (type, options) {
  17. let className = 'ui' + type[0].toUpperCase() + type.substr(1);
  18. let el = $('.' + className);
  19. if (el.length > 0)
  20. return;
  21. this.getTemplate(type, options);
  22. $(window).on('resize', this.onResize.bind(this));
  23. },
  24. getTemplate: function (type, options) {
  25. require([this.root + 'ui/templates/' + type + '/' + type], this.onGetTemplate.bind(this, options));
  26. },
  27. onGetTemplate: function (options, template) {
  28. let ui = $.extend(true, {}, uiBase, template);
  29. ui.setOptions(options);
  30. ui.render();
  31. ui.el.data('ui', ui);
  32. this.uis.push(ui);
  33. if ((options) && (options.onDone))
  34. options.onDone(ui);
  35. },
  36. onResize: function () {
  37. this.uis.forEach(function (ui) {
  38. if (ui.centered)
  39. ui.center();
  40. else if ((ui.centeredX) || (ui.centeredY))
  41. ui.center(ui.centeredX, ui.centeredY);
  42. }, this);
  43. },
  44. update: function () {
  45. let uis = this.uis;
  46. let uLen = uis.length;
  47. for (let i = 0; i < uLen; i++) {
  48. let u = uis[i];
  49. if (u.update)
  50. u.update();
  51. }
  52. },
  53. events: {
  54. onKeyDown: function (key) {
  55. if (key == 'esc') {
  56. this.uis.forEach(function (u) {
  57. if (!u.modal)
  58. return;
  59. u.destroy();
  60. });
  61. $('.uiOverlay').hide();
  62. }
  63. }
  64. }
  65. };
  66. });