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