| 1 |
(function( $ ) { |
| 2 |
'use strict'; |
| 3 |
|
| 4 |
$( document ).ready(function($) { |
| 5 |
|
| 6 |
//Initiate Color Picker |
| 7 |
$('.wp-color-picker-field').wpColorPicker(); |
| 8 |
|
| 9 |
$('.selecttwo-select').select2({ |
| 10 |
placeholder: cbxgooglemap_setting.please_select, |
| 11 |
allowClear: false |
| 12 |
}); |
| 13 |
|
| 14 |
// Switches option sections |
| 15 |
var activetab = ''; |
| 16 |
if (typeof(localStorage) !== 'undefined') { |
| 17 |
activetab = localStorage.getItem('cbxgooglemapactivetab'); |
| 18 |
} |
| 19 |
|
| 20 |
//if url has section id as hash then set it as active or override the current local storage value |
| 21 |
if(window.location.hash){ |
| 22 |
if($(window.location.hash).hasClass('cbxgooglemap_group')){ |
| 23 |
activetab = window.location.hash; |
| 24 |
if (typeof(localStorage) !== 'undefined' ) { |
| 25 |
localStorage.setItem('cbxgooglemapactivetab', activetab); |
| 26 |
} |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
|
| 31 |
if (activetab !== '' && $(activetab).length && $(activetab).hasClass('cbxgooglemap_group')) { |
| 32 |
$('.cbxgooglemap_group').hide(); |
| 33 |
$(activetab).fadeIn(); |
| 34 |
} |
| 35 |
|
| 36 |
if (activetab !== '' && $(activetab + '-tab').length) { |
| 37 |
$('.nav-tab-wrapper a.nav-tab').removeClass('nav-tab-active'); |
| 38 |
$(activetab + '-tab').addClass('nav-tab-active'); |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
$('.nav-tab-wrapper a').on('click', function (e) { |
| 46 |
e.preventDefault(); |
| 47 |
|
| 48 |
var $this = $(this); |
| 49 |
|
| 50 |
$('.nav-tab-wrapper a.nav-tab').removeClass('nav-tab-active'); |
| 51 |
$this.addClass('nav-tab-active').blur(); |
| 52 |
|
| 53 |
var clicked_group = $(this).attr('href'); |
| 54 |
|
| 55 |
if (typeof (localStorage) !== 'undefined') { |
| 56 |
localStorage.setItem('cbxgooglemapactivetab', $(this).attr('href')); |
| 57 |
} |
| 58 |
$('.cbxgooglemap_group').hide(); |
| 59 |
$(clicked_group).fadeIn(); |
| 60 |
}); |
| 61 |
|
| 62 |
$('.wpsa-browse').on('click', function (event) { |
| 63 |
event.preventDefault(); |
| 64 |
|
| 65 |
var self = $(this); |
| 66 |
|
| 67 |
// Create the media frame. |
| 68 |
var file_frame = wp.media.frames.file_frame = wp.media({ |
| 69 |
title: self.data('uploader_title'), |
| 70 |
button: { |
| 71 |
text: self.data('uploader_button_text') |
| 72 |
}, |
| 73 |
multiple: false |
| 74 |
}); |
| 75 |
|
| 76 |
file_frame.on('select', function () { |
| 77 |
var attachment = file_frame.state().get('selection').first().toJSON(); |
| 78 |
|
| 79 |
self.prev('.wpsa-url').val(attachment.url); |
| 80 |
}); |
| 81 |
|
| 82 |
// Finally, open the modal |
| 83 |
file_frame.open(); |
| 84 |
}); |
| 85 |
|
| 86 |
//make the subheading single row |
| 87 |
$('.setting_subheading').each(function (index, element) { |
| 88 |
var $element = $(element); |
| 89 |
var $element_parent = $element.parent('td'); |
| 90 |
$element_parent.attr('colspan', 2); |
| 91 |
$element_parent.prev('th').remove(); |
| 92 |
}); |
| 93 |
|
| 94 |
//make the subheading single row |
| 95 |
$('.setting_heading').each(function (index, element) { |
| 96 |
var $element = $(element); |
| 97 |
var $element_parent = $element.parent('td'); |
| 98 |
$element_parent.attr('colspan', 2); |
| 99 |
$element_parent.prev('th').remove(); |
| 100 |
}); |
| 101 |
|
| 102 |
$('.cbxgooglemap_group').each(function (index, element) { |
| 103 |
var $element = $(element); |
| 104 |
var $form_table = $element.find('.form-table'); |
| 105 |
$form_table.prev('h2').remove(); |
| 106 |
}); |
| 107 |
|
| 108 |
//one click save setting for the current tab |
| 109 |
$('#save_settings').on('click', function (e) { |
| 110 |
e.preventDefault(); |
| 111 |
|
| 112 |
var $current_tab = $('.nav-tab.nav-tab-active'); |
| 113 |
var $tab_id = $current_tab.data('tabid'); |
| 114 |
$('#' + $tab_id).find('.submit_cbxgooglemap').trigger('click'); |
| 115 |
}); |
| 116 |
|
| 117 |
//copy shortcode |
| 118 |
$('.shortcode_demo_btn').on('click', function (event) { |
| 119 |
event.preventDefault(); |
| 120 |
|
| 121 |
var $this = $(this); |
| 122 |
var $target = $this.data('target-cp'); |
| 123 |
var $copy_area = $($target); |
| 124 |
|
| 125 |
$copy_area.focus(); |
| 126 |
$copy_area.select(); |
| 127 |
|
| 128 |
try { |
| 129 |
var successful = document.execCommand('copy'); |
| 130 |
if(successful){ |
| 131 |
$this.text(cbxgooglemap_setting.copy_success); |
| 132 |
$this.addClass('copy_success'); |
| 133 |
} |
| 134 |
else{ |
| 135 |
$this.text(cbxgooglemap_setting.copy_fail); |
| 136 |
$this.addClass('copy_fail'); |
| 137 |
} |
| 138 |
} catch (err) { |
| 139 |
$this.text(cbxgooglemap_setting.copy_fail); |
| 140 |
$this.addClass('copy_fail'); |
| 141 |
} |
| 142 |
|
| 143 |
});//end copy shortcode |
| 144 |
|
| 145 |
}); |
| 146 |
})( jQuery ); |
| 147 |
|