/* eslint-env jquery */ /* * Textpattern Content Management System * https://textpattern.com/ * * Copyright (C) 2020 The Textpattern Development Team * * This file is part of Textpattern. * * Textpattern is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation, version 2. * * Textpattern is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Textpattern. If not, see . */ 'use strict'; /** * Collection of client-side tools. */ textpattern.version = '4.8.4'; /** * Ascertain the page direction (LTR or RTL) as a variable. */ var langdir = document.documentElement.dir, dir = langdir === 'rtl' ? 'left' : 'right'; /** * Checks if HTTP cookies are enabled. * * @return {boolean} */ function checkCookies() { cookieEnabled = navigator.cookieEnabled && (document.cookie.indexOf('txp_test_cookie') >= 0 || document.cookie.indexOf('txp_login') >= 0); if (!cookieEnabled) { textpattern.Console.addMessage([textpattern.gTxt('cookies_must_be_enabled'), 1]); } else { document.cookie = 'txp_test_cookie=; Max-Age=0; SameSite=Lax'; } } /** * Basic confirmation for potentially powerful choices (like deletion, * for example). * * @param {string} msg The message * @return {boolean} TRUE if user confirmed the action */ function verify(msg) { return confirm(msg); } /** * Multi-edit functions. * * @param {string|object} method Called method, or options * @param {object} opt Options if method is a method * @return {object} this * @since 4.5.0 */ jQuery.fn.txpMultiEditForm = function (method, opt) { var args = {}; var defaults = { 'checkbox' : 'input[name="selected[]"][type=checkbox]', 'row' : 'tbody td', 'highlighted' : 'tr', 'filteredClass': 'filtered', 'selectedClass': 'selected', 'actions' : 'select[name=edit_method]', 'submitButton' : '.multi-edit input[type=submit]', 'selectAll' : 'input[name=select_all][type=checkbox]', 'rowClick' : true, 'altClick' : true, 'confirmation' : textpattern.gTxt('are_you_sure') }; if ($.type(method) !== 'string') { opt = method; method = null; } else { args = opt; } this./*closest('form').*/each(function () { var $this = $(this), form = {}, methods = {}, lib = {}; if ($this.data('_txpMultiEdit')) { form = $this.data('_txpMultiEdit'); opt = $.extend(form.opt, opt); } else { opt = $.extend(defaults, opt); form.editMethod = $this.find(opt.actions); form.lastCheck = null; form.opt = opt; form.selectAll = $this.find(opt.selectAll); form.button = $this.find(opt.submitButton); } form.boxes = $this.find(opt.checkbox); /** * Registers a multi-edit option. * * @param {object} options * @param {string} options.label The option's label * @param {string} options.value The option's value * @param {string} options.html The second step HTML * @return {object} methods */ methods.addOption = function (options) { var settings = $.extend({ 'label': null, 'value': null, 'html' : null }, options); if (!settings.value) { return methods; } var option = form.editMethod.find('option').filter(function () { return $(this).val() === settings.value; }); var exists = (option.length > 0); form.editMethod.val(''); if (!exists) { option = $('