Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

128 Zeilen
4.1 KiB

  1. /**
  2. * Copyright © Magento, Inc. All rights reserved.
  3. * See COPYING.txt for license details.
  4. */
  5. /* eslint-disable strict */
  6. define([
  7. 'jquery',
  8. 'mage/translate'
  9. ], function ($) {
  10. var methods = {
  11. /**
  12. * Decorate a list (e.g. a <ul> containing <li>) recursively if specified.
  13. * @param {Boolean} isRecursive
  14. */
  15. list: function (isRecursive) {
  16. return this.each(function () {
  17. var list = $(this),
  18. items;
  19. if (list.length > 0) {
  20. items = typeof isRecursive === 'undefined' || isRecursive ?
  21. list.find('li') :
  22. list.children();
  23. items.decorate('generic', ['odd', 'even', 'last']);
  24. }
  25. });
  26. },
  27. /**
  28. * Annotate a set of DOM elements with decorator classes.
  29. * @param {Array} decoratorParams
  30. */
  31. generic: function (decoratorParams) {
  32. var elements = $(this),
  33. allSupportedParams;
  34. if (elements) {
  35. allSupportedParams = {
  36. even: 'odd', // Flip jQuery odd/even so that index 0 is odd.
  37. odd: 'even',
  38. last: 'last',
  39. first: 'first'
  40. };
  41. decoratorParams = decoratorParams || allSupportedParams;
  42. $.each(decoratorParams, function (index, param) {
  43. if (param === 'even' || param === 'odd') {
  44. elements.filter(':' + param).removeClass('odd even').addClass(allSupportedParams[param]);
  45. } else {
  46. elements.filter(':' + param).addClass(allSupportedParams[param]);
  47. }
  48. });
  49. }
  50. return this;
  51. },
  52. /**
  53. * Decorate DOM elements in an HTML table with specified classes.
  54. * @param {Object} instanceOptions
  55. */
  56. table: function (instanceOptions) {
  57. return this.each(function () {
  58. var table = $(this),
  59. options;
  60. if (table.length > 0) {
  61. options = {
  62. 'tbody': false,
  63. 'tbody tr': ['odd', 'even', 'first', 'last'],
  64. 'thead tr': ['first', 'last'],
  65. 'tfoot tr': ['first', 'last'],
  66. 'tr td': ['last']
  67. };
  68. $.extend(options, instanceOptions || {});
  69. $.each(options, function (key, value) {
  70. if (options[key]) {
  71. if (key === 'tr td') {
  72. $.each(table.find('tr'), function () {
  73. $(this).find('td').decorate('generic', options['tr td']);
  74. });
  75. } else {
  76. table.find(key).decorate('generic', value);
  77. }
  78. }
  79. });
  80. }
  81. });
  82. },
  83. /**
  84. * Annotate data list elements with CSS classes.
  85. */
  86. dataList: function () {
  87. return this.each(function () {
  88. var list = $(this);
  89. if (list) {
  90. list.find('dt').decorate('generic', ['odd', 'even', 'last']);
  91. list.find('dd').decorate('generic', ['odd', 'even', 'last']);
  92. }
  93. });
  94. }
  95. };
  96. /**
  97. * @param {String} method
  98. * @return {*}
  99. */
  100. $.fn.decorate = function (method) {
  101. var message;
  102. if (methods[method]) {
  103. return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
  104. } else if (typeof method === 'object' || !method) {
  105. return methods.init.apply(this, arguments);
  106. }
  107. message = $.mage.__('Method %s does not exist on jQuery.decorate');
  108. // eslint-disable-next-line jquery-no-event-shorthand
  109. $.error(message.replace('%s', method));
  110. };
  111. });