Is there a way to change the body class of a Wordpress page based on Rev Slider's slide? - wordpress

The goal is: as the slide of rev slider changes, the body's page background color changes. The only way that I think it could be possible is using custom class on page slug. But how to insert a class based on the slide? Is it possible?

1) You must find where Revolution Slider is initialized in your theme or plugin, and either a) note the variable it is assigned to or b) assign it to a variable. It should be something like this:
var revapi2 = jQuery('#slider_id').show().revolution();
New versions of Revolution Slider already assign the slider to a variable that allows binding. The format for this variable is revapi{id}.
2) Once the slider is assigned to a variable, you'll have access to the slide's API methods, described fully here. One of the methods, revolution.slide.onchange will enable detecting when the slider is about to change slides. Then you can do something like this to assign the body class depending on the slide's index. Note I'm using jQuery because it's a jQuery plugin and I'm using the variable automatically assigned by the Revolution Slider WordPress plugin:
revapi2.on('revolution.slide.onbeforeswap', function(event, data) {
switch (data.nextSlideIndex) {
case 1:
bodyClass = "green";
break;
case 2:
bodyClass = "blue";
break;
case 3:
bodyClass = "red";
break;
default:
bodyClass = "yellow";
}
$('body').removeClass('red green blue yellow').addClass(bodyClass);
});

Related

IcCube Reporting V8 - How to add a (some) CSS class(es) to a widget?

In IcCube reporting V7, I used a lot the functionality to add a or some class(es) to a widget which allowed me mainly to display or hide other widgets based on data selected or not. for example, show the map widget related only if at least one company is selected.
Add a CSS Class in V7 was easy like this : Select General, then Advanced properties, and input a class name :
Then, from the report's JS code, I could manage what I need, as for example :
if (event.name == 'EtabSelected') {
var $report = context.$report;
var $mapVisible = $report.find(".map-visible");
if (event.value.classID === "viz.event.EmptySelectionEvent")
{
$mapVisible.hide();
}
else
{
$mapVisible.show();
}
}...
Is it possible to do that in V8 ?
Also, being able to override a style at widget level was also very handy, is it also still possible ?
Hiding/showing widgets based on an event is possible in V8.
For example, if I have a report with buttons to select an article, and I only want to show widgets based on the value of my button filter, then I can use this code.
if (context.getEventName(event) === "selProduct") {
const eventValue = context.getEventMdx(event);
if (eventValue === "[Product].[Article].[Article].&[2]") {
// Hide ww0 (area chart) and show ww2 (column chart)
context.getWidget$("ww0").css('visibility', 'hidden')
context.getWidget$("ww2").css('visibility', 'visible')
} else {
// Hide ww2 (column chart) and show ww0 (area chart)
context.getWidget$("ww0").css('visibility', 'visible')
context.getWidget$("ww2").css('visibility', 'hidden')
}
}
You can set this option in Dashboard Settings > Javascript > onNewEvent. See the screenshot below.

Adding Tree Header for Button in Odoo

I have added icons in tree view to perform some actions and i want to show header / label to these buttons. For example, I have two icons on tree view and its header title is empty. So I want to add a single heading for these icons which will be "Action" for eg. for all the records like other fields heading.
I have tried a link for this and exactly I want the same in my case but didn't worked for me. Here is the link.
Here is the screenshot of what I am getting while implementing the code. It is displaying the string in the icon itself but not in the tree header.
The node tag attribute will be set to button_group, the string and class attributes will be available in the child attributes.
Try to change the _renderHeaderCell to:
_renderHeaderCell: function (node) {
const $th = this._super.apply(this, arguments);
if (node.tag === 'button_group' && node.children && node.children[0].attrs.class === "custom_identifier"){
$th.text(node.children[0].attrs.string)
.attr('tabindex', -1);
}
return $th;
},

how to use page scroll to id plugin on page template in wordpress?

I have homepage which is created by using multiple small template pages in wordpress. I have set menus on it . now i want to go on particular section/ template using menu. like if i press contact menu button then it should go smoothly downwards of homepage where the contact template has been called. I am using "Page scroll to id" plugin of wordpress but its not working. I have also seen that this plugin work when the page is created by dashoard page. Please help me , how can i navigate to my template page/section using this plugin. If any other plugin is there , please tell me about it . i will try to use that too.
Thanks
To create smooth scroll on link click follow the below steps :
Step 1: Add section ids in menu href including #section1 from admin section Appearance >> Menu .
Step 2: Create section or div with id name section1.
<div id="section1"></div>
Step 3: Paste the below code under your custom js file.
$(document).ready(function(){
// Add smooth scrolling to all links
$("a").on('click', function(event) {
// Make sure this.hash has a value before overriding default behavior
if (this.hash !== "") {
// Prevent default anchor click behavior
event.preventDefault();
// Store hash
var hash = this.hash;
// Using jQuery's animate() method to add smooth page scroll
// The optional number (800) specifies the number of milliseconds it takes to scroll to the specified area
$('html, body').animate({
scrollTop: $(hash).offset().top
}, 800, function(){
// Add hash (#) to URL when done scrolling (default click behavior)
window.location.hash = hash;
});
} // End if
});
});
I hope it will helps you.

Wordpress - Changing Background-Color of Multiple Divs

