How to debug a simple jsQuery plugin which attempts to change background color of a section?
(Using a new install of Vanilla 2.1)
I'm trying to have a simple plugin that changes background on a div based on a jsQuery and content (in this case an Announcement).
Following peregrine's suggestion I created a plugin and enabled it. It has a jsQuery as follows:
- jQuery(document).ready(function($) {
- $("span.Tag-Announcement").closest('.Item').css("background", "yellow");
- });
The plugin enabled successfully but it's not taking any effect.
I created the plugin in /plugins/Announce_js with files default.php and /plugins/Announce_js/js/set_background.js
<?php if (!defined('APPLICATION')) exit(); // Define the plugin: $PluginInfo['Announce_js'] = array( 'Name' => 'Announce_js', 'Description' => 'set background of sticky discussions (Announcements)', 'Version' => '1.1', 'RequiredApplications' => FALSE, 'RequiredTheme' => FALSE, 'RequiredPlugins' => FALSE, 'Author' => "Ricardo" ); class Announce_jsPlugin extends Gdn_Plugin { public function DiscussionsController_Render_Before(&$Sender) { $Sender->AddJsFile('/plugins/Announce_js/js/set_background.js'); } public function DiscussionController_Render_Before($Sender) { $Sender->AddJsFile('/plugins/Announce_js/js/set_background.js'); } }
The set_background.js file:jQuery(document).ready(function($) { $("span.Tag-Announcement").closest('.Item').css("background", "yellow"); });
Comments
use console and web developer tools and logically assign triggers to fire and test if they are fired and if you have js errors. It's a stepwise progression to debugging.
I already finished the plugin I started for you, rather than debugging or correcting yours.
http://vanillaforums.org/discussion/comment/209112/#Comment_209112
also troubleshooting tips and js tutorials and firbug tutorial links in this thread.
http://vanillaforums.org/discussion/20231/how-to-become-somewhat-adept-at-modifying-vanilla-to-meet-your-needs-for-free
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
Yes I understand and I have been doing some tests and trying to debug.
Once again, I appreciate your willingness to help.
I am unable to enable the plugin, it simply gives me this error (with no additional description) other than a yellow line/bar across the page below this text.
The addon could not be enabled because it generated a fatal error:
I will continue trying to debug this.
thank you,
Ricardo
Sorry for creating confusion. I know you put the answer in the other posting, I had followed your suggestion and created this new posting.
I did use your AnnouncementColor plugin example and that's what's causing the fatal error without additional description.
I'm taking a look to see if I can figure it out. You have been very helpful
I would post a zip of the plugin. unfortunately they removed the ability to post zip files, which makes things alot harder.
I would delete the pluginAnnouncementColor folder.
and your delete your old plugin folder for Announce_js
then look here: http://vanillaforums.org/discussion/comment/209112/#Comment_209112
then I would cut and paste EXACTLY (no mods) as it says in the proper folders. If you can't enable and disable, you probably did make your folder properly. The UpperandLowercase MUST match. and you must have read permissions.
make sure the folder is EXACT AnnouncementColor
and don't change the plugin! till you see the unchanged plugin working.
edited: ALMOST exactly
see comment below.
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
got it, thanks.
There was one error (typo) I noticed which was for the filename in your example.
put the above in plugins/AnnouncementColor/js/ancolor,js
it should be
put the above in plugins/AnnouncementColor/js/ancolor.js
You had a comma (,) instead of period (.) in the filename
good eyes. you are right. it wouldn't have loaded the js if your filename had a comma in it.
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.