main.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. (function ($, Drupal, Backbone) {
  2. "use strict";
  3. /**
  4. * Define namespaces.
  5. */
  6. Drupal.webprofiler = {
  7. views: {},
  8. models: {},
  9. collectors: {},
  10. routers: {}
  11. };
  12. Drupal.behaviors.webprofiler = {
  13. attach: function (context) {
  14. var el,
  15. elz,
  16. key,
  17. sel,
  18. value,
  19. select,
  20. selector,
  21. unselected,
  22. filter = [],
  23. livefilter = function (e) {
  24. el = $(e).attr('id').replace('edit-', '');
  25. value = $(e).val();
  26. filter[el] = value.replace('/', '\/');
  27. selector = [];
  28. unselected = [];
  29. for (key in filter) {
  30. if (filter[key].length > 0 && filter[key] != ' ') {
  31. select = filter[key].split(' ').filter(Boolean);
  32. for (sel in select) {
  33. selector.push('[data-wp-' + key + ' *= ' + select[sel].toLowerCase() + ']');
  34. unselected.push('[data-wp-' + key + ']:not([data-wp-' + key + ' *= ' + select[sel].toLowerCase() + '])');
  35. }
  36. }
  37. else {
  38. selector.push('[data-wp-' + key + ']');
  39. }
  40. }
  41. for (elz in unselected) {
  42. $(unselected[elz]).addClass('is--hidden');
  43. }
  44. $(selector.join('')).removeClass('is--hidden');
  45. },
  46. modalFill = function(t,c){
  47. $('.modal__title').html(t);
  48. $('.modal__main-data').html(c);
  49. },
  50. clipboard = function (e, t) {
  51. var clip = e.parent().find(t).get(0),
  52. title = 'Original Code',
  53. content = '<textarea readonly >' +
  54. clip.textContent +
  55. '</textarea>';
  56. modalFill(title,content);
  57. $('.modal').show();
  58. };
  59. $(context).find('#collectors').once('webprofiler').each(function () {
  60. new Drupal.webprofiler.routers.CollectorsRouter({el: $('#collectors')});
  61. Backbone.history.start({
  62. pushState: false
  63. });
  64. });
  65. $(context).find('.js--modal-close').each(function () {
  66. $(this).on('click', function () {
  67. $('.js--modal').hide();
  68. });
  69. });
  70. $(context).find('.js--live-filter').each(function () {
  71. $(this).on('keyup', function () {
  72. livefilter($(this));
  73. });
  74. $(this).on('change', function () {
  75. livefilter($(this));
  76. });
  77. });
  78. $(context).find('.js--panel-toggle').once('js--panel-toggle').each(function () {
  79. $(this).on('click', function () {
  80. $(this).parent().parent().toggleClass('is--open');
  81. });
  82. });
  83. $(context).find('.js--clipboard-trigger').once('js--clipboard-trigger').each(function () {
  84. $(this).on('click', function () {
  85. clipboard($(this), '.js--clipboard-target')
  86. }
  87. );
  88. });
  89. }
  90. };
  91. }(jQuery, Drupal, Backbone));