PATH:
home
/
lab2454c
/
foreclass.com
/
wp-content
/
plugins
/
search-replace-for-elementor
/
assets
/
dev
/
js
var ELEMSNR = ELEMSNR || {}; var $ = jQuery || {}; ELEMSNR.pluginURL = elemsnr.plugin_url; ELEMSNR.ajaxURL = elemsnr.ajax_url; ELEMSNR.ajaxNonce = elemsnr.ajax_nonce; ELEMSNR.highlightColor = '#dc00af'; /** * Add nav menu item under Menu > Navigate from Page. */ ELEMSNR.addNavMenu = function( event ) { var $panelPage = $( '#elementor-panel-page-menu' ); if ( $panelPage.length ) { var $finderCont = $( '.elementor-panel-menu-item-finder' ); if ( $finderCont.length ) { var $searchReplaceCont = $( '<div/>' ) .addClass( 'elementor-panel-menu-item elementor-panel-menu-item-search-and-replace' ); $searchReplaceCont.html( ` <div class="elementor-panel-menu-item-icon"><i class="eicon-search-results"></i></div> <div class="elementor-panel-menu-item-title">Search & Replace</div> ` ); $finderCont.after( $searchReplaceCont ); } } }; /** * Open, build, and display plugin modal window. */ ELEMSNR.openSearchReplaceModal = function( event ) { var $searchReplaceModalCont = $( '<div/>' ) .addClass( 'elemsnr-search-replace' ) .prop( 'id', 'elemsnr-search-replace' ); $searchReplaceModalCont.html( ` <div class="elemsnr-modal" id="elemsnr-modal"> <div class="elemsnr-modal-body"> <div class="elemsnr-modal-header"> <div class="elemsnr-modal-logo"> <i class="eicon-search-results"></i> <span class="elemsnr-modal-title">Search & Replace</span> </div> <div class="elemsnr-modal-icons"> <div id="elemsnr-modal-help" class="elemsnr-modal-help"> <i class="eicon-help" aria-hidden="true"></i> </div> <div id="elemsnr-modal-close" class="elemsnr-modal-close"> <i class="eicon-close" aria-hidden="true"></i> </div> </div> <div class="elemsnr-modal-loading-bar"></div> </div> <div class="elemsnr-modal-content"> <div id="elemsnr-output"></div> <div class="elemsnr-row elemsnr-row-html-regexp"> <div class="elemsnr-col" data-tooltip="Search and replace HTML in the Text Editor widget with regular expressions (experts only)."> <label for="elemsnr-html-regexp"> <input type="checkbox" id="elemsnr-html-regexp" name="elemsnr-html-regexp" autocomplete="off" /> <span> HTML with RegEx (experts only) <i class="eicon-help" aria-hidden="true"></i> </span> </label> </div> </div> <label for="elemsnr-search-phrase"> <i class="eicon-search"></i> <input type="text" id="elemsnr-search-phrase" name="elemsnr-search-phrase" placeholder="Enter your search phrase (no HTML allowed)..." autocomplete="off" /> <div class="elemsnr-modal-button-group"> <button type="submit" name="elemsnr-search-button" class="elemsnr-button" /> Search </button> </div> </label> <label for="elemsnr-replace-with-phrase"> <i class="eicon-site-search"></i> <input type="text" id="elemsnr-replace-with-phrase" name="elemsnr-replace-with-phrase" placeholder="Enter your replace with phrase (no HTML allowed)..." autocomplete="off" /> </label> <div class="elemsnr-row elemsnr-row-options"> <div class="elemsnr-col"> <label for="elemsnr-text-only"> <div> <input type="radio" id="elemsnr-text-only" name="elemsnr-text-and-link" autocomplete="off" checked /> <span>Text-only</span> </div> </label> <label for="elemsnr-links"> <div> <input type="radio" id="elemsnr-links" name="elemsnr-text-and-link" autocomplete="off" disabled="disabled" /> <span class="pro-only">Links (URLs)</span> </div> </label> <label for="elemsnr-images"> <div> <input type="radio" id="elemsnr-images" name="elemsnr-text-and-link" autocomplete="off" disabled="disabled" /> <span class="pro-only">Images</span> </div> </label> </div> <div class="elemsnr-col"> <label for="elemsnr-highlight"> <div> <input type="checkbox" id="elemsnr-highlight" name="elemsnr-highlight" autocomplete="off" /> <span>Highlight text on search</span> </div> </label> <label for="elemsnr-case-sensitive"> <div> <input type="checkbox" id="elemsnr-case-sensitive" name="elemsnr-case-sensitive" autocomplete="off" disabled="disabled" /> <span class="pro-only">Case-sensitive search and replace</span> </div> </label> </div> </div> <button type="submit" name="elemsnr-html-regexp-button" class="elemsnr-button" /> Search & Replace </button> <div class="elemsnr-modal-button-group"> <button type="submit" name="elemsnr-replace-button" class="elemsnr-button" /> Replace </button> <button type="reset" name="elemsnr-clear-button" class="elemsnr-button"> Clear </button> </div> <p class="pro-note"><sup>*</sup> Get Search & Replace for Elementor <span class="pro-only"></span> to unlock the plugin, be able to use on pages with data larger than <em>50kb</em> in size and run the HTML with regular expressions feature with maximum requests.</p> </div> </div> </div> ` ); $( '#elemsnr-search-replace' ).remove(); $( 'body' ).append( $searchReplaceModalCont ); $( '#elemsnr-modal' ).draggable(); }; /** * Close plugin modal window. */ ELEMSNR.closeSearchReplaceModal = function( event ) { event.preventDefault(); $( '#elemsnr-search-replace' ).remove(); }; /** * Highlight existing custom tags on load. */ ELEMSNR.highlightTermsOnLoad = function() { var $modal = $( '.elemsnr-modal' ); // Inject highlight style in the iframe only if option is checked. if ( $modal.length && $modal.find( 'input[name="elemsnr-highlight"]:checked' ).length ) { elementor.reloadPreview(); elementor.once( 'preview:loaded', function () { // Add custom tag style in the preview window head. elementor.$preview.contents() .find( 'head' ) .append( $( '<style/>' ) .prop( 'id', 'elemsnr' ) .html( `elsnr-highlight { background-color: ${ELEMSNR.highlightColor}; padding: 3px; }` ) ); } ); } }; /** * Highlight all search terms and reload Elementor window. */ ELEMSNR.highlightTerms = function( event, undo = false ) { event.preventDefault(); var $elem = $( event.target ); var $modal = $elem.closest( '.elemsnr-modal' ); var url = new URL( document.location.href ); var searchPhrase = $modal.find( 'input[name="elemsnr-search-phrase"]' ).val(); // In case the user click UNDO link invert the 'search' and 'replace' text. if ( true === undo ) { var searchPhrase = $modal.find( '#elemsnr-undo-replace-with-phrase' ).text(); } // Delay & get the last typed letter. setTimeout( function() { $.ajax( { method: 'post', url: ELEMSNR.ajaxURL, data: { action: 'elemsnr_highlight_search', security: ELEMSNR.ajaxNonce, current_post_id: url.searchParams.get( 'post' ), search_phrase: searchPhrase, replace_with_phrase: $modal.find( 'input[name="elemsnr-replace-with-phrase"]' ).val(), is_highlighted: $modal.find( 'input[name="elemsnr-highlight"]:checked' ).length, is_text_only: $modal.find( 'input[id="elemsnr-text-only"]:checked' ).length, }, beforeSend: function () { $modal.find( '.elemsnr-modal-loading-bar' ).show(); }, success: function ( response ) { if ( undefined !== response.success && false === response.success ) { return; } // console.log( response ); return; // debug (dev-only) response = JSON.parse( response )[0]; if ( 1 === response.status && false === undo ) { ELEMSNR.reloadElementorEditor( $modal, response.message ); } else { $( '#elemsnr-output' ).addClass( 'elemsnr-output-active' ); $( '#elemsnr-output' ).empty().html( response.message ); } }, complete: function() { $modal.find( '.elemsnr-modal-loading-bar' ).hide(); } } ); }, 500 ); }; /** * UnHighlight and clear all search terms and reload Elementor window. */ ELEMSNR.unHiglightTerms = function( event ) { event.preventDefault(); var $elem = $( event.target ); var $modal = $elem.closest( '.elemsnr-modal' ); var url = new URL( document.location.href ); $.ajax( { method: 'post', url: ELEMSNR.ajaxURL, data: { action: 'elemsnr_unhighlight_search', security: ELEMSNR.ajaxNonce, current_post_id: url.searchParams.get( 'post' ), search_phrase: $modal.find( 'input[name="elemsnr-search-phrase"]' ).val(), replace_with_phrase: $modal.find( 'input[name="elemsnr-replace-with-phrase"]' ).val(), is_highlighted: $modal.find( 'input[name="elemsnr-highlight"]:checked' ).length, is_text_only: $modal.find( 'input[id="elemsnr-text-only"]:checked' ).length, }, beforeSend: function () { $modal.find( '.elemsnr-modal-loading-bar' ).show(); }, success: function ( response ) { if ( undefined !== response.success && false === response.success ) { return; } // console.log( response ); return; // debug debug (dev-only) response = JSON.parse( response )[0]; // Clear search and replace input values. $modal.find( 'input[name="elemsnr-search-phrase"]' ).val( '' ); $modal.find( 'input[name="elemsnr-replace-with-phrase"]' ).val( '' ); if ( 1 === response.status ) { ELEMSNR.reloadElementorEditor( $modal, response.message ); } else { $( '#elemsnr-output' ).addClass( 'elemsnr-output-active' ); $( '#elemsnr-output' ).empty().html( response.message ); } }, complete: function() { $modal.find( '.elemsnr-modal-loading-bar' ).hide(); } } ); }; /** * Replace all the searched and found terms. */ ELEMSNR.replaceTerms = function( event, undo = false ) { event.preventDefault(); var $elem = $( event.target ); var $modal = $elem.closest( '.elemsnr-modal' ); var url = new URL( document.location.href ); var searchPhrase = $modal.find( 'input[name="elemsnr-search-phrase"]' ).val(); var replaceWithPhrase = $modal.find( 'input[name="elemsnr-replace-with-phrase"]' ).val(); // In case the user click UNDO link invert the 'search' and 'replace' text. if ( true === undo ) { var searchPhrase = $modal.find( '#elemsnr-undo-replace-with-phrase' ).text(); var replaceWithPhrase = $modal.find( '#elemsnr-undo-search-phrase' ).text(); } // Delay & get the last typed letter. setTimeout( function() { $.ajax( { method: 'post', url: ELEMSNR.ajaxURL, data: { action: 'elemsnr_replace_search', security: ELEMSNR.ajaxNonce, current_post_id: url.searchParams.get( 'post' ), search_phrase: searchPhrase, replace_with_phrase: replaceWithPhrase, is_highlighted: $modal.find( 'input[name="elemsnr-highlight"]:checked' ).length, is_text_only: $modal.find( 'input[id="elemsnr-text-only"]:checked' ).length, }, beforeSend: function () { $modal.find( '.elemsnr-modal-loading-bar' ).show(); }, success: function ( response ) { if ( undefined !== response.success && false === response.success ) { return; } // console.log( response ); return; // debug debug (dev-only) response = JSON.parse( response )[0]; // Clear search and replace input values. $modal.find( 'input[name="elemsnr-search-phrase"]' ).val( '' ); $modal.find( 'input[name="elemsnr-replace-with-phrase"]' ).val( '' ); if ( 1 === response.status ) { ELEMSNR.reloadElementorEditor( $modal, response.message ); } else { $( '#elemsnr-output' ).addClass( 'elemsnr-output-active' ); $( '#elemsnr-output' ).empty().html( response.message ); } }, complete: function() { $modal.find( '.elemsnr-modal-loading-bar' ).hide(); } } ); }, 500 ); }; /** * Reload Elementor editor with sessionStorage to pass modal values. */ ELEMSNR.reloadElementorEditor = function( $modal, message ) { var elemsnr = { search_phrase: $modal.find( 'input[name="elemsnr-search-phrase"]' ).val(), replace_with_phrase: $modal.find( 'input[name="elemsnr-replace-with-phrase"]' ).val(), is_highlighted: $modal.find( 'input[name="elemsnr-highlight"]:checked' ).length, show_is_highlighted: $modal.find( 'label[for="elemsnr-highlight"]' ).css( 'display' ), is_text_only: $modal.find( 'input[id="elemsnr-text-only"]:checked' ).length, response_message: message, } sessionStorage.setItem( 'elemsnr', JSON.stringify( elemsnr ) ); window.location.reload( true ); }; /** * Populate searcha and replace modal with values after window.reload() */ ELEMSNR.reloadSearchReplaceModal = function() { var elemsnr = JSON.parse( sessionStorage.getItem( 'elemsnr' ) ); if ( null === elemsnr ) { return; } ELEMSNR.openSearchReplaceModal(); var $modal = $( '.elemsnr-modal' ); if ( $modal.length ) { $modal.find( 'input[name="elemsnr-search-phrase"]' ).val( elemsnr.search_phrase ); $modal.find( 'input[name="elemsnr-replace-with-phrase"]' ).val( elemsnr.replace_with_phrase ); $modal.find( 'input[name="elemsnr-highlight"]' ).prop( 'checked', elemsnr.is_highlighted ); $modal.find( 'input[id="elemsnr-text-only"]' ).prop( 'checked', elemsnr.is_text_only ); $modal.find( 'label[for="elemsnr-highlight"]' ).css( 'display', elemsnr.show_is_highlighted ); $( '#elemsnr-output' ).addClass( 'elemsnr-output-active' ); $( '#elemsnr-output' ).empty().html( elemsnr.response_message ); // Inject highlight style in the iframe only if option is checked. if ( $modal.find( 'input[name="elemsnr-highlight"]:checked' ).length ) { elementor.reloadPreview(); elementor.once( 'preview:loaded', function () { // Add custom tag style in the preview window head. elementor.$preview.contents() .find( 'head' ) .append( $( '<style/>' ) .prop( 'id', 'elemsnr' ) .html( `elsnr-highlight { background-color: ${ELEMSNR.highlightColor}; padding: 3px; }` ) ); } ); } sessionStorage.removeItem( 'elemsnr' ); } }; /** * Toggle view when user want to run HTML RegEx. */ ELEMSNR.toggleHTMLRegEx = function( event ) { var $elem = $( event.target ); var $modal = $elem.closest( '.elemsnr-modal' ); if ( $elem.prop( 'checked' ) ) { $modal.find( 'input[name="elemsnr-search-phrase"]' ) .prop( { 'type' : 'text', 'placeholder' : 'Enter your regular expression...', 'readonly': false, 'class': '', } ); $modal.find( 'input[name="elemsnr-replace-with-phrase"]' ) .prop( { 'type' : 'text', 'placeholder' : 'Enter your replace with phrase or HTML...', 'readonly': false, 'class': '', } ); $modal.find( '.elemsnr-row-options input') .prop( 'disabled', true ); $modal.find( '.elemsnr-row-options label[for*="elemsnr-"]' ).hide(); $modal.find( 'button[name="elemsnr-search-button"]' ).hide(); $modal.find( '.elemsnr-modal-button-group' ).hide(); $modal.find( 'button[name="elemsnr-html-regexp-button"]' ).show(); $modal.find( '#elemsnr-output' ) .addClass( 'elemsnr-output-active' ) .html( ` <strong>Important:</strong> It is strongly recommended to <a href="/wp-admin/admin.php?page=elemsnr-backup" target="_blank">backup your database</a> before you run the search and replace. Learn how to use regular expressions at <a href="https://www.regular-expressions.info/" target="_blank">Regular Expressions</a>. ` ); } else { $modal.find( 'input[name="elemsnr-search-phrase"]' ) .prop( { 'type' : 'text', 'placeholder' : 'Enter your search phrase...(no HTML allowed)', 'readonly': false, 'class': '', } ); $modal.find( 'input[name="elemsnr-replace-with-phrase"]' ) .prop( { 'type' : 'text', 'placeholder' : 'Enter your replace with phrase...(no HTML allowed)', 'readonly': false, 'class': '', } ); $modal.find( '.elemsnr-row-options input') .prop( 'disabled', false ); $modal.find( 'input#elemsnr-text-only') .prop( 'checked', true ); $modal.find( '.elemsnr-row-options label[for*="elemsnr-"]' ).show(); $modal.find( 'button[name="elemsnr-search-button"]' ).show(); $modal.find( '.elemsnr-modal-button-group' ).show(); $modal.find( 'button[name="elemsnr-html-regexp-button"]' ).hide(); $modal.find( '#elemsnr-output' ) .removeClass( 'elemsnr-output-active' ) .empty(); } }; /** * Run HTML regular expression search and replace. */ ELEMSNR.replaceHTMLRegEx = function( event ) { event.preventDefault(); var $elem = $( event.target ); var $modal = $elem.closest( '.elemsnr-modal' ); var url = new URL( document.location.href ); var searchPhrase = $modal.find( 'input[name="elemsnr-search-phrase"]' ).val(); var replaceWithPhrase = $modal.find( 'input[name="elemsnr-replace-with-phrase"]' ).val(); // Delay & get the last typed letter. setTimeout( function() { $.ajax( { method: 'post', url: ELEMSNR.ajaxURL, data: { action: 'elemsnr_replace_html_regex', security: ELEMSNR.ajaxNonce, current_post_id: url.searchParams.get( 'post' ), search_phrase: searchPhrase, replace_with_phrase: replaceWithPhrase, }, beforeSend: function () { $modal.find( '.elemsnr-modal-loading-bar' ).show(); }, success: function ( response ) { if ( undefined !== response.success && false === response.success ) { return; } // console.log( response ); return; // debug debug (dev-only) response = JSON.parse( response )[0]; // Clear search and replace input values. $modal.find( 'input[name="elemsnr-search-phrase"]' ).val( '' ); $modal.find( 'input[name="elemsnr-replace-with-phrase"]' ).val( '' ); if ( 1 === response.status ) { ELEMSNR.reloadElementorEditor( $modal, response.message ); } else { $( '#elemsnr-output' ).addClass( 'elemsnr-output-active' ); $( '#elemsnr-output' ).empty().html( response.message ); } }, complete: function() { $modal.find( '.elemsnr-modal-loading-bar' ).hide(); } } ); }, 500 ); }; /** * Actions. */ ;( function ( $, _ ) { ELEMSNR.highlightTermsOnLoad(); ELEMSNR.reloadSearchReplaceModal(); $( document ).on( 'click', '#elementor-panel-header-menu-button', ELEMSNR.addNavMenu ); $( document ).on( 'click', '.elementor-panel-menu-item-search-and-replace', ELEMSNR.openSearchReplaceModal ); $( document ).on( 'click', '#elemsnr-modal-close', ELEMSNR.closeSearchReplaceModal ); $( document ).on( 'click', 'input[name="elemsnr-html-regexp"]', ELEMSNR.toggleHTMLRegEx ); $( document ).on( 'click', 'button[name="elemsnr-search-button"]', ELEMSNR.highlightTerms ); $( document ).on( 'click', 'button[name="elemsnr-clear-button"]', ELEMSNR.unHiglightTerms ); $( document ).on( 'click', 'button[name="elemsnr-replace-button"]', ELEMSNR.replaceTerms ); $( document ).on( 'click', 'button[name="elemsnr-html-regexp-button"]', ELEMSNR.replaceHTMLRegEx ); $( document ).on( 'click', 'a[name="elemsnr-undo-button"]', function( event ) { event.preventDefault(); ELEMSNR.highlightTerms( event, true ); setTimeout( function() { ELEMSNR.replaceTerms( event, true ); }, 500 ); } ); } )( jQuery );
[-] elemsnr-admin.js
[edit]
[+]
..
[-] elemsnr-search-replace.js
[edit]