File Editor
Directories:
.. (Back)
Files:
admin-spp-2.12.100.min.js
admin-spp-2.13.0.min.js
admin-spp.min.js
blocks-2.12.100.min.js
blocks-2.13.0.min.js
blocks.min.js
mce-spp.js
mce-stp.js
Create New File
Create
Edit File: admin-spp.min.js
(function () { /** * @license almond 0.3.1 Copyright (c) 2011-2014, The Dojo Foundation All Rights Reserved. * Available via the MIT or new BSD license. * see: http://github.com/jrburke/almond for details */ //Going sloppy to avoid 'use strict' string cost, but strict practices should //be followed. /*jslint sloppy: true */ /*global setTimeout: false */ var requirejs, require, define; (function (undef) { var main, req, makeMap, handlers, defined = {}, waiting = {}, config = {}, defining = {}, hasOwn = Object.prototype.hasOwnProperty, aps = [].slice, jsSuffixRegExp = /\.js$/; function hasProp(obj, prop) { return hasOwn.call(obj, prop); } /** * Given a relative module name, like ./something, normalize it to * a real name that can be mapped to a path. * @param {String} name the relative name * @param {String} baseName a real name that the name arg is relative * to. * @returns {String} normalized name */ function normalize(name, baseName) { var nameParts, nameSegment, mapValue, foundMap, lastIndex, foundI, foundStarMap, starI, i, j, part, baseParts = baseName && baseName.split("/"), map = config.map, starMap = (map && map['*']) || {}; //Adjust any relative paths. if (name && name.charAt(0) === ".") { //If have a base name, try to normalize against it, //otherwise, assume it is a top-level require that will //be relative to baseUrl in the end. if (baseName) { name = name.split('/'); lastIndex = name.length - 1; // Node .js allowance: if (config.nodeIdCompat && jsSuffixRegExp.test(name[lastIndex])) { name[lastIndex] = name[lastIndex].replace(jsSuffixRegExp, ''); } //Lop off the last part of baseParts, so that . matches the //"directory" and not name of the baseName's module. For instance, //baseName of "one/two/three", maps to "one/two/three.js", but we //want the directory, "one/two" for this normalization. name = baseParts.slice(0, baseParts.length - 1).concat(name); //start trimDots for (i = 0; i < name.length; i += 1) { part = name[i]; if (part === ".") { name.splice(i, 1); i -= 1; } else if (part === "..") { if (i === 1 && (name[2] === '..' || name[0] === '..')) { //End of the line. Keep at least one non-dot //path segment at the front so it can be mapped //correctly to disk. Otherwise, there is likely //no path mapping for a path starting with '..'. //This can still fail, but catches the most reasonable //uses of .. break; } else if (i > 0) { name.splice(i - 1, 2); i -= 2; } } } //end trimDots name = name.join("/"); } else if (name.indexOf('./') === 0) { // No baseName, so this is ID is resolved relative // to baseUrl, pull off the leading dot. name = name.substring(2); } } //Apply map config if available. if ((baseParts || starMap) && map) { nameParts = name.split('/'); for (i = nameParts.length; i > 0; i -= 1) { nameSegment = nameParts.slice(0, i).join("/"); if (baseParts) { //Find the longest baseName segment match in the config. //So, do joins on the biggest to smallest lengths of baseParts. for (j = baseParts.length; j > 0; j -= 1) { mapValue = map[baseParts.slice(0, j).join('/')]; //baseName segment has config, find if it has one for //this name. if (mapValue) { mapValue = mapValue[nameSegment]; if (mapValue) { //Match, update name to the new value. foundMap = mapValue; foundI = i; break; } } } } if (foundMap) { break; } //Check for a star map match, but just hold on to it, //if there is a shorter segment match later in a matching //config, then favor over this star map. if (!foundStarMap && starMap && starMap[nameSegment]) { foundStarMap = starMap[nameSegment]; starI = i; } } if (!foundMap && foundStarMap) { foundMap = foundStarMap; foundI = starI; } if (foundMap) { nameParts.splice(0, foundI, foundMap); name = nameParts.join('/'); } } return name; } function makeRequire(relName, forceSync) { return function () { //A version of a require function that passes a moduleName //value for items that may need to //look up paths relative to the moduleName var args = aps.call(arguments, 0); //If first arg is not require('string'), and there is only //one arg, it is the array form without a callback. Insert //a null so that the following concat is correct. if (typeof args[0] !== 'string' && args.length === 1) { args.push(null); } return req.apply(undef, args.concat([relName, forceSync])); }; } function makeNormalize(relName) { return function (name) { return normalize(name, relName); }; } function makeLoad(depName) { return function (value) { defined[depName] = value; }; } function callDep(name) { if (hasProp(waiting, name)) { var args = waiting[name]; delete waiting[name]; defining[name] = true; main.apply(undef, args); } if (!hasProp(defined, name) && !hasProp(defining, name)) { throw new Error('No ' + name); } return defined[name]; } //Turns a plugin!resource to [plugin, resource] //with the plugin being undefined if the name //did not have a plugin prefix. function splitPrefix(name) { var prefix, index = name ? name.indexOf('!') : -1; if (index > -1) { prefix = name.substring(0, index); name = name.substring(index + 1, name.length); } return [prefix, name]; } /** * Makes a name map, normalizing the name, and using a plugin * for normalization if necessary. Grabs a ref to plugin * too, as an optimization. */ makeMap = function (name, relName) { var plugin, parts = splitPrefix(name), prefix = parts[0]; name = parts[1]; if (prefix) { prefix = normalize(prefix, relName); plugin = callDep(prefix); } //Normalize according if (prefix) { if (plugin && plugin.normalize) { name = plugin.normalize(name, makeNormalize(relName)); } else { name = normalize(name, relName); } } else { name = normalize(name, relName); parts = splitPrefix(name); prefix = parts[0]; name = parts[1]; if (prefix) { plugin = callDep(prefix); } } //Using ridiculous property names for space reasons return { f: prefix ? prefix + '!' + name : name, //fullName n: name, pr: prefix, p: plugin }; }; function makeConfig(name) { return function () { return (config && config.config && config.config[name]) || {}; }; } handlers = { require: function (name) { return makeRequire(name); }, exports: function (name) { var e = defined[name]; if (typeof e !== 'undefined') { return e; } else { return (defined[name] = {}); } }, module: function (name) { return { id: name, uri: '', exports: defined[name], config: makeConfig(name) }; } }; main = function (name, deps, callback, relName) { var cjsModule, depName, ret, map, i, args = [], callbackType = typeof callback, usingExports; //Use name if no relName relName = relName || name; //Call the callback to define the module, if necessary. if (callbackType === 'undefined' || callbackType === 'function') { //Pull out the defined dependencies and pass the ordered //values to the callback. //Default to [require, exports, module] if no deps deps = !deps.length && callback.length ? ['require', 'exports', 'module'] : deps; for (i = 0; i < deps.length; i += 1) { map = makeMap(deps[i], relName); depName = map.f; //Fast path CommonJS standard dependencies. if (depName === "require") { args[i] = handlers.require(name); } else if (depName === "exports") { //CommonJS module spec 1.1 args[i] = handlers.exports(name); usingExports = true; } else if (depName === "module") { //CommonJS module spec 1.1 cjsModule = args[i] = handlers.module(name); } else if (hasProp(defined, depName) || hasProp(waiting, depName) || hasProp(defining, depName)) { args[i] = callDep(depName); } else if (map.p) { map.p.load(map.n, makeRequire(relName, true), makeLoad(depName), {}); args[i] = defined[depName]; } else { throw new Error(name + ' missing ' + depName); } } ret = callback ? callback.apply(defined[name], args) : undefined; if (name) { //If setting exports via "module" is in play, //favor that over return value and exports. After that, //favor a non-undefined return value over exports use. if (cjsModule && cjsModule.exports !== undef && cjsModule.exports !== defined[name]) { defined[name] = cjsModule.exports; } else if (ret !== undef || !usingExports) { //Use the return value from the function. defined[name] = ret; } } } else if (name) { //May just be an object definition for the module. Only //worry about defining if have a module name. defined[name] = callback; } }; requirejs = require = req = function (deps, callback, relName, forceSync, alt) { if (typeof deps === "string") { if (handlers[deps]) { //callback in this case is really relName return handlers[deps](callback); } //Just return the module wanted. In this scenario, the //deps arg is the module name, and second arg (if passed) //is just the relName. //Normalize module name, if it contains . or .. return callDep(makeMap(deps, callback).f); } else if (!deps.splice) { //deps is a config object, not an array. config = deps; if (config.deps) { req(config.deps, config.callback); } if (!callback) { return; } if (callback.splice) { //callback is an array, which means it is a dependency list. //Adjust args if there are dependencies deps = callback; callback = relName; relName = null; } else { deps = undef; } } //Support require(['a']) callback = callback || function () {}; //If relName is a function, it is an errback handler, //so remove it. if (typeof relName === 'function') { relName = forceSync; forceSync = alt; } //Simulate async callback; if (forceSync) { main(undef, deps, callback, relName); } else { //Using a non-zero value because of concern for what old browsers //do, and latest browsers "upgrade" to 4 if lower value is used: //http://www.whatwg.org/specs/web-apps/current-work/multipage/timers.html#dom-windowtimers-settimeout: //If want a value immediately, use require('id') instead -- something //that works in almond on the global level, but not guaranteed and //unlikely to work in other AMD implementations. setTimeout(function () { main(undef, deps, callback, relName); }, 4); } return req; }; /** * Just drops the config on the floor, but returns req in case * the config return value is used. */ req.config = function (cfg) { return req(cfg); }; /** * Expose module registry for debugging and tooling */ requirejs._defined = defined; define = function (name, deps, callback) { if (typeof name !== 'string') { throw new Error('See almond README: incorrect module build, no module name'); } //This module may not have dependencies if (!deps.splice) { //deps is not an array, so probably means //an object literal or factory function for //the value. Adjust args. callback = deps; deps = []; } if (!hasProp(defined, name) && !hasProp(waiting, name)) { waiting[name] = [name, deps, callback]; } }; define.amd = { jQuery: true }; }()); define("../vendor/almond", function(){}); if ( typeof jQuery === 'function' ) { define( 'jquery', function ( $ ) { return jQuery; } ); } if (typeof _ === 'function') { define( 'underscore', function () { return _; }); } function timedAddHandler(addHandler) { if (addHandler() == 0) setTimeout(timedAddHandler, 1000, addHandler); } require(['jquery', 'underscore'], function($, _) { function switchTab(e) { $(".spp-nav-tab").removeClass("nav-tab-active"); $(e.currentTarget).addClass("nav-tab-active"); e.preventDefault(); $(".spp-tab-pane").removeClass("spp-tab-active"); var tabName = e.target.getAttribute("href"); $(tabName).addClass("spp-tab-active"); } $(".spp-nav-tab").click(switchTab); $(".spp-mbstring-dismiss").click(function() { $(".spp-mbstring-notice").hide(); $.ajax( ajaxurl, { type: 'POST', data: { action: 'spp_dismiss_mbstring_notice', } }); }); // Add Color Picker to all inputs that have 'color-field' class if (typeof($('.color-field').wpColorPicker) == "function") { $('.color-field').wpColorPicker(); } // Show or hide the STP background color picker based on the background selection function setStpBackgroundColorPickerVisible() { var sel = $( 'select[name="spp_player_defaults[stp_background]"]' ); if( sel.val() === "color" ) { sel.next( '.wp-picker-container' ).show(); sel.next( '.color-field' ).show(); } else { sel.next( '.wp-picker-container' ).hide(); sel.next( '.color-field' ).hide(); } } // Call once when the settings page is loaded setStpBackgroundColorPickerVisible(); // Call when the dialog option changes $( 'select[name="spp_player_defaults[stp_background]"]').change( function() { setStpBackgroundColorPickerVisible(); }); // Subscription option headers: expand when clicked, bold when not empty timedAddHandler(function() { return $(".spp-subscription-option-header").click( function() { $(this).closest(".spp-subscription-option").toggleClass("spp-subscription-option-expanded"); }).length }); $(".spp-subscription-input").on("input", function() { if (this.value) $(this).closest(".spp-subscription-option").addClass("spp-subscription-option-enabled"); else $(this).closest(".spp-subscription-option").removeClass("spp-subscription-option-enabled"); }); // Show the correct set of options based on whether email signup is enabled function setEmailerOptionsVisible() { $(".emailer_options").hide(); var table_id = $( 'select[name="spp_player_email[portal]"] ').val(); $(".emailer_options_" + table_id ).show(); } // Call once when the email portal page is loaded setEmailerOptionsVisible(); // Call when the email portal method changes (enabled or not) $( 'select[name="spp_player_email[portal]"]' ).change( function() { setEmailerOptionsVisible(); }); // Show the correct set of embed options for the email signup CTA (Constant Contact or other) function setEmbedOptionsVisible() { $(".embed_options").hide(); var table_id = $('select[name="spp_player_email[service]"]').val(); $(".embed_options_" + table_id).show(); } // Call once when the email portal page is loaded setEmbedOptionsVisible(); // Call when the service provider changes $( 'select[name="spp_player_email[service]"]' ).change( function() { setEmbedOptionsVisible(); }); // Show or hide Episode URL field (in sticky options) function setEpisodeUrlVisible() { var isVisible = $('select#spp-latest').val() == 'false'; if (isVisible) $("#spp-episode-url-row").show(); else $("#spp-episode-url-row").hide(); } setEpisodeUrlVisible(); $("select#spp-latest").change(function() { setEpisodeUrlVisible(); }); // Show the correct set of options based on whether sticky player is enabled function setStickyOptionsVisible() { var isEnabled = $( 'select[name="spp_player_sticky[enabled]"]').val() == "true"; if (isEnabled) $(".spp-sticky-options").show(); else $(".spp-sticky-options").hide(); } // Call once when the sticky options page is loaded setStickyOptionsVisible(); // Call when it changes $( 'select[name="spp_player_sticky[enabled]"]' ).change( function() { setStickyOptionsVisible(); }); // Sticky player show/hide advanced options $('#spp-show-advanced').click(function() { $('.spp-sticky-advanced-options').slideToggle(); this.value = (this.value == "Show") ? "Hide" : "Show"; }); // Show the correct set of options based on which function the featured button has function setFeaturedButtonOptionsVisible() { $(".spp-featured-cta-email, .spp-featured-cta-link, .spp-featured-cta-javascript").hide(); var fn = $( 'select[name="spp_player_email[button_function]"]').val(); if (fn == "email") $(".spp-featured-cta-email").show(); else if (fn == "link") $(".spp-featured-cta-link").show(); else if (fn == "javascript") $(".spp-featured-cta-javascript").show(); } // Call once when the page is loaded setFeaturedButtonOptionsVisible(); // Call when the button function changes $( 'select[name="spp_player_email[button_function]"]' ).change( function() { setFeaturedButtonOptionsVisible(); }); // Indent some tables in the options page $('.spp-indent-ancestor-table').closest('table').addClass('spp-indented-option'); // Widen the first column of some tables in the options page $('.spp-wider-left-column').closest('tr').children('th').addClass('spp-wider-column'); }); define("admin-spp", function(){}); if ( typeof jQuery === 'function' ) { define( 'jquery', function ( $ ) { return jQuery; } ); } if (typeof _ === 'function') { define( 'underscore', function () { return _; }); } require(['jquery', 'underscore'], function($, _) { function urlCanon(url) { url = url.replace(/^https?:\/\//, ''); // Remove protocol url = url.replace(/\?.*$/, ''); // Remove query string return url; } function timeWithColons(time) { var seconds = time % 60; var minutes = Math.floor(time / 60) % 60; var hours = Math.floor(time / 3600); var secPad = seconds < 10 ? "0" : ""; var minPad = minutes < 10 ? "0" : ""; if (hours == 0) return minutes + ":" + secPad + seconds; return hours + ":" + minPad + minutes + ":" + secPad + seconds; } const headerRowTemplate = '<div class="spp-timestamp-row">' + '<span class="spp-timestamp-button-buffer"></span>' + '<span class="spp-timestamp-column-header spp-timestamp-time">Time</span>' + '<span class="spp-timestamp-column-header spp-timestamp-text">Text</span>' + '</div>'; const partialRowTemplate = '<div class="spp-timestamp-row">' + '<button type="button" class="spp-add-button">' + '<span class="dashicons dashicons-plus"></span>' + '</button>' + '</div>'; const fullRowTemplate = '<div class="spp-timestamp-row spp-timestamp-full-row">' + '<button type="button" class="spp-remove-button">' + '<span class="dashicons dashicons-no"></span>' + '</button>' + '<input type="text" class="spp-timestamp-time" size="4" value="" ' + 'name="spp_player_timestamps[dump]" >' + '<input type="text" class="spp-timestamp-text" size="70" value="" ' + 'name="spp_player_timestamps[dump]">' + '</div>'; const hiddenRowTemplate = '<input type="hidden" name="spp_player_timestamps[stamps][<%= stream_url %>][<%= time %>]" ' + 'value="<%= text %>">'; // Add a row to the Timestamps page. Returns the last complete row. function addTimestampRow() { var oldRowTemplate = _.template(fullRowTemplate); var oldRow = $(oldRowTemplate()); $(".spp-add-button").closest(".spp-timestamp-row").replaceWith(oldRow); oldRow.find(".spp-remove-button").click(removeTimestampRow); oldRow.find(".spp-timestamp-time").change(disableTrackSelector); oldRow.find(".spp-timestamp-text").change(disableTrackSelector); var newRow = $(partialRowTemplate); newRow.find(".spp-add-button").click(addTimestampRow); $(".spp-timestamp-table").append(newRow); return oldRow; } // Remove a row from the Timestamps page function removeTimestampRow(e) { var row = $(e.currentTarget).closest(".spp-timestamp-row"); row.remove(); } function getRef(track) { // If the ref already exists, use that var ref = _.invert(SmartPodcastPlayerAdmin.timestamp_refs)[urlCanon(track.stream_url)]; if (ref) return ref; // Otherwise, shorten the portion after the last '/' in the URL var slash = track.stream_url.lastIndexOf('/'); ref = track.stream_url.substring(slash + 1, slash + 7) // If this ref exists, add a number until it doesn't var i = 1, orig_ref = ref; while (_.keys(SmartPodcastPlayerAdmin.timestamp_refs).includes(ref)) { ref = orig_ref + "-" + i; i = i + 1; } return ref; } function showRefOptions(track) { var ref = getRef(track); $('.spp-timestamp-ref').val(ref); $('.spp-timestamp-ref').attr('name', 'spp_player_timestamps[refs][' + urlCanon(track.stream_url) + ']'); $('.spp-timestamp-shortcode').text('[ftp_timestamps ref="' + ref + '"]'); $('.spp-copy-timestamp-shortcode').click(copyShortcodeText); $(".spp-timestamp-reference-options").show(); } function disableTrackSelector() { $("#spp-track-picker").attr("disabled", "disabled"); $(".spp-track-selector-helper").show(); } function enableTrackSelector() { $("#spp-track-picker").removeAttr('disabled'); $(".spp-track-selector-helper").hide(); } function selectTrack() { // Kill the old table $('.spp-timestamp-row').remove(); // Start a new table $('.spp-timestamp-table').append(_.template(headerRowTemplate)); var index = $('#spp-track-picker').val(); var track = sppTracks[index]; addTimestampRow(); // Will be an empty "+" row if (!track.timestamps || track.timestamps.length == 0) { // Add another empty row to get started var lastRow = addTimestampRow(); $(".spp-timestamp-reference-options").hide(); lastRow.find('.spp-timestamp-time').change(function(e) { showRefOptions(track); disableTrackSelector(); }); } else { // Pull any timestamps that are already in the DB var pairs = _.pairs(track.timestamps); for (var i = 0; i < pairs.length; i++) { var lastRow = addTimestampRow(); lastRow.find('.spp-timestamp-time').val(timeWithColons(pairs[i][0])); lastRow.find('.spp-timestamp-text').val(pairs[i][1]); } showRefOptions(track); } } function copyShortcodeText() { var textArea = document.createElement("textarea"); textArea.value = $('.spp-timestamp-shortcode').text(); document.body.appendChild(textArea); textArea.select(); document.execCommand('copy'); document.body.removeChild(textArea); } var sppTracks = []; var rssTracks = []; function constructTrackDropdown() { $("#spp-track-picker").remove(); var trackPicker = $("<select id='spp-track-picker'>"); var selIndex = -1; _.each(sppTracks, function(el, index) { trackPicker.append($("<option>").attr('value', index).text(el.title)); if (SmartPodcastPlayerAdmin.last_timestamp_set == urlCanon(el.stream_url)) selIndex = index; }); if (selIndex !== -1) trackPicker[0].selectedIndex = selIndex; trackPicker.change(selectTrack); $(".spp-timestamp-table").before(trackPicker); selectTrack(); } // We're on the Timestamps page. Start with an Ajax call to get the tracks function loadFeed() { var feed_url = $('#spp-timestamps-feed-url').val(); $('.spp-feed-error').css('display', 'none'); $('.spp-loading-feed').css('display', 'block'); $.ajax({ url: SmartPodcastPlayerAdmin.ajax_url, dataType: 'json', type: 'POST', async: true, data: { action: 'get_spplayer_tracks', stream: feed_url, }, success: function(tracks) { $('.spp-loading-feed').css('display', 'none'); if( !tracks || tracks.length == 0 || (typeof tracks == "object" && tracks.error_data)) { console.log( 'Could not retrieve data from the feed. Check to ensure the feed is valid.' ); $('.spp-feed-error').css('display', 'block'); return; } rssTracks = tracks; sppTracks = JSON.parse(JSON.stringify(tracks)); // Make a copy // Add each future timestamp (URL and stamps) to the list of tracks _.each(SmartPodcastPlayerAdmin.future_timestamps, function(stamps, url) { // Unless that URL is already in the list if (! _.find(sppTracks, function(track) {return urlCanon(track.stream_url) === url;})) sppTracks.unshift({ 'title': url, 'stream_url': url, 'timestamps': stamps, }); }); constructTrackDropdown(); constructFutureUrlsTable(); }, error: function(e) { $('.spp-loading-feed').css('display', 'none'); $('.spp-feed-error').css('display', 'block'); }, }); } if ($('#spp-timestamps-feed-url').length > 0) { loadFeed(); } $('#spp-reload-feed').click(function(e) { loadFeed(); }); $('.spp-settings-form').submit(function(e) { // Add a hidden input for each row (time=>text) var track = sppTracks[$('#spp-track-picker').val()]; var stream_url = urlCanon(track.stream_url); var times = _.map($('.spp-timestamp-time'), function(t) {return t.value;}) var texts = _.map($('.spp-timestamp-text'), function(t) {return t.value;}) var inputTemplate = _.template(hiddenRowTemplate); for (var i = 0; i < times.length; i++) { $(e.target).append(inputTemplate({ stream_url: stream_url, time: times[i], text: texts[i], })); } return true; }); $('.spp-timestamp-ref').keypress(function(e) { // Reject double quotes if (e.key === '"') e.preventDefault(); }); $('.spp-timestamp-ref').keyup(function(e) { $('.spp-timestamp-shortcode').text('[ftp_timestamps ref="' + e.currentTarget.value + '"]'); disableTrackSelector(); }); $('#spp-timestamps-revert').click(function() { selectTrack(); enableTrackSelector(); }); function deleteFutureUrl(delButton) { var url = $(delButton).closest('tr').find('td.spp-future-url').text() $.ajax( ajaxurl, { type: 'POST', data: { action: 'spp_delete_future_url', url: url, }, success: function(newFutureStamps) { SmartPodcastPlayerAdmin.future_timestamps = newFutureStamps; constructFutureUrlsTable(); // Also remove the item from sppTracks and the dropdown on the "current" tab for (var i = 0; i < sppTracks.length; i++) if (sppTracks[i].stream_url == url) { sppTracks.splice(i, 1); break; } constructTrackDropdown(); }, error: function(e) { console.log("Error while deleting future URL: " + e); }, }); } function constructFutureUrlsTable() { const rowTemplate = '<tr><td class="spp-future-url"><%= url %></td>' + '<td><input type="button" class="button button-secondary spp-delete-future-url" value="Delete">' + '</td></tr>'; var table = $("#spp-future-urls-table"); table.empty(); var r = _.template(rowTemplate); for (var url in SmartPodcastPlayerAdmin.future_timestamps) { if (! _.find(rssTracks, function(track) {return urlCanon(track.stream_url) === url;})) table.append(r({ url: url, })); } $(".spp-delete-future-url").click(function() { deleteFutureUrl(this); }); } constructFutureUrlsTable(); }); define("timestamps-settings", function(){}); if ( typeof jQuery === 'function' ) { define( 'jquery', function ( $ ) { return jQuery; } ); } if (typeof _ === 'function') { define( 'underscore', function () { return _; }); } require(['jquery', 'underscore'], function($, _) { var stpUrlsB, feedUrlsB; $("#spp-submit-migration-urls").click(function() { $('.spp-feed-error').css('display', 'none'); $('.spp-loading-feed').css('display', 'block'); this.disabled = true; $this = this; $.ajax({ url: SmartPodcastPlayerAdmin.ajax_url, dataType: 'json', type: 'POST', async: true, data: { action: 'spp_get_migration_tracks', old_url: $("#spp-old-rss-url").val(), new_url: $("#spp-new-rss-url").val(), }, success: function(matches) { $('.spp-loading-feed').css('display', 'none'); $this.disabled = false; if( !matches || (typeof matches == "object" && matches.error_data)) { console.log( 'Could not retrieve data from the feed. Check to ensure the feed is valid.' ); $('.spp-feed-error').css('display', 'block'); return; } showResultTable(matches); $(".spp-migration-add-results").show(); }, error: function(e) { $this.disabled = false; $('.spp-loading-feed').css('display', 'none'); $('.spp-feed-error').css('display', 'block'); $('.spp-feed-error-url').text($("#spp-old-rss-url").val() + '" or "' + $("#spp-new-rss-url").val()); }, }); }); $("#spp-search-stps").click(function() { this.disabled = true; $this = this; $.ajax({ url: SmartPodcastPlayerAdmin.ajax_url, dataType: 'json', type: 'POST', async: true, data: { action: 'spp_search_stps', }, success: function(stps) { // $('.spp-loading-feed').css('display', 'none'); $this.disabled = false; stpUrlsB = stps; createMatchTableB(); // if( !matches || (typeof matches == "object" && matches.error_data)) { // console.log( 'Could not retrieve data from the feed. Check to ensure the feed is valid.' ); // $('.spp-feed-error').css('display', 'block'); // return; // } // showStps(stps); // $(".spp-migration-add-results").show(); }, error: function(e) { // $this.disabled = false; // $('.spp-loading-feed').css('display', 'none'); // $('.spp-feed-error').css('display', 'block'); // $('.spp-feed-error-url').text($("#spp-old-rss").val() + '" or "' + $("#spp-new-rss").val()); }, }); }); $("#spp-load-feed").click(function() { this.disabled = true; $this = this; $.ajax({ url: SmartPodcastPlayerAdmin.ajax_url, dataType: 'json', type: 'POST', async: true, data: { action: 'get_spplayer_tracks', stream: $('#spp-new-rss-url-B').val(), get_ep_num: true, }, success: function(tracks) { $('.spp-loading-feed-B').css('display', 'none'); $this.disabled = false; feedUrlsB = _.map(tracks, function(el) { return { url: el.stream_url, epnum: el.itunes_episode_number, } }); createMatchTableB(); // if( !matches || (typeof matches == "object" && matches.error_data)) { // console.log( 'Could not retrieve data from the feed. Check to ensure the feed is valid.' ); // $('.spp-feed-error').css('display', 'block'); // return; // } // showStps(stps); $(".spp-migration-add-results").show(); }, error: function(e) { $this.disabled = false; $('.spp-loading-feed-B').css('display', 'none'); $('.spp-feed-error-B').css('display', 'block'); $('.spp-feed-error-url-B').text($("#spp-new-rss-url-B").val()); }, }); }); const resultRowTemplate = '<div class="spp-migration-result-row">' + '<span class="spp-migration-result-header">Title:</span> ' + '<span class="spp-migration-result-item"><%= title %></span><br>' + '<span class="spp-migration-result-header">Old URL:</span> ' + '<span class="spp-migration-result-item"><%= old_url %></span><br>' + '<span class="spp-migration-result-header">New URL:</span> ' + '<span class="spp-migration-result-item"><%= new_url %></span><br>' + '</div>'; function showResultTable(matches) { $('.spp-migration-results').append("<h3>" + matches.length + " matches found.</h3>"); var rowTemplate = _.template(resultRowTemplate); for (var i = 0; i < matches.length; i++) { $('.spp-migration-results').append(rowTemplate({ title: matches[i].title, old_url: matches[i].old_url, new_url: matches[i].new_url, })); } } $("#spp-submit-migration-list").click(function() { $('.spp-submitting-list').show(); this.disabled = true; $this = this; $.ajax({ url: SmartPodcastPlayerAdmin.ajax_url, dataType: 'json', type: 'POST', async: true, data: { action: 'spp_add_migration_tracks', old_url: $("#spp-old-rss-url").val(), new_url: $("#spp-new-rss-url").val(), }, success: function(matches) { $('.spp-submitting-list').hide(); $this.disabled = false; $(".spp-migration-success").show(); updateCurrentReplacementTable(matches); }, error: function(e) { $this.disabled = false; $('.spp-submitting-list').hide(); $('.spp-submit-list-error').show(); }, }); }); const matchHeaderB = '<div class="spp-match-table-header-b">' + '<button type="button" class="spp-results-down">' + '<span class="dashicons dashicons-arrow-down-alt"></span>' + 'Move this list down' + '</button>' + '<button type="button" class="spp-results-up">' + '<span class="dashicons dashicons-arrow-up-alt"></span>' + 'Move this list up' + '</button>' + '</div>'; const stpRowTemplateB = '<div class="spp-stp-row-b" draggable="true">' + '<button type="button" class="spp-remove-button" title="Remove this element, shifting lower ones up">' + '<span class="dashicons dashicons-no">' + '</button>' + '<span class="spp-stp-result-b"><%= url %></span>' + '</div>'; const feedRowTemplateB = '<div class="spp-feed-row-b" draggable="true">' + '<button type="button" class="spp-remove-button" title="Remove this element, shifting lower ones up">' + '<span class="dashicons dashicons-no">' + '</button>' + '<span class="spp-result-b-epnum"><% if (typeof(epnum)!="undefined") {print("[" + epnum + "]");} %></span> ' + '<span class="spp-feed-result-b"><%= url %></span>' + '</div>'; function createMatchTableB() { var stpTable = $('.spp-b-stp-results'); stpTable.empty(); stpTable.append('<h2>On the website</h2>' + matchHeaderB); var stpTemplate = _.template(stpRowTemplateB); var idx = 0; _.each(stpUrlsB, function(el) { var row = $(stpTemplate({url: el})); row.attr('data-idx', idx++); row.on('dragstart', rowDragStart); row.on('dragover', rowDragOver); row.on('dragend', rowDragEnd); stpTable.append(row); }); var feedTable = $('.spp-b-feed-results'); feedTable.empty(); feedTable.append('<h2>From the new feed</h2>' + matchHeaderB); var feedTemplate = _.template(feedRowTemplateB); idx = 0; _.each(feedUrlsB, function(el) { var row = $(feedTemplate({ url: el.url, epnum: el.epnum, })); row.attr('data-idx', idx++); row.on('dragstart', rowDragStart); row.on('dragover', rowDragOver); row.on('dragend', rowDragEnd); feedTable.append(row); }); $('.spp-migration-results-b').find('.spp-remove-button').click(function(e) {removeRowB(e);}); $('.spp-migration-results-b').find('.spp-results-down').click(function(e) {moveDown(e);}); $('.spp-migration-results-b').find('.spp-results-up').click(function(e) {moveUp(e);}); } function removeRowB(e) { var row = $(e.currentTarget).parent(); var idx = row.attr('data-idx'); var nextRow = row.next(); if (row.hasClass("spp-stp-row-b")) { stpUrlsB.splice(idx, 1); } else if (row.hasClass("spp-feed-row-b")) { feedUrlsB.splice(idx, 1); } else { console.log("SPP Error: Malformed document"); return; } row.remove(); while (nextRow.length > 0) { nextRow.attr('data-idx', idx++); nextRow = nextRow.next(); } } function moveDown(e) { var table = $(e.currentTarget).parent().parent(); if (table.hasClass("spp-b-stp-results")) { stpUrlsB.unshift(""); createMatchTableB(); } else if (table.hasClass("spp-b-feed-results")) { feedUrlsB.unshift({url: ""}); createMatchTableB(); } else { console.log("SPP Error: Malformed document"); } } function moveUp(e) { var table = $(e.currentTarget).parent().parent(); if (table.hasClass("spp-b-stp-results")) { if (stpUrlsB.length == 0) { // Do nothing } else if (stpUrlsB[0] == "") { stpUrlsB.shift(); } else { feedUrlsB.unshift({url: ""}); } createMatchTableB(); } else if (table.hasClass("spp-b-feed-results")) { if (feedUrlsB.length == 0) { // Do nothing } else if (feedUrlsB[0].url == "") { feedUrlsB.shift(); } else { stpUrlsB.unshift(""); } createMatchTableB(); } else { console.log("SPP Error: Malformed document"); } } var fromIdx = NaN; var rowClass = ""; var tableClass = ""; function moveRow(fromIdx, toIdx, tableClass, rowClass) { if (fromIdx == toIdx) { return; } // Move the row, and set up for renumbering var table = $(tableClass); var fromRow = table.find(rowClass + '[data-idx="' + fromIdx + '"]'); var toRow = table.find(rowClass + '[data-idx="' + toIdx + '"]'); var thisRow, thisIdx; if (toIdx < fromIdx) { // Moving up fromRow.insertBefore(toRow); thisIdx = toIdx; thisRow = fromRow; } else { // Moving down fromRow.insertAfter(toRow); thisIdx = fromIdx; thisRow = table.find(rowClass + '[data-idx="' + (fromIdx + 1) + '"]'); } // Renumber the indexes var endRow = Math.max(fromIdx, toIdx); if (typeof thisIdx !== "number" || isNaN(thisIdx) || thisIdx > 9999 || endRow > 9999) // Something's wrong return; do { thisRow.attr('data-idx', thisIdx); thisRow = thisRow.next(); } while (thisRow.length > 0 && thisIdx++ < endRow); } function rowDragStart(e) { fromIdx = parseInt(e.target.dataset.idx); if ($(e.target).hasClass('spp-stp-row-b')) { rowClass = ".spp-stp-row-b"; tableClass = ".spp-b-stp-results"; } else if ($(e.target).hasClass('spp-feed-row-b')) { rowClass = ".spp-feed-row-b"; tableClass = ".spp-b-feed-results"; } $(e.currentTarget).css('font-weight', 'bold'); } function rowDragOver(e) { e.preventDefault(); // Make sure we're moving across a row boundary var toIdx = parseInt($(e.target).closest(rowClass).attr('data-idx')); if (rowDragOver.currentToIdx == toIdx) return; rowDragOver.currentToIdx = toIdx; if (fromIdx == toIdx) { return; } moveRow(fromIdx, toIdx, tableClass, rowClass); // The row we're dragging was re-indexed, so reset the "from" index fromIdx = toIdx; } function rowDragEnd(e) { $(e.currentTarget).css('font-weight', 'normal'); } // Split panel in migration results B var isDragging = false; var startX, startW; var fullTable = $('.spp-migration-results-b'); fullTable.mousedown(function(e) { // If it's contained within the splitter if ($(e.target).hasClass('spp-splitter')) { isDragging = true; startX = e.clientX; startW = parseInt($('.spp-b-stp-results').css('width')); } }); fullTable.mousemove(function(e) { if (isDragging) { var w = startW + (e.clientX - startX); $('.spp-b-stp-results').css('width', w + "px"); } }); fullTable.mouseup(function() { isDragging = false; }); $("#spp-submit-migration-list-B").click(function() { $('.spp-submitting-list').show(); this.disabled = true; $this = this; $.ajax({ url: SmartPodcastPlayerAdmin.ajax_url, dataType: 'json', type: 'POST', async: true, data: { action: 'spp_add_migration_tracks_B', stp_urls: stpUrlsB, feed_urls: _.pluck(feedUrlsB, 'url'), }, success: function(matches) { $('.spp-submitting-list').hide(); $this.disabled = false; $(".spp-migration-success").show(); updateCurrentReplacementTable(matches) }, error: function(e) { $this.disabled = false; $('.spp-submitting-list').hide(); $('.spp-submit-list-error').show(); }, }); }); function updateCurrentReplacementTable(replacements) { var table = $('.spp-current-replacements'); replacements.forEach(function(el) { table.append('Replace "' + el.old_url + '"<br>with "' + el.new_url + '"<br><br>'); }); var num = $('#spp-num-replacements'); num.text(parseInt(num.text()) + replacements.length); } var enableButton = $('#spp-enable-remove-all-replacements'); var removeButton = $('#spp-remove-all-replacements'); enableButton.click(function() { // Enable two ways, just in case removeButton.removeAttr('disabled'); removeButton.prop('disabled', false); }); removeButton.click(function() { $this = this; $.ajax({ url: SmartPodcastPlayerAdmin.ajax_url, dataType: 'json', type: 'POST', async: true, data: { action: 'spp_remove_replacements', }, success: function() { location.reload(); }, error: function() { location.reload(); }, }); }); }); define("migration-settings", function(){}); }());
Save Changes
Rename File
Rename