Skip to:
Content

BuddyPress.org

Opened 15 years ago

Closed 15 years ago

#1628 closed enhancement (fixed)

bp_filter_request is not defined

Reported by: grosbouff's profile grosbouff Owned by: apeatling's profile apeatling
Milestone: 1.2 Priority: major
Severity: Version:
Component: Keywords: has-patch
Cc: sbrajesh, marshall.sorenson@…

Description

When calling the js function bp_filter_request() in a plugin, it returns 'bp_filter_request is not defined' :

The (core) function bp_filter_request is called inside my custom ajax.js :

jQuery(document).ready( function() {
var j = jQuery;

/*load initial content*/
if ( j('div.classified3s').length ) {
bp_filter_request( j.cookie('bp-classified3s-type'), j.cookie('bp-classified3s-filter'), 'classified3s', 'div.classified3s', j.cookie('bp-classified3s-page'), j.cookie('bp-classified3s-search-terms') );
}

and the ajax.js file is loaded with this function :

function classified3s_add_js() {
global $bp;

if (bp_is_user_classified3s()) {
wp_enqueue_script( 'bp-classified3s-ajax', get_stylesheet_directory_uri() . '/classified3s/_inc/js/ajax.js', array('dtheme-ajax-js') );
}
}
add_action( 'wp_print_scripts', 'classified3s_add_js', 1 );

So I guess it should be workins as the function bp_filter_request is inside the file enqueued as 'dtheme-ajax-js'.

Any idea ?

Change History (7)

#1 @sbrajesh
15 years ago

  • Cc sbrajesh added
  • Owner set to apeatling
  • Status changed from new to assigned
  • Type changed from defect to enhancement

hi Andy
As per forum topic
http://buddypress.org/forums/topic/bp-12-bp_filter_request-is-not-defined

As I mentioned there in forum this is a scope problem with the javascript function, I am not sure whether you should really put the function in global scope or not because it is tied to dom elements/bp-default theme and custom bp-themes may not offer this function. So If a plugin is using this function, They should rather supply a copy of their own. btw, if you decide to put it in global scope, I hope most of the custom themes will also do that, but checking the existence of the javascript method will be still necessary for plugin developers.

So decision is yours :)

#2 @MrMaz
15 years ago

  • Keywords has-patch added

Here is my solution which would be added near the top of global.js. It relies very much on convention, but maybe that can be addressed in the future.

	/* Plugins
	 * To filter your plugins requests, simply add the
	 * 'do-filter-request' class to your content div
	 * Example:
	 *  <div id="foo-dir-list" class="foo dir-list do-filter-request">
	 */
	var filter_plugin_id = j('div.do-filter-request').attr('id');
	if ( filter_plugin_id && filter_plugin_id.length ) {
		var filter_plugin_id_split = filter_plugin_id.split('-');
		if ( filter_plugin_id_split[0].length ) {
			var filter_plugin_name = filter_plugin_id_split[0];
			bp_filter_request( filter_plugin_name, j.cookie('bp-' + filter_plugin_name + '-filter'), j.cookie('bp-' + filter_plugin_name + '-scope'), 'div.' + filter_plugin_name );
		}
	}

#3 @MrMaz
15 years ago

  • Cc marshall.sorenson@… added

#4 @MrMaz
15 years ago

I just ran into another case where this is a roadblock. If you want to create your own directory filter then it is necessary to call bp_filter_request onchange, or maybe onclick.

Without being able to call bp_filter_request directly, or have it somehow attached to events of a particular class, it causes plugin developers to duplicate a lot of JS only to get this functionality into scope.

My solution above is only part of the picture, and should probably be handled differently, but in general the idea is still the same.

#5 @apeatling
15 years ago

I don't really see a problem with moving this into the global scope. It does have specific HTML that it relies on, but this JS function is just for the default theme, so I think it is safe to expect it.

#6 @apeatling
15 years ago

Also, you will need to do a check in your plugins to make sure this function exists, since some themes that do not extend the default theme may not include it. Make sure you have something to fall back on, perhaps without the use of JS.

#7 @apeatling
15 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [2473]) Moving request functions into the global scope. Fixes #1628

Note: See TracTickets for help on using tickets.