| 1 |
'use strict'; |
| 2 |
|
| 3 |
(function($) { |
| 4 |
|
| 5 |
// Submit Form for save |
| 6 |
$('#wow-plugin').on('submit', function(event) { |
| 7 |
event.preventDefault(); |
| 8 |
get_tinymce_content(); |
| 9 |
const dataform = $(this).serialize(); |
| 10 |
let prefix = $('#prefix').val(); |
| 11 |
let data = 'action=' + prefix + '_item_save&' + dataform; |
| 12 |
$('.wow-plugin .saving').animate({opacity: '0.75'}); |
| 13 |
$.post(ajaxurl, data, function(response) { |
| 14 |
if (response.status == 'OK') { |
| 15 |
$('#wow-message').addClass('notice notice-success is-dismissible'); |
| 16 |
$('#wow-message').html('<p>' + response.message + '</p>'); |
| 17 |
$('#add_action').val(2); |
| 18 |
let tool_id = $('#tool_id').val(); |
| 19 |
$('.nav-tab.nav-tab-active').text('Update #' + tool_id); |
| 20 |
} |
| 21 |
$('.wow-plugin .saving').animate({opacity: '0'}); |
| 22 |
}); |
| 23 |
}); |
| 24 |
|
| 25 |
// Get Tinymce contetn |
| 26 |
function get_tinymce_content() { |
| 27 |
if ($('#wp-popupcontent-wrap').hasClass('tmce-active')) { |
| 28 |
let content = tinyMCE.activeEditor.getContent(); |
| 29 |
$('#popupcontent').val(content); |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
// Tabs |
| 34 |
$('#tab li').on('click', function() { |
| 35 |
const selected = $(this).data('tab'); |
| 36 |
$('#tab li').removeClass('is-active'); |
| 37 |
$(this).addClass('is-active'); |
| 38 |
$('.tab-content').addClass('is-hidden'); |
| 39 |
$('[data-content="' + selected + '"]').removeClass('is-hidden'); |
| 40 |
}); |
| 41 |
|
| 42 |
// Tooltip |
| 43 |
wow_attach_tooltips($('.wow-help')); |
| 44 |
|
| 45 |
function wow_attach_tooltips(selector) { |
| 46 |
selector.tooltip({ |
| 47 |
content: function() { |
| 48 |
return $(this).prop('title'); |
| 49 |
}, |
| 50 |
tooltipClass: 'wow-ui-tooltip', |
| 51 |
position: { |
| 52 |
my: 'center top', |
| 53 |
at: 'center bottom+10', |
| 54 |
collision: 'flipfit', |
| 55 |
}, |
| 56 |
hide: { |
| 57 |
duration: 200, |
| 58 |
}, |
| 59 |
show: { |
| 60 |
duration: 200, |
| 61 |
}, |
| 62 |
}); |
| 63 |
} |
| 64 |
|
| 65 |
// CheckLabel |
| 66 |
|
| 67 |
$('.checkLabel').each(function() { |
| 68 |
checkLabel(this); |
| 69 |
}).on('click', function() { |
| 70 |
checkLabel(this); |
| 71 |
}); |
| 72 |
|
| 73 |
function checkLabel(el) { |
| 74 |
const check = $(el).find('input'); |
| 75 |
if (check.prop('checked')) { |
| 76 |
$(el).parent().find('.field').removeClass('is-hidden'); |
| 77 |
} else { |
| 78 |
$(el).parent().find('.field').addClass('is-hidden'); |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
// CheckBLock |
| 83 |
$('.checkBlock').each(function() { |
| 84 |
checkBlock(this); |
| 85 |
}).on('click', function() { |
| 86 |
checkBlock(this); |
| 87 |
}); |
| 88 |
|
| 89 |
function checkBlock(el) { |
| 90 |
const check = $(el).find('input'); |
| 91 |
if (check.prop('checked')) { |
| 92 |
$(el).closest('.columns').children('.blockHidden').removeClass('is-hidden'); |
| 93 |
} else { |
| 94 |
$(el).closest('.columns').children('.blockHidden').addClass('is-hidden'); |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
// Check enable tooltip |
| 99 |
$('.checkTooltip').each(function() { |
| 100 |
checkTooltip(this); |
| 101 |
}).on('click', function() { |
| 102 |
checkTooltip(this); |
| 103 |
}); |
| 104 |
|
| 105 |
$('body').on('click', '.checkTooltip', function() { |
| 106 |
checkTooltip(this); |
| 107 |
; |
| 108 |
}); |
| 109 |
|
| 110 |
function checkTooltip(el) { |
| 111 |
const check = $(el).find('input'); |
| 112 |
if (check.prop('checked')) { |
| 113 |
$(el).closest('.toogle-content').children('.blockHidden').removeClass('is-hidden'); |
| 114 |
} else { |
| 115 |
$(el).closest('.toogle-content').children('.blockHidden').addClass('is-hidden'); |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
// Publish |
| 120 |
publish(); |
| 121 |
$('#show').on('change', publish); |
| 122 |
|
| 123 |
function publish() { |
| 124 |
const type = $('#show').val(); |
| 125 |
$('#taxonomy, #id-post, #shortcode').hide(); |
| 126 |
switch (type) { |
| 127 |
case 'shortecode': |
| 128 |
$('#shortcode').fadeIn(); |
| 129 |
break; |
| 130 |
case 'taxonomy': |
| 131 |
$('#taxonomy, #id-post').fadeIn(); |
| 132 |
break; |
| 133 |
case 'posts': |
| 134 |
case 'pages': |
| 135 |
case 'expost': |
| 136 |
case 'expage': |
| 137 |
case 'postsincat': |
| 138 |
$('#id-post').fadeIn(); |
| 139 |
break; |
| 140 |
default: |
| 141 |
$('#taxonomy, #id-post, #shortcode').hide(); |
| 142 |
break; |
| 143 |
} |
| 144 |
} |
| 145 |
|
| 146 |
// Set value in input hidden for checkbox |
| 147 |
$('.wow-plugin input:checkbox:checked').each(function() { |
| 148 |
$(this).siblings('input[type="hidden"]').val('1'); |
| 149 |
}); |
| 150 |
|
| 151 |
$('body').on('click', '.wow-plugin input:checkbox', function() { |
| 152 |
checkboxchecked(this); |
| 153 |
}); |
| 154 |
|
| 155 |
function checkboxchecked(el) { |
| 156 |
if ($(el).prop('checked')) { |
| 157 |
$(el).siblings('input[type="hidden"]').val('1'); |
| 158 |
} else { |
| 159 |
$(el).siblings('input[type="hidden"]').val('0'); |
| 160 |
} |
| 161 |
} |
| 162 |
|
| 163 |
// Change user role |
| 164 |
usersroles(); |
| 165 |
$('#item_user').on('change', function() { |
| 166 |
usersroles(); |
| 167 |
}); |
| 168 |
|
| 169 |
function usersroles() { |
| 170 |
const type = $('#item_user').val(); |
| 171 |
$('.item-user').fadeOut('200'); |
| 172 |
if (type == '2') { |
| 173 |
$('.item-user').fadeIn('200'); |
| 174 |
} |
| 175 |
} |
| 176 |
|
| 177 |
// Select Item type |
| 178 |
$('select.item-type').each(function() { |
| 179 |
itemtype(this); |
| 180 |
}); |
| 181 |
|
| 182 |
$('body').on('change', '.item-type', function() { |
| 183 |
itemtype(this); |
| 184 |
}); |
| 185 |
|
| 186 |
function itemtype(el) { |
| 187 |
const type = $(el).val(); |
| 188 |
const typeText = $(el).find('option:selected').text(); |
| 189 |
const parent = $(el).parents('.tabs-content'); |
| 190 |
const itemLink = $(parent).find('.item-link'); |
| 191 |
const itemShare = $(parent).find('.item-share'); |
| 192 |
const itemTranslate = $(parent).find('.item-translate'); |
| 193 |
const itemLinkBlank = $(parent).find('.item-link-blank'); |
| 194 |
const itemModal = $(parent).find('.item-type-menu'); |
| 195 |
const itemText = $(parent).find('.item-link-text'); |
| 196 |
const btnsOpen = $(parent).find('.item-hold-btns-open'); |
| 197 |
$(el).parents('.panel').find('.element-type').text(typeText); |
| 198 |
$(itemLink).hide(); |
| 199 |
$(itemShare).hide(); |
| 200 |
$(itemTranslate).hide(); |
| 201 |
$(itemLinkBlank).hide(); |
| 202 |
$(itemModal).hide(); |
| 203 |
$(btnsOpen).hide(); |
| 204 |
switch (type) { |
| 205 |
case 'link': |
| 206 |
case 'smoothscroll': |
| 207 |
case 'email': |
| 208 |
case 'telephone': |
| 209 |
case 'login': |
| 210 |
case 'logout': |
| 211 |
case 'lostpassword': |
| 212 |
$(itemLink).show(); |
| 213 |
break; |
| 214 |
case 'share': |
| 215 |
$(itemShare).show(); |
| 216 |
break; |
| 217 |
case 'menu': |
| 218 |
$(itemModal).show(); |
| 219 |
break; |
| 220 |
case 'main': |
| 221 |
$(btnsOpen).show(); |
| 222 |
break; |
| 223 |
case 'translate': |
| 224 |
$(itemTranslate).show(); |
| 225 |
break; |
| 226 |
} |
| 227 |
|
| 228 |
switch (type) { |
| 229 |
case 'link': |
| 230 |
case 'smoothscroll': |
| 231 |
case 'login': |
| 232 |
case 'logout': |
| 233 |
case 'lostpassword': |
| 234 |
$(itemText).text('Link'); |
| 235 |
break; |
| 236 |
case 'email': |
| 237 |
$(itemText).text('Email'); |
| 238 |
break; |
| 239 |
case 'telephone': |
| 240 |
$(itemText).text('Telephone'); |
| 241 |
break; |
| 242 |
} |
| 243 |
|
| 244 |
if (type === 'link' || type === 'dynamic') { |
| 245 |
$(itemLinkBlank).show(); |
| 246 |
} |
| 247 |
|
| 248 |
} |
| 249 |
|
| 250 |
mainBtnType(); |
| 251 |
$('body').on('change', '[data-content=1] .item-type', function() { |
| 252 |
mainBtnType(); |
| 253 |
}); |
| 254 |
|
| 255 |
function mainBtnType() { |
| 256 |
const type = $('[data-content=1] .item-type').val(); |
| 257 |
const tabs = $('#tab [data-tab=2], #tab [data-tab=3]'); |
| 258 |
$(tabs).hide(); |
| 259 |
if(type === 'main') $(tabs).show(); |
| 260 |
} |
| 261 |
|
| 262 |
// Color Picker |
| 263 |
$('.wp-color-picker-field').wpColorPicker({ |
| 264 |
change: function(event, ui) { panelHeadingIconColor(this); }, |
| 265 |
}); |
| 266 |
|
| 267 |
// Label keydown |
| 268 |
$('body').on('keyup', '.item-tooltip', function() { |
| 269 |
const val = $(this).val(); |
| 270 |
const parent = $(this).parents('.panel'); |
| 271 |
$(parent).find('.item-label-text').html(val); |
| 272 |
if (val == '') { |
| 273 |
$(parent).find('.item-label-text').html('(no label)'); |
| 274 |
} |
| 275 |
}); |
| 276 |
|
| 277 |
// Toogle menu item |
| 278 |
|
| 279 |
$('body').on('click', '.toogle-element .dashicons-arrow-down', function() { |
| 280 |
const parent = $(this).parents('.panel'); |
| 281 |
$(parent).find('.toogle-content').removeClass('is-hidden'); |
| 282 |
$(this).addClass('is-hidden'); |
| 283 |
$(parent).find('.dashicons-arrow-up').removeClass('is-hidden'); |
| 284 |
}); |
| 285 |
|
| 286 |
$('body').on('click', '.toogle-element .dashicons-arrow-up', function() { |
| 287 |
const parent = $(this).parents('.panel'); |
| 288 |
$(parent).find('.toogle-content').addClass('is-hidden'); |
| 289 |
$(this).addClass('is-hidden'); |
| 290 |
$(parent).find('.dashicons-arrow-down').removeClass('is-hidden'); |
| 291 |
}); |
| 292 |
|
| 293 |
// Check sub-item |
| 294 |
$('input.sub-item:checkbox').each(function() { |
| 295 |
subitem(this); |
| 296 |
}); |
| 297 |
$('body').on('change', 'input.sub-item', function() { |
| 298 |
subitem(this); |
| 299 |
}); |
| 300 |
|
| 301 |
function subitem(el) { |
| 302 |
const parent = $(el).parents('.panel'); |
| 303 |
if ($(el).prop('checked')) { |
| 304 |
$(parent).find('.is-submenu').removeClass('is-hidden'); |
| 305 |
} else { |
| 306 |
$(parent).find('.is-submenu').addClass('is-hidden'); |
| 307 |
} |
| 308 |
} |
| 309 |
|
| 310 |
// Check custom icon |
| 311 |
$('.icons').fontIconPicker({ |
| 312 |
theme: 'fip-darkgrey', |
| 313 |
emptyIcon: false, |
| 314 |
allCategoryText: 'Show all', |
| 315 |
}); |
| 316 |
|
| 317 |
$('input.custom-icon:checkbox').each(function() { |
| 318 |
customicon(this); |
| 319 |
}); |
| 320 |
$('body').on('click', '.custom-icon', function() { |
| 321 |
customicon(this); |
| 322 |
}); |
| 323 |
|
| 324 |
function customicon(el) { |
| 325 |
const parent = $(el).parents('.tabs-content'); |
| 326 |
const iconDefault = $(parent).find('.icon-default'); |
| 327 |
const iconCustom = $(parent).find('.icon-custom'); |
| 328 |
const iconText = $(parent).find('.icon-text'); |
| 329 |
const iconTextField = $(parent).find('.icon-text-field'); |
| 330 |
const checkText = $(parent).find('.custom-icon-text'); |
| 331 |
if ($(el).prop('checked')) { |
| 332 |
$(iconDefault).hide(); |
| 333 |
$(iconCustom).show(); |
| 334 |
$(iconText).hide(); |
| 335 |
$(checkText).prop('checked', false); |
| 336 |
$(iconTextField).addClass('is-hidden'); |
| 337 |
} else { |
| 338 |
$(iconDefault).show(); |
| 339 |
$(iconCustom).hide(); |
| 340 |
$(iconText).show(); |
| 341 |
} |
| 342 |
|
| 343 |
} |
| 344 |
|
| 345 |
$('input.custom-icon-text:checkbox').each(function() { |
| 346 |
customIconText(this); |
| 347 |
}); |
| 348 |
$('body').on('click', '.custom-icon-text', function() { |
| 349 |
customIconText(this); |
| 350 |
}); |
| 351 |
|
| 352 |
function customIconText(el) { |
| 353 |
const parent = $(el).parents('.tabs-content'); |
| 354 |
const iconDefault = $(parent).find('.icon-default'); |
| 355 |
const iconCustom = $(parent).find('.icon-custom'); |
| 356 |
const iconText = $(parent).find('.icon-text-field'); |
| 357 |
const checkCustomIcon = $(parent).find('.custom-icon'); |
| 358 |
if ($(el).prop('checked')) { |
| 359 |
$(iconDefault).hide(); |
| 360 |
$(iconCustom).hide(); |
| 361 |
$(iconText).removeClass('is-hidden'); |
| 362 |
$(checkCustomIcon).prop('checked', false); |
| 363 |
} else { |
| 364 |
$(iconText).addClass('is-hidden'); |
| 365 |
$(iconDefault).show(); |
| 366 |
} |
| 367 |
} |
| 368 |
|
| 369 |
// Hide plugin message |
| 370 |
|
| 371 |
$(document).on('click', '.wow-plugin-message .notice-dismiss', function() { |
| 372 |
$.ajax({ |
| 373 |
url: ajaxurl, data: { |
| 374 |
action: 'float_menu_message', |
| 375 |
}, |
| 376 |
}); |
| 377 |
}); |
| 378 |
|
| 379 |
// Add new Menu item |
| 380 |
$('.add-item').on('click', function() { |
| 381 |
const id = $(this).data('template'); |
| 382 |
const element = document.getElementById('clone-' + id).innerHTML; |
| 383 |
document.querySelector('.menu-items-' + id).insertAdjacentHTML('beforeend', element); |
| 384 |
refreashel(); |
| 385 |
}); |
| 386 |
|
| 387 |
// Refreash the functions |
| 388 |
function refreashel() { |
| 389 |
$('select.item-type').each(function() { |
| 390 |
itemtype(this); |
| 391 |
}); |
| 392 |
$('input.custom-icon:checkbox').each(function() { |
| 393 |
customicon(this); |
| 394 |
}); |
| 395 |
$('.wp-color-picker-field').wpColorPicker({ |
| 396 |
change: function(event, ui) { panelHeadingIconColor(this); }, |
| 397 |
}); |
| 398 |
|
| 399 |
wow_attach_tooltips($('.wow-help')); |
| 400 |
$('.icons').fontIconPicker({ |
| 401 |
theme: 'fip-darkgrey', |
| 402 |
emptyIcon: false, |
| 403 |
allCategoryText: 'Show all', |
| 404 |
}); |
| 405 |
|
| 406 |
$('.icons-selector').on('click', function() { |
| 407 |
const parent = $(this).parents('.panel'); |
| 408 |
selectIcon(parent); |
| 409 |
}); |
| 410 |
|
| 411 |
$('body').on('click keyup', '[data-tab-content="2"]', function() { |
| 412 |
const parent = $(this).parents('.panel'); |
| 413 |
selectIcon(parent); |
| 414 |
}); |
| 415 |
|
| 416 |
} |
| 417 |
|
| 418 |
// Remove Items |
| 419 |
$('body').on('click', '.item-delete', function() { |
| 420 |
const parent = $(this).parents('.panel'); |
| 421 |
$(parent).remove(); |
| 422 |
}); |
| 423 |
|
| 424 |
// Panel tabs |
| 425 |
$('body').on('click', '.panel-tabs a', function() { |
| 426 |
panelTab(this); |
| 427 |
}); |
| 428 |
|
| 429 |
function panelTab(el) { |
| 430 |
const selected = $(el).data('tab'); |
| 431 |
const parent = $(el).parents('.panel'); |
| 432 |
$(parent).find('.panel-tabs a').removeClass('is-active'); |
| 433 |
$(el).addClass('is-active'); |
| 434 |
$(parent).find('.tabs-content').addClass('is-hidden'); |
| 435 |
$(parent).find('[data-tab-content="' + selected + '"]').removeClass('is-hidden'); |
| 436 |
} |
| 437 |
|
| 438 |
$('.wp-color-picker-field').each(function() { |
| 439 |
panelHeadingIconColor(this); |
| 440 |
}); |
| 441 |
$('body').on('change', '.wp-color-picker-field', function() { |
| 442 |
panelHeadingIconColor(this); |
| 443 |
}); |
| 444 |
|
| 445 |
function panelHeadingIconColor(el) { |
| 446 |
const attr = $(el).attr('name'); |
| 447 |
const color = $(el).val(); |
| 448 |
const parent = $(el).parents('.panel'); |
| 449 |
if (attr.includes('[icon_color]')) { |
| 450 |
$(parent).find('.icon-select').css('color', color); |
| 451 |
} else if (attr.includes('[button_color]')) { |
| 452 |
$(parent).find('.icon-select').css('background-color', color); |
| 453 |
} |
| 454 |
} |
| 455 |
|
| 456 |
$('.icons-selector').on('click', function() { |
| 457 |
const parent = $(this).parents('.panel'); |
| 458 |
selectIcon(parent); |
| 459 |
}); |
| 460 |
|
| 461 |
$('body').on('click keyup', '[data-tab-content="2"]', function() { |
| 462 |
const parent = $(this).parents('.panel'); |
| 463 |
selectIcon(parent); |
| 464 |
}); |
| 465 |
|
| 466 |
$('.panel').each(function() { |
| 467 |
selectIcon(this); |
| 468 |
}); |
| 469 |
|
| 470 |
function selectIcon(el) { |
| 471 |
let icon; |
| 472 |
const iconCustom = $(el).find('.custom-icon'); |
| 473 |
const iconText = $(el).find('.custom-icon-text'); |
| 474 |
const iconDefault = $(el).find('.icons').val(); |
| 475 |
if ($(iconCustom).prop('checked')) { |
| 476 |
const img = $(el).find('.custom-icon-url').val(); |
| 477 |
icon = '<img src="' + img + '">'; |
| 478 |
} else if ($(iconText).prop('checked')) { |
| 479 |
const text = $(el).find('.icon-custom-text').val(); |
| 480 |
icon = text; |
| 481 |
} else { |
| 482 |
icon = '<i class="' + iconDefault + '"></i>'; |
| 483 |
} |
| 484 |
$(el).find('.icon-select').html(icon); |
| 485 |
|
| 486 |
} |
| 487 |
|
| 488 |
$('.menu-items').sortable(); |
| 489 |
|
| 490 |
// Close Icon |
| 491 |
$('#close-button-icon').each(function() { |
| 492 |
closeButton(this); |
| 493 |
}).on('click', function() { |
| 494 |
closeButton(this); |
| 495 |
}); |
| 496 |
|
| 497 |
function closeButton(el) { |
| 498 |
const check = $(el).find('input'); |
| 499 |
const closeIcon = $('.close-button-icon'); |
| 500 |
if (check.prop('checked')) { |
| 501 |
$(closeIcon).removeClass('is-hidden'); |
| 502 |
} else { |
| 503 |
$(closeIcon).addClass('is-hidden'); |
| 504 |
} |
| 505 |
} |
| 506 |
|
| 507 |
})(jQuery); |
| 508 |
|