/* * Textpattern Content Management System * http://textpattern.com * * Copyright (C) 2016 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 . */ /** * Collection of client-side tools. */ /** * Ascertain the page direction (LTR or RTL) as a variable. */ var langdir = document.documentElement.dir; /** * Checks if HTTP cookies are enabled. * * @return {boolean} */ function checkCookies() { var date = new Date(); date.setTime(date.getTime() + (60 * 1000)); document.cookie = 'testcookie=enabled; expired=' + date.toGMTString() + '; path=/'; cookieEnabled = (document.cookie.length > 2) ? true : false; date.setTime(date.getTime() - (60 * 1000)); document.cookie = 'testcookie=; expires=' + date.toGMTString() + '; path=/'; return cookieEnabled; } /** * Spawns a centred popup window. * * @param {string} url The location * @param {integer} width The width * @param {integer} height The height * @param {string} options A list of options */ function popWin(url, width, height, options) { var w = (width) ? width : 400; var h = (height) ? height : 400; var t = (screen.height) ? (screen.height - h) / 2 : 0; var l = (screen.width) ? (screen.width - w) / 2 : 0; var opt = (options) ? options : 'toolbar = no, location = no, directories = no, ' + 'status = yes, menubar = no, scrollbars = yes, copyhistory = no, resizable = yes'; var popped = window.open(url, 'popupwindow', 'top = ' + t + ', left = ' + l + ', width = ' + w + ', height = ' + h + ',' + opt); popped.focus(); } /** * Legacy multi-edit tool. * * @param {object} elm * @deprecated in 4.6.0 */ function poweredit(elm) { var something = elm.options[elm.selectedIndex].value; // Add another chunk of HTML var pjs = document.getElementById('js'); if (pjs == null) { var br = document.createElement('br'); elm.parentNode.appendChild(br); pjs = document.createElement('P'); pjs.setAttribute('id', 'js'); elm.parentNode.appendChild(pjs); } if (pjs.style.display == 'none' || pjs.style.display == '') { pjs.style.display = 'block'; } if (something != '') { switch (something) { default: pjs.style.display = 'none'; break; } } return false; } /** * 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); } /** * Selects all multi-edit checkboxes. * * @deprecated in 4.5.0 */ function selectall() { $('form[name=longform] input[type=checkbox][name="selected[]"]').prop('checked', true); } /** * De-selects all multi-edit checkboxes. * * @deprecated in 4.5.0 */ function deselectall() { $('form[name=longform] input[type=checkbox][name="selected[]"]').prop('checked', false); } /** * Selects a range of multi-edit checkboxes. * * @deprecated in 4.5.0 */ function selectrange() { var inrange = false; $('form[name=longform] input[type=checkbox][name="selected[]"]').each(function () { var $this = $(this); if ($this.is(':checked')) { inrange = (!inrange) ? true : false; } if (inrange) { $this.prop('checked', true); } }); } /** * ? * * @deprecated in 4.5.0 */ function cleanSelects() { var withsel = document.getElementById('withselected'); if (withsel && withsel.options[withsel.selectedIndex].value != '') { return (withsel.selectedIndex = 0); } } /** * 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', '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.boxes = opt.checkbox; form.editMethod = $this.find(opt.actions); form.lastCheck = null; form.opt = opt; form.selectAll = $this.find(opt.selectAll); form.button = $this.find(opt.submitButton); } /** * 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 = $('