I have multiple DIV elements on my page with the class "grid-item-container"
I want to make the background-color of each one different. I will set an array of 5 different colours that can be set.
There is a script available here that seems to do this: http://jsfiddle.net/VXG36/1/
$(document).ready(function() {
var randomColors = ["green","yellow","red","blue","orange","pink","cyan"];
$(".random").each(function(index) {
var len = randomColors.length;
var randomNum = Math.floor(Math.random()*len);
$(this).css("backgroundColor",randomColors[randomNum]);
//Removes color from array so it can't be used again
randomColors.splice(randomNum, 1);
});
});
I cannot however get it to run on my page. Is there something in this script that needs to be amended to make it Wordpress friendly?
Kind regards
Dave
You might wan't to wrap it in something like this:
jQuery(document).ready(function($) {
// Inside of this function, $() will work as an alias for jQuery()
// and other libraries also using $ will not be accessible under this shortcut
});
The jQuery library included with WordPress is set to the noConflict() mode (see wp-includes/js/jquery/jquery.js). This is to prevent compatibility problems with other JavaScript libraries that WordPress can link. Read more about it in Codex here.
Also, change $(.random) to $(.grid-item-container), this targets the class of your div.

Can I enable users on Plone4 to show/hide the Portlet column on-the-fly

The Portlets in Plone are quite handy but I'd like to be able to provide some method to users to be able to temporarily hide/show the portlets column. That is, by clicking a button, the portlets column should collapse and you see the content page in full width. Then clicking again and the portlets panel on the left expands and the main content page width shrinks to accommodate.
I've observed the HTML ID of the portlets column is "portal-column-one" and I tried adding a button to the page that runs javascript to set the visibility property of that element to "hidden" but this seemed to have no effect. I was able to go into Firebug and add style="visibility:hidden;" to the "portal-column-one" element and it had the effect of making the region invisible w/o resizing the page.
I am using Plone 4.1. I have the site configured with navigation portlet on all pages except the main page which has Navigation, Review List and Recent Changes.
So it seems it must be possible to embed some javascript in the page (I was thinking of adding this to the plone.logo page which I've already customized). But I guess its more complicated than the few stabs I've made at it.
Thanks in advance for any advice.
Solution (Thanks to input from Ulrich Schwarz and hvelarde):
The solution I arrived at uses JavaScript to set CSS attributes to show/hide the Portlets Column (Left side) and expand the content column to fill the space the porlets column filled.
I started by customizing the Plone header template to add a link for the user to toggle the view of the Porlets column. I also put the necessary javascript functions in this header.
To customize the header, go to the following page (need to be logged in as Admin of your Plone site):
http://SERVER/SITE/portal_view_customizations/zope.interface.interface-plone.logo
Where:
SERVER is the address and port of your site (e.g. localhost:8080)
SITE is the short name of your Plone Site
To create this page:
Go to Site Setup (as Admin)
Go to Zope Management Interface
Click on "portal_view_customizations"
Click on "plone.logo" (or at least this is where I choose to put the button so it would be located just above the navigation Portlet)
Add the following to the page:
<script>
function getById(id) {
return document.getElementById(id);
}
function TogglePortletsPanel() {
var dispVal = getById('portal-column-one').style.display
if( dispVal == "none") { // Normal display
SetPortletsPanelState("inline");
} else { // Full Screen Content
SetPortletsPanelState("none");
}
}
function SetPortletsPanelState(dispVal) {
var nav = getById('portal-column-one');
var content = getById('portal-column-content');
if( dispVal == "none") { // Normal display
nav.style.display='none';
content.className='cell width-full position-0';
// Set cookie to updated value
setCookie("portletDisplayState","none",365);
} else { // Full Screen Content
nav.style.display='inline';
content.className='cell width-3:4 position-1:4';
// Set cookie to updated value
setCookie("portletDisplayState","inline",365);
}
}
function InitializePortletsPanelState() {
var portletDisplayState=getCookie("portletDisplayState");
//alert("portletDisplayState="+portletDisplayState)
if (portletDisplayState!=null) SetPortletsPanelState(portletDisplayState);
}
function setCookie(c_name,value,exdays) {
//alert(c_name+"="+value);
// cookie format: document.cookie = 'name=value; expires=Thu, 2 Aug 2001 20:47:11 UTC; path=/'
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var exp= ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + escape(value) + exp + "; path=/";
}
function getCookie(c_name) {
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++) {
x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
x=x.replace(/^\s+|\s+$/g,"");
if (x==c_name) return unescape(y);
}
}
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {oldonload(); }
func();
}
}
}
addLoadEvent(InitializePortletsPanelState);
</script>
<a style="font-size:50%;" href="javascript:TogglePortletsPanel();">Toggle Portlets Panel</a>
6. Save the page
Notes:
I got the names of the plone div elements using Firebug.
I also used Firebug to experiment with different settings to speed up prototyping. For example, editing the HTML inline to verify settings do as expected.
There is a slight but of delay until the Left Portlet panel is hidden. This is only obvious on Safari for me (which is probably due to how fast it is) but not on Firefox or IE.
Maybe it's just a matter of setting the right property: you want display:none, not visibility:hidden.
But even then, the content area will probably not reflow automatically, you'll need to (dynamically) change the class on it as well.
Specifically, you'll need to put classes width-full and position-0 on portal-column-content, instead of width-1:2 and position-1:4.
This must be achieved client side by javascript (jquery).
You must first read documentation about the css grid framework used by plone: deco.gs. The website is down so, git clone this repo: https://github.com/limi/deco.gs and open pages in a webbrowser
Note: you just have to change css classes on the containers.
Try adi.fullscreen, it respects Plone's css-structure as Ulrich Schwarz thoughtfully mentioned.

Resources