Me and Javascript/jQuery don't get along well ...
What I want to do is show the first 200 or so characters of a user's "about me" text and then expand it when you click the "more" link.
I added to my template.php
function bartik_preprocess_user_profile(&$variables){
drupal_add_js('themes/bartik/js/moreless.js');
}
The moreless.js code is:
jQuery(document).ready( function ($) {
$(".moreLess").hide();
$(".moreLessSwitch").toggle(function() {
$(this).html("<a href=#>Less</a>");
$(this).prevAll(".moreLess").slideDown();
}, function() {
$(this).html("<a href=#>More...</a>");
$(this).prevAll(".moreLess").slideUp();
});
}(jQuery));
in user-profile.tpl.php I have:
stuff to always show
<div class="moreLess">stuff to hide...</div><br>
<div class="moreLessSwitch">[+] more</div>
This is the working jfiddle sample.
When I load a user profile nothing happens, I had all caches flushed. No js errors. When i copy the jquery code into the console it works.
This has to be something dumb simple ;-)
Also, is this really the correct way to add conditional js to some pages?