annotate core/modules/views_ui/js/views-admin.js @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents af1871eacc83
children
rev   line source
Chris@0 1 /**
Chris@0 2 * DO NOT EDIT THIS FILE.
Chris@0 3 * See the following change record for more information,
Chris@0 4 * https://www.drupal.org/node/2815083
Chris@0 5 * @preserve
Chris@0 6 **/
Chris@0 7
Chris@0 8 (function ($, Drupal, drupalSettings) {
Chris@0 9 Drupal.viewsUi = {};
Chris@0 10
Chris@0 11 Drupal.behaviors.viewsUiEditView = {
Chris@0 12 attach: function attach() {
Chris@0 13 $('[data-drupal-selector="edit-query-options-disable-sql-rewrite"]').on('click', function () {
Chris@0 14 $('.sql-rewrite-warning').toggleClass('js-hide');
Chris@0 15 });
Chris@0 16 }
Chris@0 17 };
Chris@0 18
Chris@0 19 Drupal.behaviors.viewsUiAddView = {
Chris@0 20 attach: function attach(context) {
Chris@0 21 var $context = $(context);
Chris@0 22
Chris@0 23 var exclude = new RegExp('[^a-z0-9\\-]+', 'g');
Chris@0 24 var replace = '-';
Chris@0 25 var suffix = void 0;
Chris@0 26
Chris@0 27 var $fields = $context.find('[id^="edit-page-title"], [id^="edit-block-title"], [id^="edit-page-link-properties-title"]');
Chris@0 28 if ($fields.length) {
Chris@0 29 if (!this.fieldsFiller) {
Chris@0 30 this.fieldsFiller = new Drupal.viewsUi.FormFieldFiller($fields);
Chris@0 31 } else {
Chris@0 32 this.fieldsFiller.rebind($fields);
Chris@0 33 }
Chris@0 34 }
Chris@0 35
Chris@0 36 var $pathField = $context.find('[id^="edit-page-path"]');
Chris@0 37 if ($pathField.length) {
Chris@0 38 if (!this.pathFiller) {
Chris@0 39 this.pathFiller = new Drupal.viewsUi.FormFieldFiller($pathField, exclude, replace);
Chris@0 40 } else {
Chris@0 41 this.pathFiller.rebind($pathField);
Chris@0 42 }
Chris@0 43 }
Chris@0 44
Chris@0 45 var $feedField = $context.find('[id^="edit-page-feed-properties-path"]');
Chris@0 46 if ($feedField.length) {
Chris@0 47 if (!this.feedFiller) {
Chris@0 48 suffix = '.xml';
Chris@0 49 this.feedFiller = new Drupal.viewsUi.FormFieldFiller($feedField, exclude, replace, suffix);
Chris@0 50 } else {
Chris@0 51 this.feedFiller.rebind($feedField);
Chris@0 52 }
Chris@0 53 }
Chris@0 54 }
Chris@0 55 };
Chris@0 56
Chris@0 57 Drupal.viewsUi.FormFieldFiller = function ($target, exclude, replace, suffix) {
Chris@0 58 this.source = $('#edit-label');
Chris@0 59
Chris@0 60 this.target = $target;
Chris@0 61
Chris@0 62 this.exclude = exclude || false;
Chris@0 63
Chris@0 64 this.replace = replace || '';
Chris@0 65
Chris@0 66 this.suffix = suffix || '';
Chris@0 67
Chris@0 68 var self = this;
Chris@0 69
Chris@0 70 this.populate = function () {
Chris@0 71 return self._populate.call(self);
Chris@0 72 };
Chris@0 73
Chris@0 74 this.unbind = function () {
Chris@0 75 return self._unbind.call(self);
Chris@0 76 };
Chris@0 77
Chris@0 78 this.bind();
Chris@0 79 };
Chris@0 80
Chris@0 81 $.extend(Drupal.viewsUi.FormFieldFiller.prototype, {
Chris@0 82 bind: function bind() {
Chris@0 83 this.unbind();
Chris@0 84
Chris@0 85 this.source.on('keyup.viewsUi change.viewsUi', this.populate);
Chris@0 86
Chris@0 87 this.target.on('focus.viewsUi', this.unbind);
Chris@0 88 },
Chris@0 89 getTransliterated: function getTransliterated() {
Chris@0 90 var from = this.source.val();
Chris@0 91 if (this.exclude) {
Chris@0 92 from = from.toLowerCase().replace(this.exclude, this.replace);
Chris@0 93 }
Chris@0 94 return from;
Chris@0 95 },
Chris@0 96 _populate: function _populate() {
Chris@0 97 var transliterated = this.getTransliterated();
Chris@0 98 var suffix = this.suffix;
Chris@0 99 this.target.each(function (i) {
Chris@0 100 var maxlength = $(this).attr('maxlength') - suffix.length;
Chris@0 101 $(this).val(transliterated.substr(0, maxlength) + suffix);
Chris@0 102 });
Chris@0 103 },
Chris@0 104 _unbind: function _unbind() {
Chris@0 105 this.source.off('keyup.viewsUi change.viewsUi', this.populate);
Chris@0 106 this.target.off('focus.viewsUi', this.unbind);
Chris@0 107 },
Chris@0 108 rebind: function rebind($fields) {
Chris@0 109 this.target = $fields;
Chris@0 110 this.bind();
Chris@0 111 }
Chris@0 112 });
Chris@0 113
Chris@0 114 Drupal.behaviors.addItemForm = {
Chris@0 115 attach: function attach(context) {
Chris@0 116 var $context = $(context);
Chris@0 117 var $form = $context;
Chris@0 118
Chris@0 119 if (!$context.is('form[id^="views-ui-add-handler-form"]')) {
Chris@0 120 $form = $context.find('form[id^="views-ui-add-handler-form"]');
Chris@0 121 }
Chris@0 122 if ($form.once('views-ui-add-handler-form').length) {
Chris@0 123 new Drupal.viewsUi.AddItemForm($form);
Chris@0 124 }
Chris@0 125 }
Chris@0 126 };
Chris@0 127
Chris@0 128 Drupal.viewsUi.AddItemForm = function ($form) {
Chris@0 129 this.$form = $form;
Chris@0 130 this.$form.find('.views-filterable-options :checkbox').on('click', $.proxy(this.handleCheck, this));
Chris@0 131
Chris@0 132 this.$selected_div = this.$form.find('.views-selected-options').parent();
Chris@0 133 this.$selected_div.hide();
Chris@0 134
Chris@0 135 this.checkedItems = [];
Chris@0 136 };
Chris@0 137
Chris@0 138 Drupal.viewsUi.AddItemForm.prototype.handleCheck = function (event) {
Chris@0 139 var $target = $(event.target);
Chris@0 140 var label = $.trim($target.closest('td').next().html());
Chris@0 141
Chris@0 142 if ($target.is(':checked')) {
Chris@0 143 this.$selected_div.show().css('display', 'block');
Chris@0 144 this.checkedItems.push(label);
Chris@0 145 } else {
Chris@0 146 var position = $.inArray(label, this.checkedItems);
Chris@0 147
Chris@0 148 for (var i = 0; i < this.checkedItems.length; i++) {
Chris@0 149 if (i === position) {
Chris@0 150 this.checkedItems.splice(i, 1);
Chris@0 151 i--;
Chris@0 152 break;
Chris@0 153 }
Chris@0 154 }
Chris@0 155
Chris@0 156 if (this.checkedItems.length === 0) {
Chris@0 157 this.$selected_div.hide();
Chris@0 158 }
Chris@0 159 }
Chris@0 160 this.refreshCheckedItems();
Chris@0 161 };
Chris@0 162
Chris@0 163 Drupal.viewsUi.AddItemForm.prototype.refreshCheckedItems = function () {
Chris@0 164 this.$selected_div.find('.views-selected-options').html(this.checkedItems.join(', ')).trigger('dialogContentResize');
Chris@0 165 };
Chris@0 166
Chris@0 167 Drupal.behaviors.viewsUiRenderAddViewButton = {
Chris@0 168 attach: function attach(context) {
Chris@0 169 var $menu = $(context).find('#views-display-menu-tabs').once('views-ui-render-add-view-button');
Chris@0 170 if (!$menu.length) {
Chris@0 171 return;
Chris@0 172 }
Chris@0 173
Chris@0 174 var $addDisplayDropdown = $('<li class="add"><a href="#"><span class="icon add"></span>' + Drupal.t('Add') + '</a><ul class="action-list" style="display:none;"></ul></li>');
Chris@0 175 var $displayButtons = $menu.nextAll('input.add-display').detach();
Chris@0 176 $displayButtons.appendTo($addDisplayDropdown.find('.action-list')).wrap('<li>').parent().eq(0).addClass('first').end().eq(-1).addClass('last');
Chris@0 177
Chris@0 178 $displayButtons.each(function () {
Chris@0 179 var label = $(this).val();
Chris@0 180 if (label.substr(0, 4) === 'Add ') {
Chris@0 181 $(this).val(label.substr(4));
Chris@0 182 }
Chris@0 183 });
Chris@0 184 $addDisplayDropdown.appendTo($menu);
Chris@0 185
Chris@0 186 $menu.find('li.add > a').on('click', function (event) {
Chris@0 187 event.preventDefault();
Chris@0 188 var $trigger = $(this);
Chris@0 189 Drupal.behaviors.viewsUiRenderAddViewButton.toggleMenu($trigger);
Chris@0 190 });
Chris@0 191
Chris@0 192 $('li.add', $menu).on('mouseleave', function (event) {
Chris@0 193 var $this = $(this);
Chris@0 194 var $trigger = $this.children('a[href="#"]');
Chris@0 195 if ($this.children('.action-list').is(':visible')) {
Chris@0 196 Drupal.behaviors.viewsUiRenderAddViewButton.toggleMenu($trigger);
Chris@0 197 }
Chris@0 198 });
Chris@0 199 }
Chris@0 200 };
Chris@0 201
Chris@0 202 Drupal.behaviors.viewsUiRenderAddViewButton.toggleMenu = function ($trigger) {
Chris@0 203 $trigger.parent().toggleClass('open');
Chris@0 204 $trigger.next().slideToggle('fast');
Chris@0 205 };
Chris@0 206
Chris@0 207 Drupal.behaviors.viewsUiSearchOptions = {
Chris@0 208 attach: function attach(context) {
Chris@0 209 var $context = $(context);
Chris@0 210 var $form = $context;
Chris@0 211
Chris@0 212 if (!$context.is('form[id^="views-ui-add-handler-form"]')) {
Chris@0 213 $form = $context.find('form[id^="views-ui-add-handler-form"]');
Chris@0 214 }
Chris@0 215
Chris@0 216 if ($form.once('views-ui-filter-options').length) {
Chris@0 217 new Drupal.viewsUi.OptionsSearch($form);
Chris@0 218 }
Chris@0 219 }
Chris@0 220 };
Chris@0 221
Chris@0 222 Drupal.viewsUi.OptionsSearch = function ($form) {
Chris@0 223 this.$form = $form;
Chris@0 224
Chris@0 225 this.$form.on('click', 'td.title', function (event) {
Chris@0 226 var $target = $(event.currentTarget);
Chris@0 227 $target.closest('tr').find('input').trigger('click');
Chris@0 228 });
Chris@0 229
Chris@0 230 var searchBoxSelector = '[data-drupal-selector="edit-override-controls-options-search"]';
Chris@0 231 var controlGroupSelector = '[data-drupal-selector="edit-override-controls-group"]';
Chris@0 232 this.$form.on('formUpdated', searchBoxSelector + ',' + controlGroupSelector, $.proxy(this.handleFilter, this));
Chris@0 233
Chris@0 234 this.$searchBox = this.$form.find(searchBoxSelector);
Chris@0 235 this.$controlGroup = this.$form.find(controlGroupSelector);
Chris@0 236
Chris@0 237 this.options = this.getOptions(this.$form.find('.filterable-option'));
Chris@0 238
Chris@0 239 this.$searchBox.on('keypress', function (event) {
Chris@0 240 if (event.which === 13) {
Chris@0 241 event.preventDefault();
Chris@0 242 }
Chris@0 243 });
Chris@0 244 };
Chris@0 245
Chris@0 246 $.extend(Drupal.viewsUi.OptionsSearch.prototype, {
Chris@0 247 getOptions: function getOptions($allOptions) {
Chris@0 248 var $title = void 0;
Chris@0 249 var $description = void 0;
Chris@0 250 var $option = void 0;
Chris@0 251 var options = [];
Chris@0 252 var length = $allOptions.length;
Chris@0 253 for (var i = 0; i < length; i++) {
Chris@0 254 $option = $($allOptions[i]);
Chris@0 255 $title = $option.find('.title');
Chris@0 256 $description = $option.find('.description');
Chris@0 257 options[i] = {
Chris@0 258 searchText: $title.text().toLowerCase() + ' ' + $description.text().toLowerCase(),
Chris@0 259
Chris@0 260 $div: $option
Chris@0 261 };
Chris@0 262 }
Chris@0 263 return options;
Chris@0 264 },
Chris@0 265 handleFilter: function handleFilter(event) {
Chris@0 266 var search = this.$searchBox.val().toLowerCase();
Chris@0 267 var words = search.split(' ');
Chris@0 268
Chris@0 269 var group = this.$controlGroup.val();
Chris@0 270
Chris@0 271 this.options.forEach(function (option) {
Chris@0 272 function hasWord(word) {
Chris@0 273 return option.searchText.indexOf(word) !== -1;
Chris@0 274 }
Chris@0 275
Chris@0 276 var found = true;
Chris@0 277
Chris@0 278 if (search) {
Chris@0 279 found = words.every(hasWord);
Chris@0 280 }
Chris@0 281 if (found && group !== 'all') {
Chris@0 282 found = option.$div.hasClass(group);
Chris@0 283 }
Chris@0 284
Chris@0 285 option.$div.toggle(found);
Chris@0 286 });
Chris@0 287
Chris@0 288 $(event.target).trigger('dialogContentResize');
Chris@0 289 }
Chris@0 290 });
Chris@0 291
Chris@0 292 Drupal.behaviors.viewsUiPreview = {
Chris@0 293 attach: function attach(context) {
Chris@0 294 var $contextualFiltersBucket = $(context).find('.views-display-column .views-ui-display-tab-bucket.argument');
Chris@0 295 if ($contextualFiltersBucket.length === 0) {
Chris@0 296 return;
Chris@0 297 }
Chris@0 298
Chris@0 299 var $contextualFilters = $contextualFiltersBucket.find('.views-display-setting a');
Chris@0 300 if ($contextualFilters.length) {
Chris@0 301 $('#preview-args').parent().show();
Chris@0 302 } else {
Chris@0 303 $('#preview-args').parent().hide();
Chris@0 304 }
Chris@0 305
Chris@0 306 if ($('#edit-displays-live-preview').once('edit-displays-live-preview').is(':checked')) {
Chris@0 307 $('#preview-submit').once('edit-displays-live-preview').trigger('click');
Chris@0 308 }
Chris@0 309 }
Chris@0 310 };
Chris@0 311
Chris@0 312 Drupal.behaviors.viewsUiRearrangeFilter = {
Chris@0 313 attach: function attach(context) {
Chris@0 314 if (typeof Drupal.tableDrag === 'undefined' || typeof Drupal.tableDrag['views-rearrange-filters'] === 'undefined') {
Chris@0 315 return;
Chris@0 316 }
Chris@0 317 var $context = $(context);
Chris@0 318 var $table = $context.find('#views-rearrange-filters').once('views-rearrange-filters');
Chris@0 319 var $operator = $context.find('.js-form-item-filter-groups-operator').once('views-rearrange-filters');
Chris@0 320 if ($table.length) {
Chris@0 321 new Drupal.viewsUi.RearrangeFilterHandler($table, $operator);
Chris@0 322 }
Chris@0 323 }
Chris@0 324 };
Chris@0 325
Chris@0 326 Drupal.viewsUi.RearrangeFilterHandler = function ($table, $operator) {
Chris@0 327 this.table = $table;
Chris@0 328
Chris@0 329 this.operator = $operator;
Chris@0 330
Chris@0 331 this.hasGroupOperator = this.operator.length > 0;
Chris@0 332
Chris@0 333 this.draggableRows = $table.find('.draggable');
Chris@0 334
Chris@0 335 this.addGroupButton = $('input#views-add-group');
Chris@0 336
Chris@0 337 this.removeGroupButtons = $table.find('input.views-remove-group');
Chris@0 338
Chris@0 339 this.insertAddRemoveFilterGroupLinks();
Chris@0 340
Chris@0 341 if (this.hasGroupOperator) {
Chris@0 342 this.dropdowns = this.duplicateGroupsOperator();
Chris@0 343 this.syncGroupsOperators();
Chris@0 344 }
Chris@0 345
Chris@0 346 this.modifyTableDrag();
Chris@0 347
Chris@0 348 this.redrawOperatorLabels();
Chris@0 349 $table.find('.views-group-title select').once('views-rearrange-filter-handler').on('change.views-rearrange-filter-handler', $.proxy(this, 'redrawOperatorLabels'));
Chris@0 350
Chris@0 351 $table.find('a.views-groups-remove-link').once('views-rearrange-filter-handler').on('click.views-rearrange-filter-handler', $.proxy(this, 'updateRowspans')).on('click.views-rearrange-filter-handler', $.proxy(this, 'redrawOperatorLabels'));
Chris@0 352 };
Chris@0 353
Chris@0 354 $.extend(Drupal.viewsUi.RearrangeFilterHandler.prototype, {
Chris@0 355 insertAddRemoveFilterGroupLinks: function insertAddRemoveFilterGroupLinks() {
Chris@0 356 $('<ul class="action-links"><li><a id="views-add-group-link" href="#">' + this.addGroupButton.val() + '</a></li></ul>').prependTo(this.table.parent()).once('views-rearrange-filter-handler').find('#views-add-group-link').on('click.views-rearrange-filter-handler', $.proxy(this, 'clickAddGroupButton'));
Chris@0 357
Chris@0 358 var length = this.removeGroupButtons.length;
Chris@0 359 var i = void 0;
Chris@0 360 for (i = 0; i < length; i++) {
Chris@0 361 var $removeGroupButton = $(this.removeGroupButtons[i]);
Chris@0 362 var buttonId = $removeGroupButton.attr('id');
Chris@0 363 $('<a href="#" class="views-remove-group-link">' + Drupal.t('Remove group') + '</a>').insertBefore($removeGroupButton).once('views-rearrange-filter-handler').on('click.views-rearrange-filter-handler', { buttonId: buttonId }, $.proxy(this, 'clickRemoveGroupButton'));
Chris@0 364 }
Chris@0 365 },
Chris@0 366 clickAddGroupButton: function clickAddGroupButton(event) {
Chris@0 367 this.addGroupButton.trigger('mousedown');
Chris@0 368 event.preventDefault();
Chris@0 369 },
Chris@0 370 clickRemoveGroupButton: function clickRemoveGroupButton(event) {
Chris@0 371 this.table.find('#' + event.data.buttonId).trigger('mousedown');
Chris@0 372 event.preventDefault();
Chris@0 373 },
Chris@0 374 duplicateGroupsOperator: function duplicateGroupsOperator() {
Chris@0 375 var newRow = void 0;
Chris@0 376 var titleRow = void 0;
Chris@0 377
Chris@0 378 var titleRows = $('tr.views-group-title').once('duplicateGroupsOperator');
Chris@0 379
Chris@0 380 if (!titleRows.length) {
Chris@0 381 return this.operator;
Chris@0 382 }
Chris@0 383
Chris@0 384 this.operator.find('label').add('div.description').addClass('visually-hidden');
Chris@0 385 this.operator.find('select').addClass('form-select');
Chris@0 386
Chris@14 387 var dropdowns = this.operator;
Chris@0 388
Chris@0 389 titleRow = $('tr#views-group-title-2');
Chris@0 390 newRow = $('<tr class="filter-group-operator-row"><td colspan="5"></td></tr>');
Chris@0 391 newRow.find('td').append(this.operator);
Chris@0 392 newRow.insertBefore(titleRow);
Chris@0 393 var length = titleRows.length;
Chris@0 394
Chris@0 395 for (var i = 2; i < length; i++) {
Chris@0 396 titleRow = $(titleRows[i]);
Chris@0 397
Chris@0 398 var fakeOperator = this.operator.clone();
Chris@0 399 fakeOperator.attr('id', '');
Chris@0 400 newRow = $('<tr class="filter-group-operator-row"><td colspan="5"></td></tr>');
Chris@0 401 newRow.find('td').append(fakeOperator);
Chris@0 402 newRow.insertBefore(titleRow);
Chris@0 403 dropdowns.add(fakeOperator);
Chris@0 404 }
Chris@0 405
Chris@0 406 return dropdowns;
Chris@0 407 },
Chris@0 408 syncGroupsOperators: function syncGroupsOperators() {
Chris@0 409 if (this.dropdowns.length < 2) {
Chris@0 410 return;
Chris@0 411 }
Chris@0 412
Chris@0 413 this.dropdowns.on('change', $.proxy(this, 'operatorChangeHandler'));
Chris@0 414 },
Chris@0 415 operatorChangeHandler: function operatorChangeHandler(event) {
Chris@0 416 var $target = $(event.target);
Chris@0 417 var operators = this.dropdowns.find('select').not($target);
Chris@0 418
Chris@0 419 operators.val($target.val());
Chris@0 420 },
Chris@0 421 modifyTableDrag: function modifyTableDrag() {
Chris@0 422 var tableDrag = Drupal.tableDrag['views-rearrange-filters'];
Chris@0 423 var filterHandler = this;
Chris@0 424
Chris@0 425 tableDrag.row.prototype.onSwap = function () {
Chris@0 426 if (filterHandler.hasGroupOperator) {
Chris@0 427 var thisRow = $(this.group);
Chris@0 428 var previousRow = thisRow.prev('tr');
Chris@0 429 if (previousRow.length && !previousRow.hasClass('group-message') && !previousRow.hasClass('draggable')) {
Chris@0 430 var next = thisRow.next();
Chris@0 431 if (next.is('tr')) {
Chris@0 432 this.swap('after', next);
Chris@0 433 }
Chris@0 434 }
Chris@0 435 filterHandler.updateRowspans();
Chris@0 436 }
Chris@0 437
Chris@0 438 filterHandler.redrawOperatorLabels();
Chris@0 439 };
Chris@0 440
Chris@0 441 tableDrag.onDrop = function () {
Chris@0 442 var changeMarker = $(this.oldRowElement).find('.tabledrag-changed');
Chris@0 443 if (changeMarker.length) {
Chris@0 444 var operatorLabel = changeMarker.prevAll('.views-operator-label');
Chris@0 445 if (operatorLabel.length) {
Chris@0 446 operatorLabel.insertAfter(changeMarker);
Chris@0 447 }
Chris@0 448 }
Chris@0 449
Chris@0 450 var groupRow = $(this.rowObject.element).prevAll('tr.group-message').get(0);
Chris@0 451 var groupName = groupRow.className.replace(/([^ ]+[ ]+)*group-([^ ]+)-message([ ]+[^ ]+)*/, '$2');
Chris@0 452 var groupField = $('select.views-group-select', this.rowObject.element);
Chris@18 453 if (!groupField.is('.views-group-select-' + groupName)) {
Chris@0 454 var oldGroupName = groupField.attr('class').replace(/([^ ]+[ ]+)*views-group-select-([^ ]+)([ ]+[^ ]+)*/, '$2');
Chris@0 455 groupField.removeClass('views-group-select-' + oldGroupName).addClass('views-group-select-' + groupName);
Chris@0 456 groupField.val(groupName);
Chris@0 457 }
Chris@0 458 };
Chris@0 459 },
Chris@0 460 redrawOperatorLabels: function redrawOperatorLabels() {
Chris@0 461 for (var i = 0; i < this.draggableRows.length; i++) {
Chris@0 462 var $draggableRow = $(this.draggableRows[i]);
Chris@0 463 var $firstCell = $draggableRow.find('td').eq(0);
Chris@0 464 if ($firstCell.length) {
Chris@0 465 var operatorValue = $draggableRow.prevAll('.views-group-title').find('option:selected').html();
Chris@0 466 var operatorLabel = '<span class="views-operator-label">' + operatorValue + '</span>';
Chris@0 467
Chris@0 468 var $nextRow = $draggableRow.nextAll(':visible').eq(0);
Chris@0 469 var $existingOperatorLabel = $firstCell.find('.views-operator-label');
Chris@0 470 if ($nextRow.hasClass('draggable')) {
Chris@0 471 if ($existingOperatorLabel.length) {
Chris@0 472 $existingOperatorLabel.replaceWith(operatorLabel);
Chris@0 473 } else {
Chris@0 474 $firstCell.append(operatorLabel);
Chris@0 475 }
Chris@0 476 } else {
Chris@0 477 $existingOperatorLabel.remove();
Chris@0 478 }
Chris@0 479 }
Chris@0 480 }
Chris@0 481 },
Chris@0 482 updateRowspans: function updateRowspans() {
Chris@0 483 var $row = void 0;
Chris@0 484 var $currentEmptyRow = void 0;
Chris@0 485 var draggableCount = void 0;
Chris@0 486 var $operatorCell = void 0;
Chris@0 487 var rows = $(this.table).find('tr');
Chris@0 488 var length = rows.length;
Chris@0 489 for (var i = 0; i < length; i++) {
Chris@0 490 $row = $(rows[i]);
Chris@0 491 if ($row.hasClass('views-group-title')) {
Chris@0 492 $operatorCell = $row.find('td.group-operator');
Chris@0 493
Chris@0 494 draggableCount = 0;
Chris@0 495 $currentEmptyRow = $row.next('tr');
Chris@0 496 $currentEmptyRow.removeClass('group-populated').addClass('group-empty');
Chris@0 497
Chris@0 498 $operatorCell.attr('rowspan', 2);
Chris@0 499 } else if ($row.hasClass('draggable') && $row.is(':visible')) {
Chris@0 500 draggableCount++;
Chris@0 501 $currentEmptyRow.removeClass('group-empty').addClass('group-populated');
Chris@0 502
Chris@0 503 $operatorCell.attr('rowspan', draggableCount + 1);
Chris@0 504 }
Chris@0 505 }
Chris@0 506 }
Chris@0 507 });
Chris@0 508
Chris@0 509 Drupal.behaviors.viewsFilterConfigSelectAll = {
Chris@0 510 attach: function attach(context) {
Chris@0 511 var $context = $(context);
Chris@0 512
Chris@0 513 var $selectAll = $context.find('.js-form-item-options-value-all').once('filterConfigSelectAll');
Chris@0 514 var $selectAllCheckbox = $selectAll.find('input[type=checkbox]');
Chris@0 515 var $checkboxes = $selectAll.closest('.form-checkboxes').find('.js-form-type-checkbox:not(.js-form-item-options-value-all) input[type="checkbox"]');
Chris@0 516
Chris@0 517 if ($selectAll.length) {
Chris@0 518 $selectAll.show();
Chris@0 519 $selectAllCheckbox.on('click', function () {
Chris@0 520 $checkboxes.prop('checked', $(this).is(':checked'));
Chris@0 521 });
Chris@0 522
Chris@0 523 $checkboxes.on('click', function () {
Chris@0 524 if ($(this).is('checked') === false) {
Chris@0 525 $selectAllCheckbox.prop('checked', false);
Chris@0 526 }
Chris@0 527 });
Chris@0 528 }
Chris@0 529 }
Chris@0 530 };
Chris@0 531
Chris@0 532 Drupal.behaviors.viewsRemoveIconClass = {
Chris@0 533 attach: function attach(context) {
Chris@0 534 $(context).find('.dropbutton').once('dropbutton-icon').find('.icon').removeClass('icon');
Chris@0 535 }
Chris@0 536 };
Chris@0 537
Chris@0 538 Drupal.behaviors.viewsUiCheckboxify = {
Chris@0 539 attach: function attach(context, settings) {
Chris@0 540 var $buttons = $('[data-drupal-selector="edit-options-expose-button-button"], [data-drupal-selector="edit-options-group-button-button"]').once('views-ui-checkboxify');
Chris@0 541 var length = $buttons.length;
Chris@0 542 var i = void 0;
Chris@0 543 for (i = 0; i < length; i++) {
Chris@0 544 new Drupal.viewsUi.Checkboxifier($buttons[i]);
Chris@0 545 }
Chris@0 546 }
Chris@0 547 };
Chris@0 548
Chris@0 549 Drupal.behaviors.viewsUiChangeDefaultWidget = {
Chris@0 550 attach: function attach(context) {
Chris@0 551 var $context = $(context);
Chris@0 552
Chris@0 553 function changeDefaultWidget(event) {
Chris@0 554 if ($(event.target).prop('checked')) {
Chris@0 555 $context.find('input.default-radios').parent().hide();
Chris@0 556 $context.find('td.any-default-radios-row').parent().hide();
Chris@0 557 $context.find('input.default-checkboxes').parent().show();
Chris@0 558 } else {
Chris@0 559 $context.find('input.default-checkboxes').parent().hide();
Chris@0 560 $context.find('td.any-default-radios-row').parent().show();
Chris@0 561 $context.find('input.default-radios').parent().show();
Chris@0 562 }
Chris@0 563 }
Chris@0 564
Chris@0 565 $context.find('input[name="options[group_info][multiple]"]').on('change', changeDefaultWidget).trigger('change');
Chris@0 566 }
Chris@0 567 };
Chris@0 568
Chris@0 569 Drupal.viewsUi.Checkboxifier = function (button) {
Chris@0 570 this.$button = $(button);
Chris@0 571 this.$parent = this.$button.parent('div.views-expose, div.views-grouped');
Chris@0 572 this.$input = this.$parent.find('input:checkbox, input:radio');
Chris@0 573
Chris@0 574 this.$button.hide();
Chris@0 575 this.$parent.find('.exposed-description, .grouped-description').hide();
Chris@0 576
Chris@0 577 this.$input.on('click', $.proxy(this, 'clickHandler'));
Chris@0 578 };
Chris@0 579
Chris@0 580 Drupal.viewsUi.Checkboxifier.prototype.clickHandler = function (e) {
Chris@0 581 this.$button.trigger('click').trigger('submit');
Chris@0 582 };
Chris@0 583
Chris@0 584 Drupal.behaviors.viewsUiOverrideSelect = {
Chris@0 585 attach: function attach(context) {
Chris@0 586 $(context).find('[data-drupal-selector="edit-override-dropdown"]').once('views-ui-override-button-text').each(function () {
Chris@0 587 var $context = $(context);
Chris@0 588 var $submit = $context.find('[id^=edit-submit]');
Chris@14 589 var oldValue = $submit.val();
Chris@0 590
Chris@0 591 $submit.once('views-ui-override-button-text').on('mouseup', function () {
Chris@14 592 $(this).val(oldValue);
Chris@0 593 return true;
Chris@0 594 });
Chris@0 595
Chris@0 596 $(this).on('change', function () {
Chris@0 597 var $this = $(this);
Chris@0 598 if ($this.val() === 'default') {
Chris@0 599 $submit.val(Drupal.t('Apply (all displays)'));
Chris@0 600 } else if ($this.val() === 'default_revert') {
Chris@0 601 $submit.val(Drupal.t('Revert to default'));
Chris@0 602 } else {
Chris@0 603 $submit.val(Drupal.t('Apply (this display)'));
Chris@0 604 }
Chris@0 605 var $dialog = $context.closest('.ui-dialog-content');
Chris@0 606 $dialog.trigger('dialogButtonsChange');
Chris@0 607 }).trigger('change');
Chris@0 608 });
Chris@0 609 }
Chris@0 610 };
Chris@0 611
Chris@0 612 Drupal.behaviors.viewsUiHandlerRemoveLink = {
Chris@0 613 attach: function attach(context) {
Chris@0 614 var $context = $(context);
Chris@0 615
Chris@0 616 $context.find('a.views-remove-link').once('views').on('click', function (event) {
Chris@0 617 var id = $(this).attr('id').replace('views-remove-link-', '');
Chris@0 618 $context.find('#views-row-' + id).hide();
Chris@0 619 $context.find('#views-removed-' + id).prop('checked', true);
Chris@0 620 event.preventDefault();
Chris@0 621 });
Chris@0 622
Chris@0 623 $context.find('a.display-remove-link').once('display').on('click', function (event) {
Chris@0 624 var id = $(this).attr('id').replace('display-remove-link-', '');
Chris@0 625 $context.find('#display-row-' + id).hide();
Chris@0 626 $context.find('#display-removed-' + id).prop('checked', true);
Chris@0 627 event.preventDefault();
Chris@0 628 });
Chris@0 629 }
Chris@0 630 };
Chris@0 631 })(jQuery, Drupal, drupalSettings);