Steffen Itterheim
asked this on May 14 16:41
I've added a search form to my Wordpress site according to this example: http://help.screensteps.com/spaces/screensteps/manuals/api/lessons/...
The search results all link to pages on http://learngamedev.screenstepslive.com instead of http://www.learn-cocos2d.com
Try the search box on this page for example: http://www.learn-cocos2d.com/knowledge-base/tutorial-professional-c...
Is it possible to have the search result links pointing to the Wordpress domain instead?
I mean a link like this to a lesson that's embedded in Wordpress: http://www.learn-cocos2d.com/knowledge-base/tutorial-professional-c...

Steffen
You can do this by performing a string replace on the search results that are returned. Add this bit of code right after the
SearchScreenStepsLiveSpace(search_string);
function in your javascript.
jQuery("div#search_results ul li a").each(function(i) {
new_url = this.href.replace("http://learngamedev.screenstepslive.com/spaces/", "http://www.learn-cocos2d.com/knowledge-base/tutorial-professional-c...");
this.href = new_url;
});
Let us know if that works for you.

Unfortunately it didn't change the search result links at all. Maybe i made a mistake though.
It probably won't work correctly because search will find results from all manuals but the replaced link can only point to a specific manual. Which means for every manual returned i would have to pick the correct wordpress url and replace it with that, and also maintain those links when i add more pages and manuals.

This is what the code should look like:
jQuery(document).ready(function($) {
jQuery('#screenstepslive-search').submit(function(e){
e.preventDefault();
search_string = jQuery('#screenstepslive-search input#screenstepslive-search-field').val();
SearchScreenStepsLiveSpace(search_string);
jQuery("div#search_results ul li a").each(function(i) {
new_url = this.href.replace("http://learngamedev.screenstepslive.com/spaces/", "http://www.learn-cocos2d.com/knowledge-base/tutorial-professional-c...");
this.href = new_url;
});
})
});
Have your lessons in separate manuals shouldn't make a difference because the widget is searching your entire space and only replacing the top level information.

This is the full script code on my site:
<code>
<script src="http://screenstepslive.com/javascripts/push/screenstepslive.js" type="text/javascript" charset="utf-8"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
ScreenStepsLiveSearchOptions = {
domain: "learngamedev.screenstepslive.com",
space: "learn-cocos2d-public-content",
update_element: "search_results",
username: "apiaccess",
password: "apiaccess",
use_ssl: false
}
jQuery.noConflict();
jQuery(document).ready(function($) {
jQuery('#screenstepslive-search').submit(function(e){
e.preventDefault();
search_string = jQuery('#screenstepslive-search input#screenstepslive-search-field').val();
SearchScreenStepsLiveSpace(search_string);
jQuery("div#search_results ul li a").each(function(i) {
new_url = this.href.replace("http://learngamedev.screenstepslive.com/spaces/", "http://www.learn-cocos2d.com/knowledge-base/tutorial-professional-c...");
this.href = new_url;
});
})
}); </script>
</code>
The code is from the page source once it was loaded, i wanted to be sure that nothing mangled it. Still only get learngamedev.screenstepslive.com links.
I did notice however that jquery is included twice on my website, the first time by the blog theme which includes jquery 1.3.2 ... could this cause problems?

Btw, how do i properly format code in this forum? The <code> tags were my attempt to format it, they are not part of the actual code.

OK - Have tested this and it works. The old code wasn't getting called. Sorry about that. What we need to do is override one of the callback functions. First we will add two lines to your config:
ScreenStepsLiveSearchOptions = {
domain: "learngamedev.screenstepslive.com",
space: "learn-cocos2d-public-content",
update_element: "search_results",
username: "apiaccess",
password: "apiaccess",
use_ssl: false,
string_to_replace: "http://learngamedev.screenstepslive.com/spaces/",
replacement_string: "http://www.learn-cocos2d.com/knowledge-base/tutorial-professional-c..."
}
Make sure you update the replace_string with "http://www.learn-cocos2d.com/knowledge-base/tutorial-professional-c...". The forum software keeps truncating that text.
Now add a new function to your script:
function UpdateURLs(){
jQuery("div#search_results ul li a").each(function(i) {
new_url = this.href.replace(ScreenStepsLiveSearchOptions.string_to_replace, ScreenStepsLiveSearchOptions.replacement_string);
jQuery(this).attr("href", new_url)
});
}
And finally we are going to overwrite a function from the server script to call our new function. Add this code in:
function DisplayScreenStepsLiveSearchResults(data){
if (data.errors == undefined) {
jQuery('#' + ScreenStepsLiveSearchOptions.update_element).html(render_lesson_results(data.lessons));
UpdateURLs();
} else {
jQuery.each(data.errors, function(error) { alert(error); })
}
}
To add the code you have to enter HTML edit mode and enter pre tags. Your can use the preformatted option from the styling drop down as well but that can be a bit flakey.

I would also make sure that you aren't including jQuery twice. That could cause problems for you.

Thanks so much! That's a huge leap forward but unfortunately still not quite there yet.
Ii removed the additional jQuery (using the blog's default 1.3.2). I added your functions and the options part (with correct string). I also removed the previous jQuery block with the href.replace.
The result is: it works fine for lessons of the "replacement_string" manual, so that's great!
But it fails for lessons from a different manual, it creates this link and when i open it it takes a while and then displays only "Error:", see this link:
http://www.learn-cocos2d.com/knowledge-base/tutorial-professional-c...
I also wanted to ask two more questions:
- is it possible to integrate ScreenSteps Live search with Wordpress' builtin search function?
- is it possible to change the "open in new window" behavior when clicking on a search result link?

Can you either post a screenshot of your WP ScreenSteps Live plugin configuration screen or email it to support (if it has any sensitive info)?
Re: integrating WP search. That isn't possible right now. I know Trevor was looking at that but I don't know what the status is.
Re: opening in new window. We can add some additional jQuery code that will take care of this. Let's get the other issues resolved first and then we can work on that.
If you can post or send your configuration to us that would help.