Liferay.com

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 = A.one('#openServeyWindow').getAttribute('href');
var jsAtt = sessionId;
A.one('#openServeyWindow').setAttribute('href', hrefDefaultVal+jsAtt);

A.one('#openServeyWindow').setAttribute('onclick', "saveEntry('${count}','${newSessionIdPK}','${recentSessionIdPK}','"+buttonClicked+"' );");

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

closeRmiWindow();
window.location.replace('${lastAccessedPageUrl}'); // to redirect to previous page
},
['node-event-simulate']
);

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