bws_menu.js
4 years ago
bws_tooltip.js
4 years ago
c_o_o_k_i_e.js
4 years ago
codemirror.js
4 years ago
general_script.js
4 years ago
shortcode-button.js
4 years ago
general_script.js
185 lines
| 1 | function bws_show_settings_notice() { |
| 2 | "use strict"; |
| 3 | (function($) { |
| 4 | $( '.updated.fade:not(.bws_visible), .error:not(.bws_visible)' ).css( 'display', 'none' ); |
| 5 | $( '#bws_save_settings_notice' ).css( 'display', 'block' ); |
| 6 | })(jQuery); |
| 7 | } |
| 8 | |
| 9 | (function($) { |
| 10 | "use strict"; |
| 11 | $( document ).ready( function() { |
| 12 | /** |
| 13 | * add notice about changing on the settings page |
| 14 | */ |
| 15 | $( '.bws_form input, .bws_form textarea, .bws_form select' ).on( "change paste select", function() { |
| 16 | if ( $( this ).attr( 'type' ) != 'submit' && ! $( this ).hasClass( 'bws_no_bind_notice' ) ) { |
| 17 | bws_show_settings_notice(); |
| 18 | }; |
| 19 | }); |
| 20 | $( '.bws_save_anchor' ).on( "click", function( event ) { |
| 21 | event.preventDefault(); |
| 22 | $( '.bws_form #bws-submit-button' ).click(); |
| 23 | }); |
| 24 | |
| 25 | /* custom code */ |
| 26 | |
| 27 | if ( 'function' == typeof wp.CodeMirror || 'function' == typeof CodeMirror ) { |
| 28 | var CodeMirrorFunc = ( typeof wp.CodeMirror != 'undefined' ) ? wp.CodeMirror : CodeMirror; |
| 29 | if ( $( '#bws_newcontent_css' ).length > 0 ) { |
| 30 | var editor = CodeMirrorFunc.fromTextArea( document.getElementById( 'bws_newcontent_css' ), { |
| 31 | mode: "css", |
| 32 | theme: "default", |
| 33 | styleActiveLine: true, |
| 34 | matchBrackets: true, |
| 35 | lineNumbers: true, |
| 36 | addModeClass: 'bws_newcontent_css' |
| 37 | }); |
| 38 | } |
| 39 | |
| 40 | if ( $( '#bws_newcontent_php' ).length > 0 ) { |
| 41 | var editor = CodeMirrorFunc.fromTextArea( document.getElementById( "bws_newcontent_php" ), { |
| 42 | mode: 'text/x-php', |
| 43 | styleActiveLine: true, |
| 44 | matchBrackets: true, |
| 45 | lineNumbers: true, |
| 46 | }); |
| 47 | /* disable lines */ |
| 48 | editor.markText( {ch:0,line:0}, {ch:0,line:5}, { readOnly: true, className: 'bws-readonly' } ); |
| 49 | } |
| 50 | |
| 51 | if ( $( '#bws_newcontent_js' ).length > 0 ) { |
| 52 | var editor = CodeMirrorFunc.fromTextArea( document.getElementById( "bws_newcontent_js" ), { |
| 53 | mode: 'javascript', |
| 54 | styleActiveLine: true, |
| 55 | matchBrackets: true, |
| 56 | lineNumbers: true, |
| 57 | }); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | /* banner to settings */ |
| 62 | $( '.bws_banner_to_settings_joint .bws-details' ).addClass( 'hidden' ).removeClass( 'hide-if-js' ); |
| 63 | $( '.bws_banner_to_settings_joint .bws-more-links' ).on( "click", function( event ) { |
| 64 | event.preventDefault(); |
| 65 | if ( $( '.bws_banner_to_settings_joint .bws-less' ).hasClass( 'hidden' ) ) { |
| 66 | $( '.bws_banner_to_settings_joint .bws-less, .bws_banner_to_settings_joint .bws-details' ).removeClass( 'hidden' ); |
| 67 | $( '.bws_banner_to_settings_joint .bws-more' ).addClass( 'hidden' ); |
| 68 | } else { |
| 69 | $( '.bws_banner_to_settings_joint .bws-less, .bws_banner_to_settings_joint .bws-details' ).addClass( 'hidden' ); |
| 70 | $( '.bws_banner_to_settings_joint .bws-more' ).removeClass( 'hidden' ); |
| 71 | } |
| 72 | }); |
| 73 | |
| 74 | /* help tooltips */ |
| 75 | if ( $( '.bws_help_box' ).length > 0 ) { |
| 76 | if ( $( 'body' ).hasClass( 'rtl' ) ) { |
| 77 | var current_position = { my: "right top+15", at: "right bottom" }; |
| 78 | } else { |
| 79 | var current_position = { my: "left top+15", at: "left bottom" }; |
| 80 | } |
| 81 | $( document ).tooltip( { |
| 82 | items: $( '.bws_help_box' ), |
| 83 | content: function() { |
| 84 | return $( this ).find( '.bws_hidden_help_text' ).html() |
| 85 | }, |
| 86 | show: null, /* show immediately */ |
| 87 | tooltipClass: "bws-tooltip-content", |
| 88 | position: current_position, |
| 89 | open: function( event, ui ) { |
| 90 | if ( typeof( event.originalEvent ) === 'undefined' ) { |
| 91 | return false; |
| 92 | } |
| 93 | if ( $( event.originalEvent.target ).hasClass( 'bws-auto-width' ) ) { |
| 94 | ui.tooltip.css( "max-width", "inherit" ); |
| 95 | } |
| 96 | var $id = $( ui.tooltip ).attr( 'id' ); |
| 97 | /* close any lingering tooltips */ |
| 98 | $( 'div.ui-tooltip' ).not( '#' + $id ).remove(); |
| 99 | }, |
| 100 | close: function( event, ui ) { |
| 101 | ui.tooltip.hover( function() { |
| 102 | $( this ).stop( true ).fadeTo( 200, 1 ); |
| 103 | }, |
| 104 | function() { |
| 105 | $( this ).fadeOut( '200', function() { |
| 106 | $( this ).remove(); |
| 107 | }); |
| 108 | }); |
| 109 | } |
| 110 | }); |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Handle the styling of the "Settings" tab on the plugin settings page |
| 115 | */ |
| 116 | var tabs = $( '#bws_settings_tabs_wrapper' ); |
| 117 | if ( tabs.length ) { |
| 118 | var current_tab_field = $( 'input[name="bws_active_tab"]' ), |
| 119 | prevent_tabs_change = false, |
| 120 | active_tab = current_tab_field.val(); |
| 121 | if ( '' == active_tab ) { |
| 122 | var active_tab_index = 0; |
| 123 | } else { |
| 124 | var active_tab_index = $( '#bws_settings_tabs li[data-slug=' + active_tab + ']' ).index(); |
| 125 | } |
| 126 | |
| 127 | $( '.bws_tab' ).css( 'min-height', $( '#bws_settings_tabs' ).css( 'height' ) ); |
| 128 | |
| 129 | /* jQuery tabs initialization */ |
| 130 | tabs.tabs({ |
| 131 | active: active_tab_index |
| 132 | }).on( "tabsactivate", function( event, ui ) { |
| 133 | if ( ! prevent_tabs_change ) { |
| 134 | active_tab = ui.newTab.data( 'slug' ); |
| 135 | current_tab_field.val( active_tab ); |
| 136 | } |
| 137 | prevent_tabs_change = false; |
| 138 | }); |
| 139 | $( '.bws_trigger_tab_click' ).on( 'click', function () { |
| 140 | $( '#bws_settings_tabs a[href="' + $( this ).attr( 'href' ) + '"]' ).click(); |
| 141 | }); |
| 142 | } |
| 143 | /** |
| 144 | * Hide content for options on the plugin settings page |
| 145 | */ |
| 146 | var options = $( '.bws_option_affect' ); |
| 147 | if ( options.length ) { |
| 148 | options.each( function() { |
| 149 | var element = $( this ); |
| 150 | if ( element.is( ':selected' ) || element.is( ':checked' ) ) { |
| 151 | $( element.data( 'affect-show' ) ).show(); |
| 152 | $( element.data( 'affect-hide' ) ).hide(); |
| 153 | } else { |
| 154 | $( element.data( 'affect-show' ) ).hide(); |
| 155 | $( element.data( 'affect-hide' ) ).show(); |
| 156 | } |
| 157 | if ( element.is( 'option' ) ) { |
| 158 | element.parent().on( 'change', function() { |
| 159 | var affect_hide = element.data( 'affect-hide' ), |
| 160 | affect_show = element.data( 'affect-show' ); |
| 161 | if ( element.is( ':selected' ) ) { |
| 162 | $( affect_show ).show(); |
| 163 | $( affect_hide ).hide(); |
| 164 | } else { |
| 165 | $( affect_show ).hide(); |
| 166 | $( affect_hide ).show(); |
| 167 | } |
| 168 | }); |
| 169 | } else { |
| 170 | element.on( 'change', function() { |
| 171 | var affect_hide = element.data( 'affect-hide' ), |
| 172 | affect_show = element.data( 'affect-show' ); |
| 173 | if ( element.is( ':selected' ) || element.is( ':checked' ) ) { |
| 174 | $( affect_show ).show(); |
| 175 | $( affect_hide ).hide(); |
| 176 | } else { |
| 177 | $( affect_show ).hide(); |
| 178 | $( affect_hide ).show(); |
| 179 | } |
| 180 | }); |
| 181 | } |
| 182 | }); |
| 183 | } |
| 184 | }); |
| 185 | })(jQuery); |