I am trying to write a selector that spits bunch of custom JS variables. As author uses frames, those variables are not available. But publish seems to fine as there are no frames. How does CQ.WCM or CQ_Analytics objects are available? How I can I achieve the same thing in my selector js.jsp file. I appreciate your detailed response. thank you.
Selector example (/content/xxx/en/home.html, head will generate <script type="text/javascript" src="/content/xxxx/en_US.globalconfig.js"></script>
page/basePage/globalconfig.js.jsp
{code}---------------------
<%@include file="/apps/fishersci/components/shared/global.jsp" %>
<%
%>
var globalCQConfigs = window.globalCQConfigs ||{};
// design path
globalCQConfigs.publicRootDir = "${publicRootDir}";
globalCQConfigs.pageLocale = "${pageLocale}";
globalCQConfigs.localePath = "${localePath}";
---------------------
Solved! Go to Solution.
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Replies
Total Likes
Need little more clarification please. Objects are generated in JSP as JS. is it possible to make a client lib thats going to be generated on the fly?
Views
Replies
Total Likes
bswx wrote...
Need little more clarification please. Objects are generated in JSP as JS. is it possible to make a client lib thats going to be generated on the fly?
<script type="text/javascript" src="<%= clientlibResource.getPath() %>.<%= "genarate_clientlib_as_per_your_requirement" %>.js"></script>
Views
Replies
Total Likes
Sham I appreciate your time. Still not clear actual solution though.
Say the on page template selector is globalCQConfigs.js.jsp i.e <head> contains .. <script tag calls globalCQConfigs.js> thus auto generates the js file. (/apps/xxxx/components/page/globalCQConfigs.js.jsp)
Generating script tag is not the problem, but how can we make the selector js.jsp file into clientlib?
Views
Replies
Total Likes
bswx wrote...
Generating script tag is not the problem, but how can we make the selector js.jsp file into clientlib?
You can't. A client library is essentially static. What you want is to dynamically generate JavaScript, which is perfectly fine, just has nothing to do with clientlibs.
Your original post mentioned something about frames, which seems to be a problem specific to your JavaScript (and not how it is generated). What do you mean by "those variables are not available"? "Available" in what context?
Views
Replies
Total Likes
Problem : I want to make some global values available to Javascripts, for example WCMMode is available using CQ.WCM.WCMMode. But these variables will be be coming from various SS objects, configs etc, I want to make that available for client side scripts so they can accessible to perform some tasks.
Attempted Solution: So using selectors I know how to generate a JS file with values as I need from server side as above. But these are accessible on publish side as there are no frames. Because this script is inside a frame in author, the other scripts wont be able to access them. But I see CQ.WCM.WCMMode available in author. Hope this clarifies ..
Thank you for your help!.
Views
Replies
Total Likes
bswx wrote...
Problem : I want to make some global values available to Javascripts, for example WCMMode is available using CQ.WCM.WCMMode. But these variables will be be coming from various SS objects, configs etc, I want to make that available for client side scripts so they can accessible to perform some tasks.
Attempted Solution: So using selectors I know how to generate a JS file with values as I need from server side as above. But these are accessible on publish side as there are no frames. Because this script is inside a frame in author, the other scripts wont be able to access them. But I see CQ.WCM.WCMMode available in author. Hope this clarifies ..
Thank you for your help!.
I guess I'm not understanding what the issue is with the frames. The "other scripts" should be in the same frame (whether on author or publish), so there shouldn't be an issue. And again, the fact that the JavaScript is dynamically generated isn't relevant to the browser.
The only thing which would be different between author and publish is that in author (from a script running in the site page), window.top != window. So if you do have a script which does window.top.globalCQConfigs, that wouldn't work. But I don't see why you would be doing this.
Regards,
Justin
Views
Replies
Total Likes
Views
Likes
Replies