| 1 |
/** |
| 2 |
* String.prototype.includes polyfill. |
| 3 |
* |
| 4 |
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes |
| 5 |
*/ |
| 6 |
if (!String.prototype.includes) { |
| 7 |
String.prototype.includes = function (search, start) { |
| 8 |
'use strict'; |
| 9 |
|
| 10 |
if (search instanceof RegExp) { |
| 11 |
throw TypeError('first argument must not be a RegExp'); |
| 12 |
} |
| 13 |
if (start === undefined) { start = 0; } |
| 14 |
return this.indexOf(search, start) !== -1; |
| 15 |
}; |
| 16 |
} |
| 17 |
|
| 18 |
/** |
| 19 |
* Scripts within customizer control panel. |
| 20 |
* |
| 21 |
* Used global objects: |
| 22 |
* - jQuery |
| 23 |
* - wp |
| 24 |
* - WPAdminifyLoginCustomizer |
| 25 |
*/ |
| 26 |
(function ($) { |
| 27 |
'use strict'; |
| 28 |
|
| 29 |
var events = {}; |
| 30 |
|
| 31 |
wp.customize.bind('ready', function () { |
| 32 |
wpAdminifyListen(); |
| 33 |
$( 'body' ).addClass( 'wp-adminify' ); |
| 34 |
if (!WPAdminifyLoginCustomizer.isProActive) adminifyUpgradeProLink(); |
| 35 |
}); |
| 36 |
|
| 37 |
|
| 38 |
function wpAdminifyListen() { |
| 39 |
events.switchLoginPreview(); |
| 40 |
events.switchFormPreview(); |
| 41 |
events.focusSection(); |
| 42 |
events.focusSection(); |
| 43 |
if (!WPAdminifyLoginCustomizer.isProActive) events.templateFieldsChange(); |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
events.focusSection = function(){ |
| 49 |
wp.customize.previewer.bind( 'wp-adminify-focus-section', function ( sectionName ) { |
| 50 |
var section = wp.customize.section( sectionName ); |
| 51 |
|
| 52 |
if ( undefined !== section ) { |
| 53 |
section.focus(); |
| 54 |
} |
| 55 |
} ); |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
events.switchFormPreview = function(){ |
| 60 |
|
| 61 |
|
| 62 |
wp.customize.section( 'wp_adminify_register-form', function ( section ) { |
| 63 |
section.expanded.bind( function ( isExpanding ) { |
| 64 |
// Value of isExpanding will = true if you're entering the section, false if you're leaving it. |
| 65 |
if ( isExpanding ) { |
| 66 |
wp.customize.previewer.send( 'change-form', 'register' ); |
| 67 |
} else { |
| 68 |
wp.customize.previewer.send( 'change-form', 'login' ); |
| 69 |
} |
| 70 |
} ); |
| 71 |
} ); |
| 72 |
|
| 73 |
|
| 74 |
wp.customize.section( 'wp_adminify_lostpassword-form', function ( section ) { |
| 75 |
section.expanded.bind( function ( isExpanding ) { |
| 76 |
// Value of isExpanding will = true if you're entering the section, false if you're leaving it. |
| 77 |
if ( isExpanding ) { |
| 78 |
wp.customize.previewer.send( 'change-form', 'lostpassword' ); |
| 79 |
} else { |
| 80 |
wp.customize.previewer.send( 'change-form', 'login' ); |
| 81 |
} |
| 82 |
} ); |
| 83 |
} ); |
| 84 |
|
| 85 |
} |
| 86 |
/** |
| 87 |
* Change the page when the "WP Adminify Login Customizer" panel is expanded (or collapsed). |
| 88 |
*/ |
| 89 |
events.switchLoginPreview = function () { |
| 90 |
wp.customize.panel( 'jltwp_adminify_panel', function ( section ) { |
| 91 |
section.expanded.bind( function ( isExpanding ) { |
| 92 |
var loginURL = WPAdminifyLoginCustomizer.siteurl + '?wp-adminify-login-customizer=true'; |
| 93 |
// Value of isExpanding will = true if you're entering the section, false if you're leaving it. |
| 94 |
if ( isExpanding ) { |
| 95 |
wp.customize.previewer.previewUrl.set( loginURL ); |
| 96 |
} else { |
| 97 |
wp.customize.previewer.previewUrl.set( WPAdminifyLoginCustomizer.siteurl ); |
| 98 |
} |
| 99 |
} ); |
| 100 |
} ); |
| 101 |
} |
| 102 |
|
| 103 |
events.templateFieldsChange = function () { |
| 104 |
wp.customize.section('jltwp_adminify_customizer_template_section', function (section) { |
| 105 |
section.expanded.bind(function (isExpanded) { |
| 106 |
if (isExpanded) { |
| 107 |
var figur_input = $('#customize-control-jltwp_adminify_login-templates .adminify--image-group .adminify--image figure input'); |
| 108 |
|
| 109 |
for (let index = 0; index < figur_input.length; index++) { |
| 110 |
var element = figur_input[index]; |
| 111 |
var val = element.value; |
| 112 |
// console.log('element', element.value); |
| 113 |
var hasDivAlready = element.parentNode.querySelector('.wp-adminify-templates-pro'); |
| 114 |
|
| 115 |
if(val === 'template-01' || val === 'template-02' || val === 'template-03' || val === 'template-04') { |
| 116 |
continue; |
| 117 |
} |
| 118 |
|
| 119 |
if(hasDivAlready !== null){ |
| 120 |
continue; |
| 121 |
} |
| 122 |
|
| 123 |
var _div = document.createElement('div'); |
| 124 |
var _a = document.createElement('a'); |
| 125 |
_div.classList = 'wp-adminify-templates-pro'; |
| 126 |
_a.setAttribute('href', 'https://wpadminify.com/login-customizer/?utm_source=plugin&utm_medium=login_customizer_link&utm_campaign=wp_adminify') |
| 127 |
_a.setAttribute('target', '_blank'); |
| 128 |
_a.innerHTML = 'Upgrade to Pro'; |
| 129 |
|
| 130 |
_div.appendChild(_a); |
| 131 |
element.parentNode.appendChild(_div); |
| 132 |
|
| 133 |
|
| 134 |
} |
| 135 |
// figur_input.forEach(element => { |
| 136 |
// console.log('figur_input_val', element.val()); |
| 137 |
// }); |
| 138 |
|
| 139 |
|
| 140 |
// var value = wp.customize('jltwp_adminify_login[templates]').get(); |
| 141 |
// console.log('value', value); |
| 142 |
// if (value !== 'template-01' ) { |
| 143 |
// $('<div class="wp-adminify-templates-pro"><a href="https://wpadminify.com/login-customizer/?utm_source=plugin&utm_medium=login_customizer_link&utm_campaign=wp_adminify" target="_blank">Upgrade to Pro</a></div>').appendTo('#customize-control-jltwp_adminify_login-templates .adminify--image-group .adminify--image figure'); |
| 144 |
// } |
| 145 |
// $("#customize-control-jltwp_adminify_login-templates .adminify--image-group .adminify--image").insertAt(0, "<li>as fasd fads fsd</li>"); |
| 146 |
// $('<li>fgdf</li>').appendToWithIndex($("#customize-control-jltwp_adminify_login-templates .adminify--image-group .adminify--image > figure"),0) |
| 147 |
} |
| 148 |
}) |
| 149 |
}); |
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
$.fn.appendToWithIndex=function(to,index){ |
| 154 |
// console.log('firesd'); |
| 155 |
// var lastIndex = this.children().size(); |
| 156 |
// if (index < 0) { |
| 157 |
// index = Math.max(0, lastIndex + 1 + index); |
| 158 |
// } |
| 159 |
// this.append(element); |
| 160 |
// if (index < lastIndex) { |
| 161 |
// this.children().eq(index).before(this.children().last()); |
| 162 |
// } |
| 163 |
// return this; |
| 164 |
if(! to instanceof jQuery){ |
| 165 |
to=$(to); |
| 166 |
}; |
| 167 |
if(index===0){ |
| 168 |
$(this).prependTo(to) |
| 169 |
}else{ |
| 170 |
$(this).insertAfter(to.children().eq(index-1)); |
| 171 |
} |
| 172 |
} |
| 173 |
|
| 174 |
|
| 175 |
function adminifyUpgradeProLink() { |
| 176 |
|
| 177 |
var proLink = '\ |
| 178 |
<li class="accordion-section control-section wp-adminify-pro-control-section">\ |
| 179 |
<a \ |
| 180 |
href="https://wpadminify.com/login-customizer/?utm_source=plugin&utm_medium=login_customizer_link&utm_campaign=wp_adminify" \ |
| 181 |
style="display: block; font-weight: 600; color: #fff !important; font-size: 16px; text-decoration: none; border-left-color: #0347FF; background: #0347FF;"\ |
| 182 |
class="accordion-section-title" target="_blank" tabindex="0">\ |
| 183 |
Upgrade to Pro ›\ |
| 184 |
</a>\ |
| 185 |
</li>\ |
| 186 |
'; |
| 187 |
|
| 188 |
$(proLink).insertBefore('#accordion-section-jltwp_adminify_customizer_template_section'); |
| 189 |
} |
| 190 |
|
| 191 |
})(jQuery, wp.customize); |
| 192 |
|