BLOG: Web Content Management

Welcome to Oshyn’s Web Content Management Blog where our experts discuss the latest developments and best practices in the Content Management industry with a focus on several leading platforms: Drupal, EPiServer, Jahia, Open Text and Sitecore.

Web 2.0 and Jahia: Using jQuery in Jahia

David Yanez... - Monday, January 18, 2010

Want to learn how to implement a jQuery plugin as a module in Jahia? First, we’ll add the same module twice in a page but passing different parameters to each module to change the appearance of both. Then we’ll implement AJAX in one module. Let’s imagine we are building a site in Jahia to sell products. The common things we find in a product page are product images, product descriptions, advertisements, etc.  For our product page we are adding a rating module that will allow us to show our score of the product, scores from another source (e.g. Other Web Site or Magazine) and let users rate the product and show their score too.We built a jQuery plugin that will allow us to display rating results. Plus letting the website visitor to rate the product in a simple way.In the image below we see how the plugin can show information, and how it lets the user rate the product using the slider. It is simple to show the rating module like in the second example.

To make the plugin work you need the following:

Include jQuery, uirateit plugin js and its css file.

<script type="text/javascript" src="jquery.js"></script>

<script type="text/javascript" src="uirateit.js"></script>

<link rel="stylesheet" type="text/css" href="uirateit.css" />

 

Then build the html with the next structure.

<div class="ratemodule" style="width:300px; height:133px; ">

<ul class="score">

<li class="bigscore">

<span>MySite.com Score</span>

<span>8.5</span>

<span>Awesome</span>

</li>

<li class="smallscore">

<span>8</span>

<span>Critic Score</span>

<span>32 review</span>

</li>

<li class="smallscore">

<span>8.5</span>

<span>User Score</span>

<span>32 review</span>

</li>

<li class="yourscore">

<span>NA</span>

<span>User Score</span>

<span>please slide to rate</span>

</li>
</
ul>

</
div>

and finally

<script type="text/javascript">

$(document).ready(function({barwidth: 191}){

$('. ratemodule ').uirateit();

});

</script>

Now we’ll implement the same plugin as a module in Jahia, so Content Editors can add the module to product pages customizing the view with different parameters.

In your definitions.cnd file add the next lines:

<ajax = 'oshyn.com/jahia/ajax/nt/1.0'>

[name_of_templates:rateModule] > jnt:container

    smallText siteMessage

    smallText siteRate

    smallText firstHeadline

    smallText firstMessage

    smallText firstRate

    smallText secondHeadline

    smallText secondMessage

    smallText secondRate

    smallText userHeadline

    smallText userMessage

    smallText moduleWidth

    smallText webSiteName

    smallText nameClass

     

[name_of_templates:moduleBox] > jnt:box

      containerList rateModuleList (ajax:rateModule)

     

[name_of_templates:home] > jnt:page

      containerList columnBox (jnt:box[availableTypes="jnt:IframeBox,ajax:moduleBox"])

[name_of_templates:rateModule] > jnt:container will[km1]  be our new module that inherits from container. We declare all the fields that the editor would be able to modify in the template.

After that we add the module container to our template

<template:boxList name="columnBox" id="columnBox" actionMenuNamePostFix="boxes" actionMenuNameLabelKey="boxes">

<template:container id="moduleBox" actionMenuNamePostFix="box" actionMenuNameLabelKey="box.update" cache="false" >
<template:box displayTitle="true" id="columnBox" onError="${jahia.requestInfo.normalMode ? 'hide' : 'default'}"/>
</template:container>
</template:boxList>

Finally we must create a display for our module following the Jahia naming convention.

Create a file under common/box/display/moduleBoxDisplay.jsp with next code.

<template:containerList name="rateModuleList" id="rates" actionMenuNamePostFix="rates" actionMenuNameLabelKey="rates">

<template:container id="rateModule" cache="off" actionMenuNamePostFix="rate" actionMenuNameLabelKey="rate.update">

<div class='<template:field name="nameClass"/>' style="width:300px; height:133px; position:relative; font-family:Arial, Helvetica, sans-serif;margin-bottom:20px;">

<ul class="score">

<li class="bigscore">

<span><template:field name="webSiteName"/></span>

<span><template:field name="siteRate"/></span>

<span><template:field name="siteMessage"/></span>

</li>

<li class="smallscore">

<span><template:field name="firstRate"/></span>

<span><template:field name="firstHeadline"/></span>

<span><template:field name="firstMessage"/></span>

</li>

<li class="smallscore">

<span><template:field name="secondRate"/></span>

<span><template:field name="secondHeadline"/></span>

<span><template:field name="secondMessage"/></span>

</li>

<li class="yourscore">

<span>NA</span>

<span><template:field name="userHeadline"/></span>

<span><template:field name="userMessage"/></span>

</li>

</ul>

</div>


<script type="text/javascript">

 $(document).ready(function(){

$('.').uirateit({

barwidth: <template:field name="moduleWidth"/>

}, function(){

});

});

</script>

</template:container>

</template:containerList>

           

As soon as you deploy the templates on Jahia, you will be able to add the new module.


and have something like this on your site:

ajax rotator
Recent Posts

RSS feeds
Tag cloud
GIS print IT Investment content mangement development url keyword selection cloud web services web marketing Solr Marketing Automation open text cms higher education IIS mashups mashup mashware web design los angeles reddot white paper content management los angeles Visual Studio reddot jahia wcm open text .net social 2.0 tools reddot whitepaper modules Maven open text web solutions OO Development design patterns google search appliance Active Directory html portal content management white paper web evolution profile tab asp open text management server Sharepoint VB facebook app, OS 3.0, three20 Web development opentext Velocity performance release management open text liveserver lead management google analytics sitecore online marketing suite, online marketing suite Navigation ubuntu Sitecore Flash jsp Business Users software design dynament inbound marketing facebook social media lead generation enterprise friendly url drools content management systems oms web3.0 Acquia google maps ASP.NET MVC MVC licencing cms los angeles, content management los angeles, web development los angeles, website design los angeles, web design los angeles, sitecore meetup, sitecore user group content management whitepaper search suggest portlets Sitecore Active Directory industry challenges profile box Dynamic Data linux ajax LiveServer ipc fbml Drupal ajax push Visual Basic design sitecore devices template design content authors jahia cms sales 2.0 tuckey plugin LS GSA twitter cms white paper JSR-168 jquery, jquery plugin data access open-source keywords mobile project management scalability LDAP web development los angeles web content management iphone code design sitecore user group sitecore layout website design los angeles google CTA deployment missing images icefaces liferay open source sitecore meetup CMS reddot higher education sitecore oms CRM social network CMS usability editing content WCM Design Patterns Live Server configuration management wcm CMS Training css google appEngine content authoring redundant database structure HubSpot lucene Delivery Server ASP.NET tuning java web design oshyn VPP php5 javascript rdbs call to action reddot cms higher education EPiServer presentation layer cms los angeles patterns community applications SMM Jahia online marketing architecture web marketing for dummies reddot cms integration open text delivery server new sites consulting target dynament SEO EPiServer Active Directory web2.0 webcomponent marketing search engine cms whitepaper cloud computing ui jquery facebook developers
2010 Copyright Oshyn. All rights reserved.