Tuesday, November 12, 2013

Using Liferay.provide - to add global java script function

An example function

Liferay.provide(window, 'existingUser', function(sessionId, buttonClicked) {
var A = AUI();

var hrefDefaultVal ='#openServeyWindow').getAttribute('href');
var jsAtt = sessionId;'#openServeyWindow').setAttribute('href', hrefDefaultVal+jsAtt);'#openServeyWindow').setAttribute('onclick', "saveEntry('${count}','${newSessionIdPK}','${recentSessionIdPK}','"+buttonClicked+"' );");

if (navigator.appName == 'Microsoft Internet Explorer') {// as AUI simulate is not working in IE, handling through
var elem = document.getElementById("openServeyWindow");
if (typeof elem.onclick == "function") {
}else{ // other browsers
// click working fine with below command for IE, redirect is not happening'#openServeyWindow').simulate('click');

window.location.replace('${lastAccessedPageUrl}'); // to redirect to previous page

Somehow this works well compared to (it seems because of lazy loading aui does with aui:script use attribute)
// whole function code from above

No comments:

Post a Comment