Add script declaration in an autoaction

2 months 2 weeks ago #329913 by activha
Hello

I tried to condition a script declaration on an itemid in a code autoaction but it fails.

Should I use something else within CB framework ?
$app = JFactory::getApplication();
$document = JFactory::getDocument();

//page activer
$jsactiver = 'cbjQuery( document ).ready( function( $ ) {
	var jQuery = $;
	$(".streamInputUploadContainer").removeClass("hidden");
	$(".galleryShareLinkArea"). addClass("hidden");
	$(".galleryItemsNewOr"). addClass("hidden");
	$(".streamInputLocationContainer").removeClass("hidden");
	$(".streamInputActiv").click(function(){
		$(\'select[name="location\[id\]"]\').val("1");
		$(".streamInputCampaign").toggleClass("hidden");
		$(".streamInputUpload").toggleClass("hidden");
		$(".galleryItemsNewOr"). addClass("hidden");
		$(".galleryShareLinkArea"). addClass("hidden");
//$(".galleryItemsNewUpload").toggleClass("hidden");
$(\'input[name="[input_name]"]\').attr(\'required\', function(_, attr){ return !attr}); 
	});
});';


//page flux
$jsflux = 'cbjQuery( document ).ready( function( $ ) {
	var jQuery = $;
	$(".streamInputActiv").click(function(){
		$(\'select[name="location\[id\]"]\').val("1");
		$(".streamInputCampaign").toggleClass("hidden");
		$(".streamInputUpload").toggleClass("hidden");
		$(".galleryItemsNewOr"). toggleClass("hidden");
		$(".galleryShareLinkArea"). toggleClass("hidden");
//$(".galleryItemsNewUpload").toggleClass("hidden");
$(\'input[name="[input_name]"]\').attr(\'required\', function(_, attr){ return !attr}); 
	});
});';

$sitemenu = $app->getMenu();
$activeMenuitem = $sitemenu->getActive();
//print_r($activeMenuitem->id);
$activeMenuitem->id = '1926' ? $document->addScriptDeclaration($jsactiver) : $document->addScriptDeclaration($jsflux);

Please Log in to join the conversation.

2 months 2 weeks ago #329917 by activha
Replied by activha on topic Add script declaration in an autoaction
Found that CB did not like this way so reverted to two single autoactions to add jQuery depending of the itemid

Solved

Please Log in to join the conversation.

2 months 2 weeks ago - 2 months 2 weeks ago #329918 by krileon
Replied by krileon on topic Add script declaration in an autoaction
Are you trying to output JS on specific menu item? What trigger are you using? I cannot help you in regards to whether your code will even work or not, but can at least suggest the appropriate trigger and conditions example (for the Conditions tab) based off whatever you're trying to do.

The Itemid (menu id) is usually always in the URL so you should be able to use [get_itemid] to retrieve it. Which can also be used in an IF condition. Example as follows.

[cb:if get_itemid="123"]
JS_FOR_MENU_123
[cb:else]
JS_FOR_OTHER_MENUS
[/cb:else]
[/cb:if]

It's cleaner to just use 2 completely separate auto actions though as you've discovered.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

2 months 2 weeks ago - 2 months 2 weeks ago #329931 by activha
Replied by activha on topic Add script declaration in an autoaction
Thanks for your suggestion, I'll keep two autoactions, that will be easier to maintain.

On a side subject, can you tell me how to hide the privacy selector near the post button on a selected page ?

I cannot find it in the activity menu params ?
For now I have hidden it with css, is that enough ?

Please Log in to join the conversation.

2 months 2 weeks ago #329938 by krileon
Replied by krileon on topic Add script declaration in an autoaction

On a side subject, can you tell me how to hide the privacy selector near the post button on a selected page ?

I guess you can hide it with CSS, but that's not going to stop its storage behavior. Ideally you should make a copy of the CB Activity privacy system actions then add conditions to them as needed to limit their usage to specific streams. This won't be necessary with CB Activity 6.0.0 though as those system actions won't exist anymore and you'll be able to just directly toggle on/off privacy in the stored streams easily.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.
The following user(s) said Thank You: activha

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.165 seconds

Facebook Twitter LinkedIn