Results 1 to 2 of 2

Thread: Override Javascript Function

  1. #1
    Thread Starter
    ncirotto's Avatar
    Join Date
    Apr 2014
    Location
    Italy
    Posts
    26
    Thanks
    4
    Thanked 1 Time in 1 Post

    Override Javascript Function

    Hi,
    I'm trying to create a Child Theme for ClassiPress.

    I need to override cp_reposition_widgets javascript function in "theme-scripts.js":

    Code:
    function cp_reposition_widgets() {
    	if ( jQuery(window).width() > 800 ) {
    		jQuery('.content_left #welcome_widget').prependTo('.content_right');
    		jQuery('.content_left #refine_widget').prependTo('.content_right');
    	} else {
    		jQuery('.content_right #welcome_widget').prependTo('.content_left');
    		jQuery('.content_right #refine_widget').prependTo('.content_left');
    	}
    }
    In functions.php I added this code:
    Code:
    if ( !function_exists('cp_load_scripts') ) :
    function cp_load_scripts() {
    	global $cp_options;
    	wp_enqueue_script( 'custom-theme-scripts', get_stylesheet_directory_uri() . '/includes/js/theme-scripts.js', array( 'jquery' ), '3.3.3' );
    }
    endif;
    add_action( 'wp_enqueue_scripts', 'cp_load_scripts' );
    But I think there are a conflict name function.

    I tryed to add "_custom" to function name:

    Code:
    if ( !function_exists('cp_load_scripts') ) :
    function cp_load_scripts_custom() {
    	global $cp_options;
    	wp_enqueue_script( 'custom-theme-scripts', get_stylesheet_directory_uri() . '/includes/js/theme-scripts.js', array( 'jquery' ), '3.3.3' );
    }
    endif;
    add_action( 'wp_enqueue_scripts', 'cp_load_scripts_custom' );
    and the javascript is:
    Code:
    jQuery(window).bind( "resize", cp_reposition_widgets_custom );
    function cp_reposition_widgets_custom() {
    	if ( jQuery(window).width() > 800 ) {
    		jQuery('.content_left #welcome_widget').prependTo('.content_right');
    		jQuery('.content_left #refine_widget').prependTo('.content_right');
    	} else {
    		jQuery('.content_right #welcome_widget').prependTo('.content_left');
    		jQuery('.content_right #refine_widget').prependTo('.content_right');
    	}
    }
    Now my javascrpt work BUT before the call from core of classipress and my eventual modification of DIV are not visible.

    Now my question is:
    There are a way to override only the "cp_reposition_widgets" function?

    (I want the refine search after the ad list on the mobile devices)

    Thanks

  2. #2
    Thread Starter
    ncirotto's Avatar
    Join Date
    Apr 2014
    Location
    Italy
    Posts
    26
    Thanks
    4
    Thanked 1 Time in 1 Post
    You must be an AppThemes customer and logged in to view this response. Join today!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [MOD NEEDED] How do I override Pagination
    By shaneoriordan in forum Vantage General Discussion (Legacy)
    Replies: 0
    Last Post: April 7th, 2014, 03:38 AM
  2. To override external links?
    By ademsari238 in forum Help Using ClassiPress
    Replies: 3
    Last Post: April 2nd, 2014, 06:12 AM
  3. Best way to override jr_* functions
    By jemcapon in forum Report JobRoller Bugs
    Replies: 1
    Last Post: July 23rd, 2012, 06:55 AM
  4. Override Function in Core Theme
    By Leongelis in forum ClassiPress General Discussion
    Replies: 3
    Last Post: March 21st, 2012, 11:14 PM