<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Client Libraries Archives - Sourced Code</title>
	<atom:link href="https://sourcedcode.com/blog/category/aem/client-libraries/feed" rel="self" type="application/rss+xml" />
	<link>https://sourcedcode.com</link>
	<description>AEM Blog Made Just for You.</description>
	<lastBuildDate>Fri, 08 Dec 2023 03:23:14 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.4.8</generator>

<image>
	<url>https://sourcedcode.com/wp-content/uploads/2019/09/cropped-favicon-32x32.png</url>
	<title>Client Libraries Archives - Sourced Code</title>
	<link>https://sourcedcode.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Execute JavaScript in the Author Environment for AEM Components AEM 6.5+</title>
		<link>https://sourcedcode.com/blog/aem/execute-javascript-in-the-author-environment-for-aem-components-aem-6-5</link>
					<comments>https://sourcedcode.com/blog/aem/execute-javascript-in-the-author-environment-for-aem-components-aem-6-5#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Fri, 08 Dec 2023 00:47:15 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Client Libraries]]></category>
		<category><![CDATA[JavaScript]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=6322</guid>

					<description><![CDATA[<p>To execute JavaScript specifically for the AEM Author Environment, developers can add a condition to check for a Cookie stored in the browser, &#8216;cq-authoring-mode&#8217;; this works on AEM 6.5+. When the Cookie of &#8216;cq-authoring-mode&#8217; exists, then execute JavaScript during authoring on the editor.html. Only in the Author Environment, the Cookie, &#8216;cq-authoring-mode&#8217;, will exist. Below is [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/execute-javascript-in-the-author-environment-for-aem-components-aem-6-5">Execute JavaScript in the Author Environment for AEM Components AEM 6.5+</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>To execute JavaScript specifically for the AEM <strong>Author Environment</strong>, developers can add a condition to check for a Cookie stored in the browser, &#8216;cq-authoring-mode&#8217;; this works on AEM 6.5+. When the Cookie of <strong class="code-highlight-primary">&#8216;cq-authoring-mode&#8217;</strong> exists, then execute JavaScript during authoring on the editor.html. Only in the Author Environment, the Cookie, <strong class="code-highlight-primary">&#8216;cq-authoring-mode&#8217;</strong>, will exist. Below is a code snippet demonstrating how to check for the existence of the <strong class="code-highlight-primary">&#8216;cq-authoring-mode&#8217;</strong> key in the cookies and gracefully exit the JavaScript logic if the key is found (targeting only the Author Environment, which means run-mode=author):</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #006600; font-style: italic;">// Import the necessary modules</span><br />
<span style="color: #FF0000;">import</span> Cookies from <span style="color: #3366CC;">'js-cookie'</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">// Check if the 'cq-authoring-mode' key exists in cookies</span><br />
<span style="color: #000066; font-weight: bold;">const</span> authoringModeCookie <span style="color: #339933;">=</span> Cookies.<span style="color: #000066; font-weight: bold;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'cq-authoring-mode'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>authoringModeCookie<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #006600; font-style: italic;">// Exit the JavaScript logic if the key is found</span><br />
&nbsp; console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Authoring mode cookie found. Exiting JavaScript logic.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #006600; font-style: italic;">// Continue with your JavaScript logic for AEM Author Environment</span><br />
&nbsp; console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Authoring mode cookie not found. Proceeding with JavaScript logic.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #006600; font-style: italic;">// Add your custom functionality here</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>In this example, we use the &#8216;js-cookie&#8217; library to handle cookies in a simplified manner. The Cookies.get(<strong class="code-highlight-primary">&#8216;cq-authoring-mode&#8217;</strong>) function retrieves the value of the <strong class="code-highlight-primary">&#8216;cq-authoring-mode&#8217;</strong> key from cookies. If the key exists, the JavaScript logic exits gracefully. Otherwise, you can proceed with implementing your custom functionality.</p>
<hr class="spacer-large">
<h2>Benefits of Customized JavaScript in AEM Editor</h2>
<ol>
<li><strong>Context-Aware Functionality: </strong>By checking for specific conditions, such as the presence of a key in cookies, developers can implement context-aware functionality tailored to the AEM authoring environment.</li>
<li><strong>Enhanced Authoring Experience: </strong>Custom JavaScript allows for the augmentation of the authoring experience by introducing features that streamline workflows and improve usability for content authors.</li>
<li><strong>Graceful Handling of Conditions:</strong> Checking for the existence of keys in cookies enables developers to gracefully handle conditions, ensuring that the JavaScript logic behaves appropriately in different scenarios.</li>
</ol>
<hr class="spacer-large">
<h2>Conclusion</h2>
<p>Mastering the art of writing JavaScript for the AEM Author Environment empowers developers to create a tailored experience purely for the authoring environment. By incorporating checks for specific conditions, such as cookie existence, developers can introduce intelligent and context-aware functionalities that enhance the content creation process. The provided code snippet serves as a starting point for customizing JavaScript in the AEM Author Environment, offering a foundation for further innovation and optimization.</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/execute-javascript-in-the-author-environment-for-aem-components-aem-6-5">Execute JavaScript in the Author Environment for AEM Components AEM 6.5+</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/execute-javascript-in-the-author-environment-for-aem-components-aem-6-5/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Race Conditions with window.Granite?.I18n</title>
		<link>https://sourcedcode.com/blog/aem/race-conditions-with-window-granite-i18n</link>
					<comments>https://sourcedcode.com/blog/aem/race-conditions-with-window-granite-i18n#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Wed, 21 Sep 2022 01:17:24 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Client Libraries]]></category>
		<category><![CDATA[JavaScript]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=3815</guid>

					<description><![CDATA[<p>We have created a JavaScript micro-frontend in VueJS to handle a new feature for our website. The JavaScript micro-frontend is set up nicely inside of a maven module. Along with it&#8217;s own Node Package Manager configuration, we used the aem-clientlib-generator to generate a client library under /apps/sourcedcode/clientlibs/micro-frontend. Within our VueJS application, we have a utility [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/race-conditions-with-window-granite-i18n">Race Conditions with window.Granite?.I18n</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>We have created a JavaScript micro-frontend in VueJS to handle a new feature for our website. The JavaScript micro-frontend is set up nicely inside of a maven module. Along with it&#8217;s own Node Package Manager configuration, we used the <a href="https://www.npmjs.com/package/aem-clientlib-generator" rel="noopener" target="_blank">aem-clientlib-generator</a> to generate a client library under /apps/sourcedcode/clientlibs/micro-frontend. </p>
<p>Within our VueJS application, we have a utility named i18n.js, the file looks like this (code below). Throughout application, we will call this util i18n(function) to get values from our i18n AEM dictionary.</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #FF0000;">export</span> <span style="color: #000066; font-weight: bold;">default</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; i18n<span style="color: #009900;">&#40;</span>id<span style="color: #339933;">,</span> params<span style="color: #339933;">,</span> notes<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>window.<span style="color: #660066;">Granite</span><span style="color: #339933;">?</span>.<span style="color: #660066;">I18n</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> window.<span style="color: #660066;">Granite</span>.<span style="color: #660066;">I18n</span>.<span style="color: #000066; font-weight: bold;">get</span><span style="color: #009900;">&#40;</span>id<span style="color: #339933;">,</span> params<span style="color: #339933;">,</span> notes<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> id<span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p><strong>When we test out the micro-frontend, we noticed that sometimes the window.Granite, AEM global object, is intermittently working; sometimes the window object is valid/not, so dictionary values are loaded, and sometimes they are not. Why window.Granite is sometimes undefined? Well, this looks like a race condition issue.</strong></p>
<div class="mention-block">
<strong>What is a race condition?</strong><br />
In short, a race condition occurs when a device or system attempts to do two or more actions at the same time, but the actions must be performed in the proper sequence to be performed correctly.<br />
</strong>
</div>
<p>How can we ensure window.Granite is loaded first before our application is loaded next? In the next section let&#8217;s look at the different ways to see how we can do this.</p>
<hr/>
<p><strong>Solutions</strong></p>
<ol>
<li><a href="#manually">Manually Invoking the i18n.js from /libs/clientlibs/granite/utils/source/I18n.js</a></li>
<li><a href="http://via-clientlibrary">Include the granite.utils as a dependency</a></li>
</ol>
<hr class="spacer-large" />
<div style="text-align:center; margin-bottom: 100px;">
<h2>Solutions</h2>
<p>In this section of the blog, you will find two solutions to this problem.
</p></div>
<h3 id="manually">1. Manually Invoking the i18n.js from /libs/clientlibs/granite/utils/source/I18n.js</h3>
<p>From the page template that your micro-frontend is embedded, you can just call the Adobe core Granite utils > i18n.js before your custom code, like the code provided below. Viewing the source code of your HTML page should look something like this; where the i18n.js is loaded first, and then your application is loaded secondly. Using the proxy method for accessing client libraries, you can serve /libs/clientlibs/granite/utils/source/I18n.js with /etc.clientlibs/clientlibs/granite/utils.js.</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span> src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;/etc.clientlibs/clientlibs/granite/utils.js&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span> src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;/etc.clientlibs/sourcedcode/clientlibs/micro-frontend.min.js&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<hr class="spacer-larger" />
<h3 id="via-clientlibrary">2. Include the <strong>granite.utils</strong> as a dependency</h3>
<p>.</p>
<p>Simply ensure that your client library has a dependency for the <strong>granite.utils</strong>.</p>
<div class="mention-block">Please be aware that if you are planning to this client library approach, you are actually going to load unwanted JavaScripts apart of your page load. This includes: Sling.js, Util.js, HTTP.js, I18n.js, TouchIndicator.js, OptOutUtil.js, and the init.js (according to the <a href="http://localhost:4502/crx/de/index.jsp#/libs/clientlibs/granite/utils/js.txt" rel="noopener" target="_blank">js.txt</a> in the Adobe AEM core library). If all you want is the i18n.js, then you should try out solution #1.</div>
<p><em>In line:6, notice how the a dependency have been added.</em></p>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;jcr:root</span> <span style="color: #000066;">xmlns:cq</span>=<span style="color: #ff0000;">&quot;http://www.day.com/jcr/cq/1.0&quot;</span> <span style="color: #000066;">xmlns:jcr</span>=<span style="color: #ff0000;">&quot;http://www.jcp.org/jcr/1.0&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;cq:ClientLibraryFolder&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">allowProxy</span>=<span style="color: #ff0000;">&quot;{Boolean}true&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">categories</span>=<span style="color: #ff0000;">&quot;[sourcedcode.micro-frontend]&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">dependencies</span>=<span style="color: #ff0000;">&quot;[granite.utils]&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></div></td></tr></tbody></table></div>
<p>While in this article, we have mentioned that we are using the <a href="https://www.npmjs.com/package/aem-clientlib-generator" rel="noopener" target="_blank">aem-clientlib-generator</a> for our micro-frontend, so to install it, it would be as simple as adding a new property in the clientlib.config.js, and would be something that looks like this: <strong>line:33</strong></p>
<div class="code-500">
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000066; font-weight: bold;">const</span> path <span style="color: #339933;">=</span> require<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'path'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">const</span> BUILD_DIR <span style="color: #339933;">=</span> path.<span style="color: #660066;">join</span><span style="color: #009900;">&#40;</span>__dirname<span style="color: #339933;">,</span> <span style="color: #3366CC;">'dist'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000066; font-weight: bold;">const</span> CLIENTLIB_DIR <span style="color: #339933;">=</span> path.<span style="color: #660066;">join</span><span style="color: #009900;">&#40;</span><br />
&nbsp; __dirname<span style="color: #339933;">,</span><br />
&nbsp; <span style="color: #3366CC;">'..'</span><span style="color: #339933;">,</span><br />
&nbsp; <span style="color: #3366CC;">'ui.apps'</span><span style="color: #339933;">,</span><br />
&nbsp; <span style="color: #3366CC;">'src'</span><span style="color: #339933;">,</span><br />
&nbsp; <span style="color: #3366CC;">'main'</span><span style="color: #339933;">,</span><br />
&nbsp; <span style="color: #3366CC;">'content'</span><span style="color: #339933;">,</span><br />
&nbsp; <span style="color: #3366CC;">'jcr_root'</span><span style="color: #339933;">,</span><br />
&nbsp; <span style="color: #3366CC;">'apps'</span><span style="color: #339933;">,</span><br />
&nbsp; <span style="color: #3366CC;">'sourcedcode'</span><span style="color: #339933;">,</span><br />
&nbsp; <span style="color: #3366CC;">'clientlibs'</span><br />
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">const</span> libsBaseConfig <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; allowProxy<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span><br />
&nbsp; serializationFormat<span style="color: #339933;">:</span> <span style="color: #3366CC;">'xml'</span><span style="color: #339933;">,</span><br />
&nbsp; cssProcessor<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'default:none'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'min:none'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><br />
&nbsp; jsProcessor<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'default:none'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'min:none'</span><span style="color: #009900;">&#93;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">// Config for `aem-clientlib-generator`</span><br />
module.<span style="color: #660066;">exports</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; context<span style="color: #339933;">:</span> BUILD_DIR<span style="color: #339933;">,</span><br />
&nbsp; clientLibRoot<span style="color: #339933;">:</span> CLIENTLIB_DIR<span style="color: #339933;">,</span><br />
&nbsp; libs<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; ...<span style="color: #660066;">libsBaseConfig</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; name<span style="color: #339933;">:</span> <span style="color: #3366CC;">'micro-frontend'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; categories<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'sourcedcode.micro-frontend'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; dependencies<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'granite.utils'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; assets<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; js<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cwd<span style="color: #339933;">:</span> <span style="color: #3366CC;">'clientlib-site'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; files<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'**/*.js'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; flatten<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; css<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cwd<span style="color: #339933;">:</span> <span style="color: #3366CC;">'clientlib-site'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; files<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'**/*.css'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; flatten<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// Copy all other files into the `resources` ClientLib directory</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; resources<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cwd<span style="color: #339933;">:</span> <span style="color: #3366CC;">'clientlib-site'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; files<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'**/*.*'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; flatten<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ignore<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'**/*.js'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'**/*.css'</span><span style="color: #009900;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #009900;">&#93;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
</div>
<div class="mention-block">
<strong>Still! My AEM i18n Not Showing Translations!</strong><br />
Sometimes after deploying new dictionary keys and values in your AEM platform, you will realize, in rare occasions, you&#8217;re dictionary values are not loading as expected. Have no fear, I have created an article here for how to solve this problem. Click here to learn how to refresh the <a href="/blog/aem/aem-i18n-not-showing-translations">Apache Sling I18N translation engine</a>.
</div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/race-conditions-with-window-granite-i18n">Race Conditions with window.Granite?.I18n</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/race-conditions-with-window-granite-i18n/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>What are AEM ExtraClientlibs?</title>
		<link>https://sourcedcode.com/blog/aem/what-are-aem-extraclientlibs</link>
					<comments>https://sourcedcode.com/blog/aem/what-are-aem-extraclientlibs#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Tue, 20 Sep 2022 04:51:05 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Client Libraries]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Touch UI]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=3796</guid>

					<description><![CDATA[<p>When dealing with cq:ClientLibraryFolder (node type), you may have come across a property called extraClientlibs. What are extraClientlibs and how does it work? As you may recall, when you want to add custom functionality or styling to the Touch Dialogues (in edit author mode, editor.html), we must include cq.authoring.editor.sites.page as a dependency and cq.authoring.editor.sites.page.hook as [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/what-are-aem-extraclientlibs">What are AEM ExtraClientlibs?</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>When dealing with cq:ClientLibraryFolder (node type), you may have come across a property called extraClientlibs. What are extraClientlibs and how does it work?</p>
<p>As you may recall, when you want to add custom functionality or styling to the Touch Dialogues (in edit author mode, editor.html), we must include cq.authoring.editor.sites.page as a dependency and cq.authoring.editor.sites.page.hook as a category to our client library&#8217;s configuration. The configuration would look something like this:</p>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span><br />
<span style="color: #000000; font-weight: bold;">&lt;jcr:root</span> <span style="color: #000066;">xmlns:cq</span>=<span style="color: #ff0000;">&quot;http://www.day.com/jcr/cq/1.0&quot;</span> <span style="color: #000066;">xmlns:jcr</span>=<span style="color: #ff0000;">&quot;http://www.jcp.org/jcr/1.0&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;cq:ClientLibraryFolder&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">dependencies</span>=<span style="color: #ff0000;">&quot;[cq.authoring.editor.sites.page]&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">categories</span>=<span style="color: #ff0000;">&quot;[cq.authoring.editor.sites.page.hook]&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></div></td></tr></tbody></table></div>
<p><a href="https://sourcedcode.com/wp-content/uploads/2022/09/cq.authoring.editor.sites_.page_.click_.png"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2022/09/cq.authoring.editor.sites_.page_.click_.png" alt="Diagram of how the ccq.authoring.editor.sites will be triggered." width="100%" class="alignnone size-full wp-image-3801" srcset="https://sourcedcode.com/wp-content/uploads/2022/09/cq.authoring.editor.sites_.page_.click_.png 1638w, https://sourcedcode.com/wp-content/uploads/2022/09/cq.authoring.editor.sites_.page_.click_-300x116.png 300w, https://sourcedcode.com/wp-content/uploads/2022/09/cq.authoring.editor.sites_.page_.click_-1024x395.png 1024w, https://sourcedcode.com/wp-content/uploads/2022/09/cq.authoring.editor.sites_.page_.click_-768x296.png 768w, https://sourcedcode.com/wp-content/uploads/2022/09/cq.authoring.editor.sites_.page_.click_-1536x593.png 1536w, https://sourcedcode.com/wp-content/uploads/2022/09/cq.authoring.editor.sites_.page_.click_-600x232.png 600w" sizes="(max-width: 1638px) 100vw, 1638px" /></a></p>
<p>This configuration above will evoke the client library every time the Touch UI dialogue is triggered, for all components. Illustrated above, from the author (editor.html), clicking on any component throughout the entire AEM platform, will invoke the client library.</p>
<p><strong>Benefits of using cq.authoring.editor.sites.page:</strong></p>
<ol>
<li>Client libraries created like this will be invoked for all components (when the Touch UI is open)</li>
</ol>
<hr class="spacer-large" />
<p><strong>But however, what happens if you only want your custom functionality or styling to be only called by ONE component? Well, we use the extraClientlibs property from the component&#8217;s Touch UI dialogue.</strong></p>
<p><a href="https://sourcedcode.com/wp-content/uploads/2022/09/my.example.clientlib.calls_.png"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2022/09/my.example.clientlib.calls_.png" alt="Diagram of how the extraClientlibs will be triggered." width="100%" height="451" class="alignnone size-full wp-image-3803" srcset="https://sourcedcode.com/wp-content/uploads/2022/09/my.example.clientlib.calls_.png 1452w, https://sourcedcode.com/wp-content/uploads/2022/09/my.example.clientlib.calls_-300x93.png 300w, https://sourcedcode.com/wp-content/uploads/2022/09/my.example.clientlib.calls_-1024x318.png 1024w, https://sourcedcode.com/wp-content/uploads/2022/09/my.example.clientlib.calls_-768x239.png 768w, https://sourcedcode.com/wp-content/uploads/2022/09/my.example.clientlib.calls_-600x186.png 600w" sizes="(max-width: 1452px) 100vw, 1452px" /></a></p>
<p>Illustrated above, you will notice that adding String[] extraClientlibs to the cq:dialog (root node) of the component, the client library will only be invoked, only targeting the Touch UI dialogue that is associated to a specific component.</p>
<p><strong>Benefits of using extraClientlibs:</strong></p>
<ol>
<li>Touch UI will only invoke the targeted client library that is configured.</li>
<li>Client libraries can be created to be specifically used for a particular component.</li>
</ol>
<p><strong>Example of usage of extraClientlibs in line:6</strong></p>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span><br />
<span style="color: #000000; font-weight: bold;">&lt;jcr:root</span> <span style="color: #000066;">xmlns:sling</span>=<span style="color: #ff0000;">&quot;http://sling.apache.org/jcr/sling/1.0&quot;</span> <span style="color: #000066;">xmlns:granite</span>=<span style="color: #ff0000;">&quot;http://www.adobe.com/jcr/granite/1.0&quot;</span> <span style="color: #000066;">xmlns:cq</span>=<span style="color: #ff0000;">&quot;http://www.day.com/jcr/cq/1.0&quot;</span> <span style="color: #000066;">xmlns:jcr</span>=<span style="color: #ff0000;">&quot;http://www.jcp.org/jcr/1.0&quot;</span> <span style="color: #000066;">xmlns:nt</span>=<span style="color: #ff0000;">&quot;http://www.jcp.org/jcr/nt/1.0&quot;</span><br />
&nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; <span style="color: #000066;">jcr:title</span>=<span style="color: #ff0000;">&quot;Component's Granite UI&quot;</span><br />
&nbsp; <span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;cq/gui/components/authoring/dialog&quot;</span><br />
&nbsp; <span style="color: #000066;">extraClientlibs</span>=<span style="color: #ff0000;">&quot;[my.custom.clientlib]&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">&lt;content</span><br />
&nbsp; &nbsp; <span style="color: #000066;">granite:class</span>=<span style="color: #ff0000;">&quot;cmp-teaser__editor cmp-image__editor&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/coral/foundation/container&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;items</span> <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;tabs</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/coral/foundation/tabs&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;items</span> <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;layout</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">jcr:title</span>=<span style="color: #ff0000;">&quot;Layout&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/coral/foundation/container&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">margin</span>=<span style="color: #ff0000;">&quot;{Boolean}true&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">sling:orderBefore</span>=<span style="color: #ff0000;">&quot;actions&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;items</span> <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;columns</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/coral/foundation/fixedcolumns&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">margin</span>=<span style="color: #ff0000;">&quot;{Boolean}true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;items</span> <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;column</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/coral/foundation/container&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;items</span> <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;layout</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/coral/foundation/form/select&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">fieldLabel</span>=<span style="color: #ff0000;">&quot;Layout&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;./layout&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
...</div></td></tr></tbody></table></div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/what-are-aem-extraclientlibs">What are AEM ExtraClientlibs?</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/what-are-aem-extraclientlibs/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Adding Custom Client Library for AEM Author Editor Touch UI</title>
		<link>https://sourcedcode.com/blog/aem/adding-custom-client-library-for-aem-author-editor-touch-ui</link>
					<comments>https://sourcedcode.com/blog/aem/adding-custom-client-library-for-aem-author-editor-touch-ui#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Wed, 22 Jun 2022 19:03:57 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Client Libraries]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Touch UI]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=3484</guid>

					<description><![CDATA[<p>You can use Clientlibs to extend the default implementation and add new functionality while reusing the default functions, objects, and methods. When customizing, you can create your own clientlib under / apps. Specifically, when you want to add CSS or JavaScript to your AEM Author Editor, Touch UI Dialogs, you would want to create a [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/adding-custom-client-library-for-aem-author-editor-touch-ui">Adding Custom Client Library for AEM Author Editor Touch UI</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>You can use Clientlibs  to extend the default implementation and add new functionality while reusing the default functions, objects, and methods. When customizing, you can create your own clientlib under / apps. </p>
<p>Specifically, when you want to add CSS or JavaScript to your AEM Author Editor, Touch UI Dialogs, you would want to create a new client library. Within your clientlib, it must have the required dependencies and categories. </p>
<div class="mention-block">
If you want to learn how to create client libraries for the authoring environment that only target specific components checkout this article <a href="https://sourcedcode.com/blog/aem/what-are-aem-extraclientlibs">here</a>.
</div>
<p><strong>The custom clientlib for AEM authoring must follow these rules:</strong></p>
<p>1. depend on the authoring clientlib cq.authoring.editor.sites.page<br />
2. be part of the appropriate cq.authoring.editor.sites.page.hook category</p>
<hr class="divider-large"/>
<h3>Example</h3>
<p>An example of a custom client library created for AEM authoring would live in this path (below), and must have the .context.xml configured like so.<br />
<strong>/apps/sourcedcode/clientlibs/clientlib-authoring</strong></p>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span><br />
<span style="color: #000000; font-weight: bold;">&lt;jcr:root</span> <span style="color: #000066;">xmlns:cq</span>=<span style="color: #ff0000;">&quot;http://www.day.com/jcr/cq/1.0&quot;</span> <span style="color: #000066;">xmlns:jcr</span>=<span style="color: #ff0000;">&quot;http://www.jcp.org/jcr/1.0&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;cq:ClientLibraryFolder&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">dependencies</span>=<span style="color: #ff0000;">&quot;[cq.authoring.editor.sites.page]&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">categories</span>=<span style="color: #ff0000;">&quot;[cq.authoring.editor.sites.page.hook]&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></div></td></tr></tbody></table></div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/adding-custom-client-library-for-aem-author-editor-touch-ui">Adding Custom Client Library for AEM Author Editor Touch UI</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/adding-custom-client-library-for-aem-author-editor-touch-ui/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>AEM Client Library Debugger &#038; Client Library Test Tool</title>
		<link>https://sourcedcode.com/blog/aem/aem-client-library-debugger-and-client-library-test-tool-blog</link>
					<comments>https://sourcedcode.com/blog/aem/aem-client-library-debugger-and-client-library-test-tool-blog#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Fri, 21 Jan 2022 05:24:24 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Client Libraries]]></category>
		<category><![CDATA[Short Post]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=3368</guid>

					<description><![CDATA[<p>A quick way to validate your AEM client libraries via registered clientlib categories is by using the AEM, out-of-the-box, &#8220;AEM Client Library Debugger Test Tool&#8221;. The tool is very bareboned. When you are on the tool page, you&#8217;ll find a Categories input field. Simply insert your to-be-tested clientlib category value here and press &#8220;submit&#8221;. Your [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-client-library-debugger-and-client-library-test-tool-blog">AEM Client Library Debugger &#038; Client Library Test Tool</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>A quick way to validate your AEM client libraries via registered <strong>clientlib categories</strong> is by using the AEM, out-of-the-box, &#8220;AEM Client Library Debugger Test Tool&#8221;.</p>
<p>The tool is very bareboned. When you are on the tool page, you&#8217;ll find a <strong>Categories</strong> input field. Simply insert your to-be-tested clientlib category value here and press &#8220;submit&#8221;. Your results will show up at the bottom panel. This tool only allows you to test one clientlib category at once.</p>
<p>This tool is great because it will display the &lt;link&gt; and &lt;script&gt; blocks that will be injected into your AEM pages when the client library is being called.</p>
<p>Try it yourself! <a href="http://localhost:4502/libs/granite/ui/content/dumplibs.test.html" rel="noopener" target="_blank">http://localhost:4502/libs/granite/ui/content/dumplibs.test.html</a>.</p>
<p><a class="foobox fbx-link fbx-instance" href="https://sourcedcode.com/wp-content/uploads/2022/01/clientlib-debug-test-tool.png"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2022/01/clientlib-debug-test-tool.png" alt="Example of a query for the &quot;sourcedcode.site&quot; client library category" /></a></p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-client-library-debugger-and-client-library-test-tool-blog">AEM Client Library Debugger &#038; Client Library Test Tool</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/aem-client-library-debugger-and-client-library-test-tool-blog/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Revealing Module Pattern in JavaScript, Jquery, for AEM Client Libraries</title>
		<link>https://sourcedcode.com/blog/aem/revealing-module-pattern-in-javascript-jquery-for-aem-clientlibs</link>
					<comments>https://sourcedcode.com/blog/aem/revealing-module-pattern-in-javascript-jquery-for-aem-clientlibs#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Wed, 12 Jan 2022 03:43:17 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Client Libraries]]></category>
		<category><![CDATA[JavaScript]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=3150</guid>

					<description><![CDATA[<p>This is a reference to the code that I have written. I call this my version of the perfect AEM JavaScript Jquery Component that uses the Revealing Module Pattern. The Revealing Module Pattern in JavaScript is a design pattern that helps us organize our JavaScript in modules. This pattern makes it possible for us not [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/revealing-module-pattern-in-javascript-jquery-for-aem-clientlibs">Revealing Module Pattern in JavaScript, Jquery, for AEM Client Libraries</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>This is a reference to the code that I have written. I call this my version of the perfect AEM JavaScript Jquery Component that uses the Revealing Module Pattern.</p>
<p>The Revealing Module Pattern in JavaScript is a design pattern that helps us organize our JavaScript in modules. This pattern makes it possible for us not to pollute the global scope, and it also ensures that the JavaScript module is running its own code as it should.</p>
<p><strong>In this example, I have incorporated the best practices, and used special naming conventions, so that the code is organized, and set for scalability. </strong></p>
<p><a href="#code-example">Skip to the code Example: Revealing Module Pattern in JavaScript, Jquery</a></p>
<hr class="spacer-large" />
<h3>Explanation of what each line does</h3>
<ol>
<li><strong>line:1</strong> = this is a self invoking function, while passing a parameter of the window.jQuery object; all functions and variables here will be closed off from the outer scope.</li>
<li><strong>line:82</strong> = on window ready, the MyComponent.init(); public method of the MyComponent will be called.</li>
<li>&#8220;use strict&#8221; on line:3 = &#8216;use strict&#8217;; states that the JavaScript code should be executed in &#8216;strict mode&#8217;. This makes it easier to write good and secure JavaScript code.</li>
<li><strong>line:11</strong> = this will be the declaration of the Module.</li>
<li><strong>line:13</strong> = this is where the Constants will be used throughout the Module; here you can include the data-arribute names, HTML element classNames, modifier classnames, etc&#8230;</li>
<li><strong>line:20</strong> = this is where the Module level variables will be saved;
<ul>
<li>variables like $myComponent, with $ as prefix, means that these variables are holding Jquery objects.</li>
<li>variables like pingUrl, with no $, means that these variables are holding standard data.</li>
</ul>
</li>
<li><strong>line:30</strong> = notice the init() function has no under_scores like the other function. No under_score in the function name means that this is a public function.</li>
<li><strong>line:31</strong> = DO NOTHING, do not run any code when the HTML element is NOT on the page.</li>
<li><strong>line:32</strong>-34 = set Jquery objects and other types of data to the variables, declaration on line 20.</li>
<li><strong>line:36</strong> &#038;&#038; line:37 = here we register the open and close button.
<ul>
<li>functions with the under_scores, means that this is a private function.</li>
<li>functions with the without under_scores, means that this is a public function, and public functions should be exposed in line:76, from the return statement.</li>
</ul>
</li>
<li><strong>line:45</strong> = _registerOpenButton(), private function; this cannot be called outside of the Module.</li>
<li><strong>line:57</strong> = _registerCloseButton(), private function; this cannot be called outside of the Module.</li>
<li><strong>line:69</strong> = _makePingCall(), private function; this cannot be called outside of the Module.</li>
<li><strong>line:76</strong> = this return declaration is used to reveal public methods that can be called by the self invoking function. In this case, only the init() function is public.</li>
</ol>
<hr class="spacer-large" />
<h2 id="code-example">Code Example: Revealing Module Pattern in JavaScript, Jquery</h2>
<div class="code-larger">
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">;</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #3366CC;">&quot;use strict&quot;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp;* MyComponent Component<br />
&nbsp; &nbsp; &nbsp;*<br />
&nbsp; &nbsp; &nbsp;* @class MyComponent<br />
&nbsp; &nbsp; &nbsp;* @classdesc initiating javascript for the MyComponent Component.<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">var</span> MyComponent <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">var</span> CONST <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DATA_ATTR_PING_URL<span style="color: #339933;">:</span> <span style="color: #3366CC;">'ping-url'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OPEN_BUTTON_CLASS_NAME<span style="color: #339933;">:</span> <span style="color: #3366CC;">'.cmp-mycomponent__open-btn'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CLOSE_BTN_CLASS_NAME<span style="color: #339933;">:</span> <span style="color: #3366CC;">'.cmp-mycomponent__close-btn'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OPEN_CLASS_NAME<span style="color: #339933;">:</span> <span style="color: #3366CC;">'open'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">var</span> $myComponent <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.cmp-mycomponent'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; $openBtn<span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; $closeBtn<span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; pingUrl<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Initializes the MyComponent<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @public<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">function</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$myComponent.<span style="color: #660066;">length</span> <span style="color: #339933;">&lt;=</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $openBtn <span style="color: #339933;">=</span> $myComponent.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span>CONST.<span style="color: #660066;">OPEN_BUTTON_CLASS_NAME</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $closeBtn <span style="color: #339933;">=</span> $myComponent.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span>CONST.<span style="color: #660066;">CLOSE_BTN_CLASS_NAME</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pingUrl <span style="color: #339933;">=</span> $myComponent.<span style="color: #660066;">data</span><span style="color: #009900;">&#40;</span>CONST.<span style="color: #660066;">DATA_ATTR_PING_URL</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _registerOpenButton<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _registerCloseButton<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Registers open button<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @private<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">function</span> _registerOpenButton<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $closeBtn.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _makePingCall<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $myComponent.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span>CONST.<span style="color: #660066;">OPEN_CLASS_NAME</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Registers close button<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @private<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">function</span> _registerCloseButton<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$closeBtn.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _makePingCall<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $myComponent.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span>CONST.<span style="color: #660066;">OPEN_CLASS_NAME</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Make ping call when open or close action have been made<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @private<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">function</span> _makePingCall<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>pingUrl<span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; url<span style="color: #339933;">:</span> pingUrl<span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; init<span style="color: #339933;">:</span> init<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; MyComponent.<span style="color: #660066;">init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
</div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/revealing-module-pattern-in-javascript-jquery-for-aem-clientlibs">Revealing Module Pattern in JavaScript, Jquery, for AEM Client Libraries</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/revealing-module-pattern-in-javascript-jquery-for-aem-clientlibs/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>With HTL, Pass Data from AEM Backend to Javascript</title>
		<link>https://sourcedcode.com/blog/aem/with-htl-pass-data-from-aem-backend-to-javascript</link>
					<comments>https://sourcedcode.com/blog/aem/with-htl-pass-data-from-aem-backend-to-javascript#comments</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Thu, 24 Sep 2020 22:24:37 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Client Libraries]]></category>
		<category><![CDATA[JavaScript]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=2290</guid>

					<description><![CDATA[<p>When working with AEM components, it&#8217;s very common to pass data from AEM backend to a particular JavaScript event. In this article, we will be focusing on how to pass data from AEM backend using the HTML data-* attribute. HTML data attributes were designed apart of HTML5 where these attributes allow developers to store data, [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/with-htl-pass-data-from-aem-backend-to-javascript">With HTL, Pass Data from AEM Backend to Javascript</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>When working with AEM components, it&#8217;s very common to pass data from AEM backend to a particular JavaScript event. In this article, we will be focusing on how to pass data from AEM backend using the HTML data-* attribute.</p>
<p>HTML data attributes were designed apart of HTML5 where these attributes allow developers to store data, as a string, on HTML elements. With HTL, we can set a value within data attribute&#8217;s value, returned from the AEM backend via Sling Model or HTL Java Use-API or HTL JavaScript Use-API. </p>
<p>The data attribute&#8217;s value set will be data from the AEM backend using the HTL scripting engine and will be apart of the HTML server-side render output. Next, JavaScript will be used to access these values.</p>
<hr class="spacer-large" />
<h2>1. HTML Data Attribute Syntax</h2>
<p><strong>The data attribute is made up of two parts:</strong></p>
<ol>
<li>The attribute name should not contain any uppercase letters, and must be at least one character long after the prefix &#8220;data-&#8220;, example: <em>data-year</em>, <em>data-tax-code</em><em>, data-calendar-point</em>.</li>
<li>The attribute value can be any string.</li>
</ol>
<p>An example of an plain &lt;section&gt; HTML element storing multiple data attributes of values, for the use of your JavaScript logic:</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #009900;">&lt;section </span><br />
<span style="color: #009900;"> &nbsp;<span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;tax-calculator&quot;</span> </span><br />
<span style="color: #009900;"> &nbsp;data-year<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;2020&quot;</span> </span><br />
<span style="color: #009900;"> &nbsp;data-tax-<span style="color: #000066;">code</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;3&quot;</span> </span><br />
<span style="color: #009900;"> &nbsp;data-calender-end-point<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;https://ms.sourcedcode.com/taxcalculator&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span>section&gt;</span></div></td></tr></tbody></table></div>
<p>A HTL implementation:</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">&lt;section data-sly-use.taxcal<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;com.sourcedcode.core.components.models.TaxCalculator&quot;</span><br />
&nbsp; <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;tax-calculator&quot;</span> <br />
&nbsp; data-year<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;${taxcal.year @ context='scriptString'}&quot;</span> <br />
&nbsp; data-tax-<span style="color: #000066;">code</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;${taxcal.taxCode @ context='scriptString'}&quot;</span> <br />
&nbsp; data-calender-end-point<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;${taxcal.endPoint @ context='scriptString'}&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span>section&gt;</div></td></tr></tbody></table></div>
<p>Sling Model implementation:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.sourcedcode.core.components.models</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.adobe.cq.export.json.ExporterConstants</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">lombok.Getter</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.resource.Resource</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.DefaultInjectionStrategy</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.Exporter</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.Model</span><span style="color: #339933;">;</span><br />
<br />
@Model<span style="color: #009900;">&#40;</span>adaptables <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> Resource.<span style="color: #000000; font-weight: bold;">class</span> <span style="color: #009900;">&#125;</span>, <br />
&nbsp; &nbsp; defaultInjectionStrategy <span style="color: #339933;">=</span> DefaultInjectionStrategy.<span style="color: #006633;">OPTIONAL</span><span style="color: #009900;">&#41;</span><br />
@Exporter<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> ExporterConstants.<span style="color: #006633;">SLING_MODEL_EXPORTER_NAME</span>, <br />
&nbsp; &nbsp; extensions <span style="color: #339933;">=</span> ExporterConstants.<span style="color: #006633;">SLING_MODEL_EXTENSION</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> TaxCalculator <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; @Getter<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> year <span style="color: #339933;">=</span> <span style="color: #cc66cc;">2020</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Getter<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> taxCode <span style="color: #339933;">=</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Getter<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> endPoint <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;https://ms.sourcedcode.com/taxcalculator&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<hr class="spacer-large" />
<h2>2. Accessing the Data Attributes with JavaScript</h2>
<p>Retrieving the value(s) of the HTML data attribute(s) in JavaScript is straight forward. You could use getAttribute() with their full HTML name to read these values, but the standard defines a better: a DOMStringMap you can read out via a dataset property.</p>
<p>To retrieve the data attribute(s) through the dataset object, retrieve the property by the part of the attribute name after data- (note that dashes are converted to camelCase).</p>
<p>Example:</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000066; font-weight: bold;">const</span> article <span style="color: #339933;">=</span> document.<span style="color: #660066;">querySelector</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#tax-calculator'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp;<br />
article.<span style="color: #660066;">dataset</span>.<span style="color: #660066;">year</span> <span style="color: #006600; font-style: italic;">// &quot;2020&quot;</span><br />
article.<span style="color: #660066;">dataset</span>.<span style="color: #660066;">taxCode</span> <span style="color: #006600; font-style: italic;">// &quot;3&quot;</span><br />
article.<span style="color: #660066;">dataset</span>.<span style="color: #660066;">calenderEndPoint</span> <span style="color: #006600; font-style: italic;">// &quot;https://ms.sourcedcode.com/taxcalculator&quot;</span></div></td></tr></tbody></table></div>
<p><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Horizontal Preview Ad --><br />
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-9053803095882933"
     data-ad-slot="8658919803"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins><br />
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/with-htl-pass-data-from-aem-backend-to-javascript">With HTL, Pass Data from AEM Backend to Javascript</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/with-htl-pass-data-from-aem-backend-to-javascript/feed</wfw:commentRss>
			<slash:comments>5</slash:comments>
		
		
			</item>
		<item>
		<title>3 Different Ways to Embed Custom Fonts in AEM Sites</title>
		<link>https://sourcedcode.com/blog/aem/3-different-ways-to-embed-custom-fonts-in-aem-sites</link>
					<comments>https://sourcedcode.com/blog/aem/3-different-ways-to-embed-custom-fonts-in-aem-sites#comments</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Wed, 23 Sep 2020 20:30:01 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Client Libraries]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=2248</guid>

					<description><![CDATA[<p>In this article, we will go through three different ways how you can embed custom fonts in an AEM site. Embed Custom Font using Google Fonts, CDN Embed Custom Font using Adobe Fonts, CDN Embed Font via AEM Client Library Static Asset Importing fonts from other services such as Google Fonts or Adobe fonts could [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/3-different-ways-to-embed-custom-fonts-in-aem-sites">3 Different Ways to Embed Custom Fonts in AEM Sites</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In this article, we will go through three different ways how you can embed custom fonts in an AEM site.</p>
<ol>
<li><a href="#embed-custom-font-google-cdn">Embed Custom Font using Google Fonts, CDN</a></li>
<li><a href="#embed-custom-font-adobe-cdn" rel="noopener noreferrer" target="_blank">Embed Custom Font using Adobe Fonts, CDN</a></li>
<li><a href="#embed-custom-font-static-asset">Embed Font via AEM Client Library Static Asset</a></li>
</ol>
<div class="mention-block">
Importing fonts from other services such as Google Fonts or Adobe fonts could also result in data-privacy issues and may not be compliant with GDPR policy. For example, an organization, they have received a warning from their data security team, resulting in them hosting fonts on AEM itself.</p>
<p><strong>Do your own diligence and find what&#8217;s the right solution for your organization.</strong></div>
<hr class="spacer-large"/>
<h2 id="embed-custom-font-google-cdn">1. Embed Custom Font using Google Fonts, CDN</h2>
<p>Embed a custom font is by using Google Fonts. Google Fonts can be quickly installed into your project by using the <strong>@import</strong> CSS rule. Utilizing the out-of-the-box setup, you are prescribed to Google Font&#8217;s CDN. The lifecycle management of the fonts embedded onto your AEM site will be dependent on Google Font&#8217;s CDN servers. </p>
<p>There are hundreds of free font&#8217;s offered by Google. Simply visit the <a href="https://fonts.google.com/specimen/Roboto?sidebar.open=true&#038;selection.family=Roboto:ital,wght@0,100;0,300;1,100" rel="noopener noreferrer" target="_blank">Google Font&#8217;s website</a> to request for which fonts you wish to use on your website. Next obtain the <strong>@import</strong> CSS configuration that is offered by the webpage.</p>
<p><strong>Embedding font via @import URL:</strong></p>
<div class="codecolorer-container css default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br /></div></td><td><div class="css codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">&lt;style type<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span><span style="color: #00AA00;">&gt;</span><br />
<br />
&nbsp; <span style="color: #3F84D9; font-weight: bold;">@import</span> URL<span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">&quot;https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;1,100&amp;display=swap&quot;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span><br />
<br />
&nbsp; div<span style="color: #00AA00;">,</span> span<span style="color: #00AA00;">,</span> applet<span style="color: #00AA00;">,</span> object<span style="color: #00AA00;">,</span> iframe<span style="color: #00AA00;">,</span><br />
&nbsp; h1<span style="color: #00AA00;">,</span> h2<span style="color: #00AA00;">,</span> h3<span style="color: #00AA00;">,</span> h4<span style="color: #00AA00;">,</span> h5<span style="color: #00AA00;">,</span> h6<span style="color: #00AA00;">,</span> p<span style="color: #00AA00;">,</span> blockquote<span style="color: #00AA00;">,</span> <span style="color: #993333;">pre</span><span style="color: #00AA00;">,</span><br />
&nbsp; a<span style="color: #00AA00;">,</span> abbr<span style="color: #00AA00;">,</span> acronym<span style="color: #00AA00;">,</span> address<span style="color: #00AA00;">,</span> big<span style="color: #00AA00;">,</span> cite<span style="color: #00AA00;">,</span> code<span style="color: #00AA00;">,</span><br />
&nbsp; del<span style="color: #00AA00;">,</span> dfn<span style="color: #00AA00;">,</span> em<span style="color: #00AA00;">,</span> font<span style="color: #00AA00;">,</span> img<span style="color: #00AA00;">,</span> ins<span style="color: #00AA00;">,</span> kbd<span style="color: #00AA00;">,</span> q<span style="color: #00AA00;">,</span> s<span style="color: #00AA00;">,</span> samp<span style="color: #00AA00;">,</span><br />
&nbsp; <span style="color: #993333;">small</span><span style="color: #00AA00;">,</span> strike<span style="color: #00AA00;">,</span> strong<span style="color: #00AA00;">,</span> <span style="color: #993333;">sub</span><span style="color: #00AA00;">,</span> sup<span style="color: #00AA00;">,</span> tt<span style="color: #00AA00;">,</span> <span style="color: #9932cc;">var</span><span style="color: #00AA00;">,</span><br />
&nbsp; dl<span style="color: #00AA00;">,</span> dt<span style="color: #00AA00;">,</span> dd<span style="color: #00AA00;">,</span> ol<span style="color: #00AA00;">,</span> ul<span style="color: #00AA00;">,</span> li<span style="color: #00AA00;">,</span><br />
&nbsp; fieldset<span style="color: #00AA00;">,</span> form<span style="color: #00AA00;">,</span> label<span style="color: #00AA00;">,</span> legend<span style="color: #00AA00;">,</span><br />
&nbsp; <span style="color: #993333;">table</span><span style="color: #00AA00;">,</span> <span style="color: #993333;">caption</span><span style="color: #00AA00;">,</span> tbody<span style="color: #00AA00;">,</span> tfoot<span style="color: #00AA00;">,</span> thead<span style="color: #00AA00;">,</span> tr<span style="color: #00AA00;">,</span> th<span style="color: #00AA00;">,</span> td<span style="color: #00AA00;">,</span> <span style="color: #6666ff;">.tab-item</span><span style="color: #00AA00;">,</span> input<span style="color: #00AA00;">,</span><br />
&nbsp; <span style="color: #993333;">button</span><span style="color: #00AA00;">,</span> select<span style="color: #00AA00;">,</span> textarea <span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">font-family</span><span style="color: #00AA00;">:</span> <span style="color: #ff0000;">&quot;Roboto&quot;</span><span style="color: #00AA00;">,</span> <span style="color: #993333;">sans-serif</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1rem</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">300</span><span style="color: #00AA00;">;</span><br />
&nbsp; <span style="color: #00AA00;">&#125;</span><br />
&lt;/style<span style="color: #00AA00;">&gt;</span></div></td></tr></tbody></table></div>
<hr class="spacer-large"/>
<h2 id="embed-custom-font-adobe-cdn">2. Embed Custom Font using Adobe Fonts, CDN</h2>
<p>Embed a custom font is by using the Adobe Fonts, where fonts can be quickly installed into your project by using the <strong>@import</strong> CSS rule. After logging into Adobe Font&#8217;s, you can create a new project where you can select different fonts from Adobe Font&#8217;s collection to be used in your website. Retrieve the &#8220;<strong>embed code</strong>&#8221; CDN path from your Adobe Font&#8217;s project, and you are well on your way.</p>
<p><a href="https://sourcedcode.com/wp-content/uploads/2020/09/adobe-fonts-screenshot.jpg"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2020/09/adobe-fonts-screenshot.jpg" alt="Adobe Font's Projects Console, with Embed Code" width="300" class="alignnone size-full wp-image-2259" srcset="https://sourcedcode.com/wp-content/uploads/2020/09/adobe-fonts-screenshot.jpg 1748w, https://sourcedcode.com/wp-content/uploads/2020/09/adobe-fonts-screenshot-300x128.jpg 300w, https://sourcedcode.com/wp-content/uploads/2020/09/adobe-fonts-screenshot-1024x437.jpg 1024w, https://sourcedcode.com/wp-content/uploads/2020/09/adobe-fonts-screenshot-768x328.jpg 768w, https://sourcedcode.com/wp-content/uploads/2020/09/adobe-fonts-screenshot-1536x656.jpg 1536w, https://sourcedcode.com/wp-content/uploads/2020/09/adobe-fonts-screenshot-600x256.jpg 600w" sizes="(max-width: 1748px) 100vw, 1748px" /></a></p>
<p>Next obtain the <strong>@import</strong> CSS configuration that is offered by the webpage.</p>
<p><strong>Embedding font via @import URL:</strong></p>
<div class="codecolorer-container css default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br /></div></td><td><div class="css codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">&lt;style type<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span><span style="color: #00AA00;">&gt;</span><br />
<br />
&nbsp; <span style="color: #3F84D9; font-weight: bold;">@import</span> URL<span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">&quot;https://use.typekit.net/mqs3rg.css&quot;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span><br />
<br />
&nbsp; div<span style="color: #00AA00;">,</span> span<span style="color: #00AA00;">,</span> applet<span style="color: #00AA00;">,</span> object<span style="color: #00AA00;">,</span> iframe<span style="color: #00AA00;">,</span><br />
&nbsp; h1<span style="color: #00AA00;">,</span> h2<span style="color: #00AA00;">,</span> h3<span style="color: #00AA00;">,</span> h4<span style="color: #00AA00;">,</span> h5<span style="color: #00AA00;">,</span> h6<span style="color: #00AA00;">,</span> p<span style="color: #00AA00;">,</span> blockquote<span style="color: #00AA00;">,</span> <span style="color: #993333;">pre</span><span style="color: #00AA00;">,</span><br />
&nbsp; a<span style="color: #00AA00;">,</span> abbr<span style="color: #00AA00;">,</span> acronym<span style="color: #00AA00;">,</span> address<span style="color: #00AA00;">,</span> big<span style="color: #00AA00;">,</span> cite<span style="color: #00AA00;">,</span> code<span style="color: #00AA00;">,</span><br />
&nbsp; del<span style="color: #00AA00;">,</span> dfn<span style="color: #00AA00;">,</span> em<span style="color: #00AA00;">,</span> font<span style="color: #00AA00;">,</span> img<span style="color: #00AA00;">,</span> ins<span style="color: #00AA00;">,</span> kbd<span style="color: #00AA00;">,</span> q<span style="color: #00AA00;">,</span> s<span style="color: #00AA00;">,</span> samp<span style="color: #00AA00;">,</span><br />
&nbsp; <span style="color: #993333;">small</span><span style="color: #00AA00;">,</span> strike<span style="color: #00AA00;">,</span> strong<span style="color: #00AA00;">,</span> <span style="color: #993333;">sub</span><span style="color: #00AA00;">,</span> sup<span style="color: #00AA00;">,</span> tt<span style="color: #00AA00;">,</span> <span style="color: #9932cc;">var</span><span style="color: #00AA00;">,</span><br />
&nbsp; dl<span style="color: #00AA00;">,</span> dt<span style="color: #00AA00;">,</span> dd<span style="color: #00AA00;">,</span> ol<span style="color: #00AA00;">,</span> ul<span style="color: #00AA00;">,</span> li<span style="color: #00AA00;">,</span><br />
&nbsp; fieldset<span style="color: #00AA00;">,</span> form<span style="color: #00AA00;">,</span> label<span style="color: #00AA00;">,</span> legend<span style="color: #00AA00;">,</span><br />
&nbsp; <span style="color: #993333;">table</span><span style="color: #00AA00;">,</span> <span style="color: #993333;">caption</span><span style="color: #00AA00;">,</span> tbody<span style="color: #00AA00;">,</span> tfoot<span style="color: #00AA00;">,</span> thead<span style="color: #00AA00;">,</span> tr<span style="color: #00AA00;">,</span> th<span style="color: #00AA00;">,</span> td<span style="color: #00AA00;">,</span> <span style="color: #6666ff;">.tab-item</span><span style="color: #00AA00;">,</span> input<span style="color: #00AA00;">,</span><br />
&nbsp; <span style="color: #993333;">button</span><span style="color: #00AA00;">,</span> select<span style="color: #00AA00;">,</span> textarea <span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">font-family</span><span style="color: #00AA00;">:</span> <span style="color: #ff0000;">&quot;Roboto&quot;</span><span style="color: #00AA00;">,</span> <span style="color: #993333;">sans-serif</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1rem</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">300</span><span style="color: #00AA00;">;</span><br />
&nbsp; <span style="color: #00AA00;">&#125;</span><br />
&lt;/style<span style="color: #00AA00;">&gt;</span></div></td></tr></tbody></table></div>
<p><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<ins class="adsbygoogle"
     style="display:block; text-align:center;"
     data-ad-layout="in-article"
     data-ad-format="fluid"
     data-ad-client="ca-pub-9053803095882933"
     data-ad-slot="4202452438"></ins><br />
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<hr class="spacer-large"/>
<h2 id="embed-custom-font-static-asset">3. Embed Font via AEM Client Library Static Asset</h2>
<p>The most common way to embed a custom font for an AEM project is to store web-safe font files directly into a client library. The fonts are then referenced by the CSS stylesheet, where the font file paths are the proxied client libraries URI. Using the CSS rule, <strong>@font-face</strong>, we are able to configure custom fonts for an AEM project.</p>
<p><a href="https://sourcedcode.com/wp-content/uploads/2020/09/crxde-fonts-resources-folder.jpg"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2020/09/crxde-fonts-resources-folder.jpg" alt="clientlib-site resources/font folder screenshot" width="300" class="alignnone size-full wp-image-2273" srcset="https://sourcedcode.com/wp-content/uploads/2020/09/crxde-fonts-resources-folder.jpg 1274w, https://sourcedcode.com/wp-content/uploads/2020/09/crxde-fonts-resources-folder-300x260.jpg 300w, https://sourcedcode.com/wp-content/uploads/2020/09/crxde-fonts-resources-folder-1024x889.jpg 1024w, https://sourcedcode.com/wp-content/uploads/2020/09/crxde-fonts-resources-folder-768x667.jpg 768w, https://sourcedcode.com/wp-content/uploads/2020/09/crxde-fonts-resources-folder-600x521.jpg 600w" sizes="(max-width: 1274px) 100vw, 1274px" /></a></p>
<div class="mention-block">
For how to Serve Static Assets in AEM as Client Library Resources, <a href="https://sourcedcode.com/blog/aem/how-to-serve-static-assets-in-aem-as-client-library-resources" rel="noopener noreferrer" target="_blank">click here</a>.
</div>
<p><strong>Embedding font via @font-face URL:</strong></p>
<div class="codecolorer-container css default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br /></div></td><td><div class="css codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">&lt;style type<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span><span style="color: #00AA00;">&gt;</span><br />
&nbsp; <span style="color: #3F84D9; font-weight: bold;">@font-face</span> <span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">font-family</span><span style="color: #00AA00;">:</span> <span style="color: #ff0000;">&quot;Roboto&quot;</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; src<span style="color: #00AA00;">:</span> <span style="color: #9932cc;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">&quot;/etc.clientlibs/sourcedcode/clientlibs/clientlib-site/resources/fonts/roboto-bold.otf&quot;</span><span style="color: #00AA00;">&#41;</span> format<span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">&quot;truetype&quot;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">font-style</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">normal</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">700</span><span style="color: #00AA00;">;</span><br />
&nbsp; <span style="color: #00AA00;">&#125;</span><br />
<br />
&nbsp; <span style="color: #3F84D9; font-weight: bold;">@font-face</span> <span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">font-family</span><span style="color: #00AA00;">:</span> <span style="color: #ff0000;">&quot;Roboto&quot;</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; src<span style="color: #00AA00;">:</span> <span style="color: #9932cc;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">&quot;/etc.clientlibs/sourcedcode/clientlibs/clientlib-site/resources/fonts/roboto-medium.otf&quot;</span><span style="color: #00AA00;">&#41;</span> format<span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">&quot;truetype&quot;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">font-style</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">normal</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">500</span><span style="color: #00AA00;">;</span><br />
&nbsp; <span style="color: #00AA00;">&#125;</span><br />
<br />
&nbsp; <span style="color: #3F84D9; font-weight: bold;">@font-face</span> <span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">font-family</span><span style="color: #00AA00;">:</span> <span style="color: #ff0000;">&quot;Roboto&quot;</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; src<span style="color: #00AA00;">:</span> <span style="color: #9932cc;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">&quot;/etc.clientlibs/sourcedcode/clientlibs/clientlib-site/resources/fonts/roboto-regular.otf&quot;</span><span style="color: #00AA00;">&#41;</span> format<span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">&quot;truetype&quot;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">font-style</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">normal</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">300</span><span style="color: #00AA00;">;</span><br />
&nbsp; <span style="color: #00AA00;">&#125;</span><br />
<br />
&nbsp; div<span style="color: #00AA00;">,</span> span<span style="color: #00AA00;">,</span> applet<span style="color: #00AA00;">,</span> object<span style="color: #00AA00;">,</span> iframe<span style="color: #00AA00;">,</span><br />
&nbsp; h1<span style="color: #00AA00;">,</span> h2<span style="color: #00AA00;">,</span> h3<span style="color: #00AA00;">,</span> h4<span style="color: #00AA00;">,</span> h5<span style="color: #00AA00;">,</span> h6<span style="color: #00AA00;">,</span> p<span style="color: #00AA00;">,</span> blockquote<span style="color: #00AA00;">,</span> <span style="color: #993333;">pre</span><span style="color: #00AA00;">,</span><br />
&nbsp; a<span style="color: #00AA00;">,</span> abbr<span style="color: #00AA00;">,</span> acronym<span style="color: #00AA00;">,</span> address<span style="color: #00AA00;">,</span> big<span style="color: #00AA00;">,</span> cite<span style="color: #00AA00;">,</span> code<span style="color: #00AA00;">,</span><br />
&nbsp; del<span style="color: #00AA00;">,</span> dfn<span style="color: #00AA00;">,</span> em<span style="color: #00AA00;">,</span> font<span style="color: #00AA00;">,</span> img<span style="color: #00AA00;">,</span> ins<span style="color: #00AA00;">,</span> kbd<span style="color: #00AA00;">,</span> q<span style="color: #00AA00;">,</span> s<span style="color: #00AA00;">,</span> samp<span style="color: #00AA00;">,</span><br />
&nbsp; <span style="color: #993333;">small</span><span style="color: #00AA00;">,</span> strike<span style="color: #00AA00;">,</span> strong<span style="color: #00AA00;">,</span> <span style="color: #993333;">sub</span><span style="color: #00AA00;">,</span> sup<span style="color: #00AA00;">,</span> tt<span style="color: #00AA00;">,</span> <span style="color: #9932cc;">var</span><span style="color: #00AA00;">,</span><br />
&nbsp; dl<span style="color: #00AA00;">,</span> dt<span style="color: #00AA00;">,</span> dd<span style="color: #00AA00;">,</span> ol<span style="color: #00AA00;">,</span> ul<span style="color: #00AA00;">,</span> li<span style="color: #00AA00;">,</span><br />
&nbsp; fieldset<span style="color: #00AA00;">,</span> form<span style="color: #00AA00;">,</span> label<span style="color: #00AA00;">,</span> legend<span style="color: #00AA00;">,</span><br />
&nbsp; <span style="color: #993333;">table</span><span style="color: #00AA00;">,</span> <span style="color: #993333;">caption</span><span style="color: #00AA00;">,</span> tbody<span style="color: #00AA00;">,</span> tfoot<span style="color: #00AA00;">,</span> thead<span style="color: #00AA00;">,</span> tr<span style="color: #00AA00;">,</span> th<span style="color: #00AA00;">,</span> td<span style="color: #00AA00;">,</span> <span style="color: #6666ff;">.tab-item</span><span style="color: #00AA00;">,</span> input<span style="color: #00AA00;">,</span><br />
&nbsp; <span style="color: #993333;">button</span><span style="color: #00AA00;">,</span> select<span style="color: #00AA00;">,</span> textarea <span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">font-family</span><span style="color: #00AA00;">:</span> <span style="color: #ff0000;">&quot;Roboto&quot;</span><span style="color: #00AA00;">,</span> <span style="color: #993333;">sans-serif</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1rem</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">300</span><span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span><br />
&lt;/style<span style="color: #00AA00;">&gt;</span></div></td></tr></tbody></table></div>
<p><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Horizontal Preview Ad --><br />
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-9053803095882933"
     data-ad-slot="8658919803"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins><br />
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/3-different-ways-to-embed-custom-fonts-in-aem-sites">3 Different Ways to Embed Custom Fonts in AEM Sites</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/3-different-ways-to-embed-custom-fonts-in-aem-sites/feed</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>How to include JavaScript for an AEM Website</title>
		<link>https://sourcedcode.com/blog/aem/how-to-include-javascript-for-an-aem-website</link>
					<comments>https://sourcedcode.com/blog/aem/how-to-include-javascript-for-an-aem-website#comments</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Sun, 19 Jul 2020 14:10:34 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Client Libraries]]></category>
		<category><![CDATA[JavaScript]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=2063</guid>

					<description><![CDATA[<p>Adding behaviour to a form, button, list of items, or page scroll are some examples of front-end user interactions that we as developers must implement, to enable user rich experiences. How do we add behaviours to a page? JavaScript! JavaScript is the technology used to add user rich experiences for a website. AEM website can [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/how-to-include-javascript-for-an-aem-website">How to include JavaScript for an AEM Website</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Adding behaviour to a form, button, list of items, or page scroll are some examples of front-end user interactions that we as developers must implement, to enable user rich experiences. How do we add behaviours to a page? JavaScript! JavaScript is the technology used to add user rich experiences for a website. </p>
<p>AEM website can include &#038; run front-end JavaScript logic like all other websites. <strong>Note</strong>, There&#8217;s nothing special about an AEM web page, as an AEM page rendered output is nothing but a standard HTML document; there&#8217;s no magic or surprises. </p>
<p>In this article, we will explore the 4 techniques of how we can include JavaScript within a webpage. </p>
<div class="mention-block">
<strong>Including JavaScript By:</strong></p>
<ol>
<li><a href="#javascript-by-html-event-attributes">HTML Event Attributes</a></li>
<li><a href="#javascript-by-inline">Inline JavaScript</a></li>
<li><a href="#javascript-by-internal-client-libraries">Internal Client Libraries JavaScript</a></li>
<li><a href="#javascript-by-external-javascript">External JavaScript</a></li>
</ol>
</div>
<hr class="spacer-large"/>
<h2 id="javascript-by-html-event-attributes">1. HTML Event Attributes</h2>
<p>HTML possesses the capability to let events trigger actions in a browser, for example, executing JavaScript logic when a user clicks, hovers, drags, or keypress an element on a page. These events include onclick,  onmouseout, ondrag, oncopy, etc&#8230;</p>
<p><strong class="cnt-margin-bottom-neg-20">Use Case:</strong><br />
Quickly way to add interactions to a unique HTML element on the page, as a proof of concept. Then later implement the same functionality with a front-end JavaScript application with tests.</p>
<p><strong class="cnt-margin-bottom-neg-20">Examples:</strong></p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;back-to-top&quot;</span> <span style="color: #000066;">onclick</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;window.scrollTo(0,0);&quot;</span>&gt; <span style="color: #66cc66;">//</span> Execute a JavaScript when this button is clicked<br />
&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">onmouseover</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;window.alert('mouse over')&quot;</span>&gt;Test&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt; <span style="color: #66cc66;">//</span> Execute a JavaScript when moving the mouse pointer over the &lt;<span style="color: #000000; font-weight: bold;">a</span>&gt; tag<br />
&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">onmouseout</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;window.alert('mouse out')&quot;</span>&gt;Test&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt; <span style="color: #66cc66;">//</span>Execute a JavaScript when moving the mouse pointer out of the &lt;<span style="color: #000000; font-weight: bold;">a</span>&gt; tag<br />
&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;fullname&quot;</span> <span style="color: #000066;">onkeydown</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;window.alert('key down')&quot;</span>&gt; <span style="color: #66cc66;">//</span> Execute a JavaScript when a user presses a key<br />
&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;fullname&quot;</span> <span style="color: #000066;">onkeyup</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;window.alert('key released')&quot;</span>&gt; <span style="color: #66cc66;">//</span> Execute a JavaScript when a user releases a key<br />
&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;fullname&quot;</span> <span style="color: #000066;">onfocus</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;window.alert('focused')&quot;</span>&gt; <span style="color: #66cc66;">//</span> Execute a JavaScript when the input field is focused <span style="color: #66cc66;">&#40;</span><span style="color: #000066;">selected</span><span style="color: #66cc66;">&#41;</span><br />
&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;fullname&quot;</span> <span style="color: #000066;">onblur</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;window.alert('blurred')&quot;</span>&gt; <span style="color: #66cc66;">//</span> Execute a JavaScript when the input field is blurred <span style="color: #66cc66;">&#40;</span>unselected<span style="color: #66cc66;">&#41;</span></div></td></tr></tbody></table></div>
<hr class="spacer-large"/>
<h2 id="javascript-by-inline">2.Inline JavaScript</h2>
<p>Inline JavaScript can be executed by using &lt;script&gt; tag inside the &lt;head&gt; or &lt;body&gt; of the HTML document object model (DOM). Instead of specifying the source(src=&#8221;…&#8221;) of the JavaScript file in the &lt;script&gt; tag, JavaScript code can be written within the Script tag.</p>
<p><strong class="cnt-margin-bottom-neg-20">Use Case:</strong><br />
Supporting Adobe Analytics&#8217;s Data Layer JSON schema configuration values, based on the context of the page. </p>
<p><strong class="cnt-margin-bottom-neg-20">Examples:</strong></p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">&lt;!DOCTYPE html&gt; &nbsp;<br />
&lt;<span style="color: #000000; font-weight: bold;">html</span>&gt; &nbsp;<br />
&nbsp; &nbsp; &lt;<span style="color: #000000; font-weight: bold;">head</span>&gt; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;<span style="color: #000000; font-weight: bold;">title</span>&gt;Inline JavaScript Example&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">title</span>&gt; &nbsp;<br />
&nbsp; &nbsp; &lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt; <br />
&nbsp; &nbsp; &lt;<span style="color: #000000; font-weight: bold;">body</span>&gt; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;<span style="color: #000000; font-weight: bold;">h1</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;intro&quot;</span>&gt;Hello &nbsp;World&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;sly data-sly-use.dataLayer<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;com.sourcedcode.models.DataLayer&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span>sly&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var digitalDataLayer <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; environment: <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; environmentVersion: <span style="color: #ff0000;">&quot;6.0.5.1&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; environmentName: <span style="color: #ff0000;">'${dataLayer.environmentName @ context=&quot;scriptString&quot;}'</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; siteName: <span style="color: #ff0000;">&quot;SourcedCode.com&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; statusCode: <span style="color: #cc66cc;">200</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">target</span>: <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; page: <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pageInfo: <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pageName: <span style="color: #ff0000;">&quot;home&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pageReferrer: document.referrer,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pageSiteSection: <span style="color: #ff0000;">&quot;homepage&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pageSiteSubsection: <span style="color: #ff0000;">&quot;&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pageType: <span style="color: #ff0000;">&quot;homepage&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pageURL: <span style="color: #ff0000;">&quot;https://www.sourcedcode.com&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt; &nbsp; <br />
&nbsp; &nbsp; &lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt; &nbsp;<br />
&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</div></td></tr></tbody></table></div>
<hr class="spacer-large"/>
<h3 id="javascript-by-internal-client-libraries">3. Internal Client Libraries JavaScript</h2>
<p>This is the HTML document that references the internal JavaScript file (compiled from client libraries).</p>
<p>The most common way to declare CSS styles and JavaScript behaviour to an AEM website is the use of AEM client libraries. A Client library is very specific to AEM where it is simply configuration declaring which CSS, JS, Resource files to be bundled; a client library can also bundle other client library configurations, and it has the capability to minify and debug. It is by choice and the preferred way that all AEM sites utilise client libraries to define a website.</p>
<p><strong class="cnt-margin-bottom-neg-20">Use Case:</strong></p>
<ul>
<li>Serving JS and CSS from source files in AEM.</li>
<li>Serving organised JS and CSS from different client libraries in AEM.</li>
<li>Stitching multiple client libraries to be served in a single CSS or JS file.</li>
</ul>
<p><strong class="cnt-margin-bottom-neg-20">Example &#8211; HTL loading CSS &#038; JS using a Helper Template:</strong></p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">&lt;!DOCTYPE html&gt; &nbsp;<br />
&lt;<span style="color: #000000; font-weight: bold;">html</span>&gt; &nbsp;<br />
&nbsp; &nbsp; &lt;<span style="color: #000000; font-weight: bold;">head</span>&gt; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;<span style="color: #000000; font-weight: bold;">title</span>&gt;Client Librbary JavaScript file&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">title</span>&gt; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;!--<span style="color: #66cc66;">/</span>* Load sourcedcode libraries, css *<span style="color: #66cc66;">/</span>--&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;sly data-sly-use.clientlib<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;/libs/granite/sightly/templates/clientlib.html&quot;</span><span style="color: #66cc66;">/</span>&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;sly data-sly-call<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;${clientlib.css @ categories='sourcedcode.site,sourcedcode.utils'}&quot;</span><span style="color: #66cc66;">/</span>&gt;<br />
&nbsp; &nbsp; &lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt; &nbsp; <br />
&nbsp; &nbsp; &lt;<span style="color: #000000; font-weight: bold;">body</span>&gt; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; ...<br />
&nbsp; &nbsp; &nbsp; &nbsp; ...<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;!--<span style="color: #66cc66;">/</span>* Load sourcedcode libraries, js *<span style="color: #66cc66;">/</span>--&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;sly data-sly-use.clientlib<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;/libs/granite/sightly/templates/clientlib.html&quot;</span><span style="color: #66cc66;">/</span>&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;sly data-sly-call<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;${clientlib.js @ categories='sourcedcode.site,sourcedcode.utils'}&quot;</span><span style="color: #66cc66;">/</span>&gt;<br />
&nbsp; &nbsp; &lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt; &nbsp;<br />
&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</div></td></tr></tbody></table></div>
<p><strong class="cnt-margin-bottom-neg-20">Example &#8211; Result of Rendered Page:</strong></p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">&lt;!DOCTYPE html&gt; &nbsp;<br />
&lt;<span style="color: #000000; font-weight: bold;">html</span>&gt; &nbsp;<br />
&nbsp; &nbsp; &lt;<span style="color: #000000; font-weight: bold;">head</span>&gt; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;<span style="color: #000000; font-weight: bold;">title</span>&gt;Client Librbary JavaScript file&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">title</span>&gt; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;/etc.clientlibs/my-site/clientlibs/clientlibs-site.css&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;/etc.clientlibs/my-site/clientlibs/clientlibs-utils.css&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;<br />
&nbsp; &nbsp; &lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt; &nbsp; <br />
&nbsp; &nbsp; &lt;<span style="color: #000000; font-weight: bold;">body</span>&gt; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; ...<br />
&nbsp; &nbsp; &nbsp; &nbsp; ...<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;/etc.clientlibs/my-site/clientlibs/clientlibs-site.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;/etc.clientlibs/my-site/clientlibs/clientlibs-utils.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;<br />
&nbsp; &nbsp; &lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt; &nbsp;<br />
&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</div></td></tr></tbody></table></div>
<div class="modernized-box">
     <strong class="cnt-margin-bottom-neg-20">Example &#8211; Including Client Library from Editable Template Page Policies:</strong><br />
     <img decoding="async" alt="Editable template page policies" src="https://sourcedcode.com/wp-content/uploads/2020/07/editable-template-page-policies.png" /><br />
<strong class="cnt-margin-bottom-neg-20">Example &#8211; Result of Rendered Page from Editable Template Page Policies:</strong></p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">&lt;!DOCTYPE html&gt; &nbsp;<br />
&lt;<span style="color: #000000; font-weight: bold;">html</span>&gt; &nbsp;<br />
&nbsp; &nbsp; &lt;<span style="color: #000000; font-weight: bold;">head</span>&gt; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;<span style="color: #000000; font-weight: bold;">title</span>&gt;Client Librbary JavaScript file&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">title</span>&gt; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;/etc.clientlibs/my-site/clientlibs/clientlibs-site.css&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;/etc.clientlibs/my-site/clientlibs/clientlibs-utils.css&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;<br />
&nbsp; &nbsp; &lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt; &nbsp; <br />
&nbsp; &nbsp; &lt;<span style="color: #000000; font-weight: bold;">body</span>&gt; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; ...<br />
&nbsp; &nbsp; &nbsp; &nbsp; ...<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;/etc.clientlibs/my-site/clientlibs/clientlibs-site.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;/etc.clientlibs/my-site/clientlibs/clientlibs-utils.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;<br />
&nbsp; &nbsp; &lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt; &nbsp;<br />
&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</div></td></tr></tbody></table></div>
</div>
<hr class="spacer-large"/>
<h3 id="javascript-by-external-javascript">4. External JavaScript</h2>
<p>This is the HTML document that references the external JavaScript file.<br />
<strong class="cnt-margin-bottom-neg-20">Use Case:</strong></p>
<ul>
<li>Referencing the Adobe Dynamic Tag Manager (DTM) library to support Adobe DTM features.</li>
<li>Referencing to the Adobe Analytics library, to support Adobe Analytics features.</li>
<li>Referencing third party libraries, to support libraries features.</li>
</ul>
<p><strong class="cnt-margin-bottom-neg-20">Example:</strong></p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">&lt;!DOCTYPE html&gt; &nbsp;<br />
&lt;<span style="color: #000000; font-weight: bold;">html</span>&gt; &nbsp;<br />
&nbsp; &nbsp; &lt;<span style="color: #000000; font-weight: bold;">head</span>&gt; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;<span style="color: #000000; font-weight: bold;">title</span>&gt;External Librbary JavaScript file&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">title</span>&gt; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;<span style="color: #000000; font-weight: bold;">link</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css&quot;</span>&gt;<br />
&nbsp; &nbsp; &lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt; &nbsp; <br />
&nbsp; &nbsp; &lt;<span style="color: #000000; font-weight: bold;">body</span>&gt; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; ...<br />
&nbsp; &nbsp; &nbsp; &nbsp; ...<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;<br />
&nbsp; &nbsp; &lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt; &nbsp;<br />
&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</div></td></tr></tbody></table></div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/how-to-include-javascript-for-an-aem-website">How to include JavaScript for an AEM Website</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/how-to-include-javascript-for-an-aem-website/feed</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>How to Serve Static Assets in AEM as Client Library Resources</title>
		<link>https://sourcedcode.com/blog/aem/how-to-serve-static-assets-in-aem-as-client-library-resources</link>
					<comments>https://sourcedcode.com/blog/aem/how-to-serve-static-assets-in-aem-as-client-library-resources#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Sun, 12 Jul 2020 12:11:50 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Assets]]></category>
		<category><![CDATA[Client Libraries]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=2019</guid>

					<description><![CDATA[<p>This article provides step by step instructions on how to create a client library, to only serve structural static assets as client library resources. Resources from this article will build upon the latest maven AEM Project Archetype, and the instructions below will demo the configuration setup within the code. Mention! Learn more about the reasons [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/how-to-serve-static-assets-in-aem-as-client-library-resources">How to Serve Static Assets in AEM as Client Library Resources</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>This article provides step by step instructions on how to create a client library, to only serve structural static assets as client library resources. Resources from this article will build upon the latest maven <a href="https://github.com/adobe/aem-project-archetype" title="AEM Project Archetype" rel="noopener nofollow noreferrer" target="_blank">AEM Project Archetype</a>, and the instructions below will demo the configuration setup within the code. </p>
<div class="mention-block">
<strong>Mention!</strong><br />
Learn more about the reasons why we should not to store structural static assets &#8220;as content&#8221;, rather to utilise client library static resources, <a href="https://sourcedcode.com/blog/aem/structural-static-assets-in-aem-as-client-library-resources" title="Structural Static Assets in AEM as Client Library Resources">click here</a>.
</div>
<h2>Instructions</h2>
<h5>1. Create a cq:ClientLibraryFolder node</h5>
<p>JCR Path: /apps/sourcedcode/clientlibs/cllienlib-site<br />
<em>Separate code from content and configuration to maximize project file oranization and separation of concerns, Adobe recommends to place client libraries under /apps and expose these client libraries via the path, /etc.clientlibs, by leveraging the allowProxy property.</em></p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;?</span>xml version<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;1.0&quot;</span> encoding<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;UTF-8&quot;</span><span style="color: #339933;">?&gt;</span><br />
<span style="color: #339933;">&lt;</span>jcr<span style="color: #339933;">:</span>root xmlns<span style="color: #339933;">:</span>cq<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://www.day.com/jcr/cq/1.0&quot;</span> xmlns<span style="color: #339933;">:</span>jcr<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://www.jcp.org/jcr/1.0&quot;</span><br />
&nbsp; &nbsp; jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;cq:ClientLibraryFolder&quot;</span><br />
&nbsp; &nbsp; allowProxy<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{Boolean}true&quot;</span><br />
&nbsp; &nbsp; categories<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;sourcedcode.site&quot;</span><span style="color: #339933;">/&gt;</span></div></td></tr></tbody></table></div>
<p><a href="https://sourcedcode.com/wp-content/uploads/2020/07/how-to-serve-static-assets-in-aem-as-client-library-resources-step-1.png"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2020/07/how-to-serve-static-assets-in-aem-as-client-library-resources-step-1-150x150.png" alt="" width="150" height="150" class="alignnone size-thumbnail wp-image-2025" srcset="https://sourcedcode.com/wp-content/uploads/2020/07/how-to-serve-static-assets-in-aem-as-client-library-resources-step-1-150x150.png 150w, https://sourcedcode.com/wp-content/uploads/2020/07/how-to-serve-static-assets-in-aem-as-client-library-resources-step-1-65x65.png 65w" sizes="(max-width: 150px) 100vw, 150px" /></a><br />
When allowedProxy is enabled, we instead of accessing the client library from /apps/sourcedcode/clientlibs/cllienlib-site, we can access the cliebt library from the proxy servlet via /etc.clientlibs/sourcedcode/clientlibs/cllienlib-site.</p>
<div class="spacer-large"></div>
<h5>2. Create a nt:folder node named &#8220;resources&#8221;</h5>
<p>JCR Path: /apps/sourcedcode/clientlibs/cllienlib-site/resources<br />
<em>By convention, the client library &#8220;resource&#8221; folder is named as &#8220;resources&#8221;; which the naming is very important if structural static assets are planned be served from a client library. This setup allowes structural static assets to be accessed via the proxy. <br />Example: /etc.clientlibs/sourcedcode/clientlibs/cllienlib-site/resources/tick.svg</em><br />
<a href="https://sourcedcode.com/wp-content/uploads/2020/07/how-to-serve-static-assets-in-aem-as-client-library-resources-step-2.png"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2020/07/how-to-serve-static-assets-in-aem-as-client-library-resources-step-2-150x150.png" alt="" width="150" height="150" class="alignnone size-thumbnail wp-image-2027" srcset="https://sourcedcode.com/wp-content/uploads/2020/07/how-to-serve-static-assets-in-aem-as-client-library-resources-step-2-150x150.png 150w, https://sourcedcode.com/wp-content/uploads/2020/07/how-to-serve-static-assets-in-aem-as-client-library-resources-step-2-65x65.png 65w" sizes="(max-width: 150px) 100vw, 150px" /></a></p>
<div class="spacer-large"></div>
<h5>3. Place the assets under the &#8220;resources&#8221; folder</h5>
<p>In this example, we will only insert one asset image, tick.svg.<br />
JCR Path: /apps/sourcedcode/clientlibs/cllienlib-site/resources/tick.svg<br />
<a href="https://sourcedcode.com/wp-content/uploads/2020/07/how-to-serve-static-assets-in-aem-as-client-library-resources-step-3.png"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2020/07/how-to-serve-static-assets-in-aem-as-client-library-resources-step-3-150x150.png" alt="" width="150" height="150" class="alignnone size-thumbnail wp-image-2026" srcset="https://sourcedcode.com/wp-content/uploads/2020/07/how-to-serve-static-assets-in-aem-as-client-library-resources-step-3-150x150.png 150w, https://sourcedcode.com/wp-content/uploads/2020/07/how-to-serve-static-assets-in-aem-as-client-library-resources-step-3-65x65.png 65w" sizes="(max-width: 150px) 100vw, 150px" /></a></p>
<div class="spacer-large"></div>
<h5>4. Build and Upload into AEM</h5>
<p>This default maven profile should be a part of the maven AEM Project Archetype.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">mvn clean install <span style="color: #339933;">-</span>PautoInstallPackage <span style="color: #339933;">-</span>Padobe<span style="color: #339933;">-</span><span style="color: #000000; font-weight: bold;">public</span></div></td></tr></tbody></table></div>
<div class="spacer-large"></div>
<h5>Results: Review the JCR</h5>
<p>A successful project build and deploy should make JCR node resources available in the AEM environment.<br />
<a href="https://sourcedcode.com/wp-content/uploads/2020/07/how-to-serve-structural-static-assets-in-aem-as-client-library-resources-image.png"><img loading="lazy" decoding="async" src="https://sourcedcode.com/wp-content/uploads/2020/07/how-to-serve-structural-static-assets-in-aem-as-client-library-resources-image-150x150.png" alt="" width="150" height="150" class="alignnone size-thumbnail wp-image-2021" srcset="https://sourcedcode.com/wp-content/uploads/2020/07/how-to-serve-structural-static-assets-in-aem-as-client-library-resources-image-150x150.png 150w, https://sourcedcode.com/wp-content/uploads/2020/07/how-to-serve-structural-static-assets-in-aem-as-client-library-resources-image-65x65.png 65w" sizes="(max-width: 150px) 100vw, 150px" /></a></p>
<h5>Results: Access the Asset(s)</h5>
<p>The images can be resolvable via the proxy servlet, replacing /apps with /etc.clientlibs.<br />
Visit: http://localhost:4502/etc.clientlibs/sourcedcode/clientlibs/cllienlib-site/resources/tick.svg<br />
<a href="https://sourcedcode.com/wp-content/uploads/2020/07/how-to-serve-structural-static-assets-in-aem-as-client-library-resources-icon-tick.png"><img loading="lazy" decoding="async" src="https://sourcedcode.com/wp-content/uploads/2020/07/how-to-serve-structural-static-assets-in-aem-as-client-library-resources-icon-tick-150x150.png" alt="" width="150" height="150" class="alignnone size-thumbnail wp-image-2020" srcset="https://sourcedcode.com/wp-content/uploads/2020/07/how-to-serve-structural-static-assets-in-aem-as-client-library-resources-icon-tick-150x150.png 150w, https://sourcedcode.com/wp-content/uploads/2020/07/how-to-serve-structural-static-assets-in-aem-as-client-library-resources-icon-tick-65x65.png 65w" sizes="(max-width: 150px) 100vw, 150px" /></a></p>
<div class="mention-block">
<strong>Mention!</strong><br />
Learn the reasons why structural assets should not be stored “as content” and managed as DAM assets, <a href="https://sourcedcode.com/blog/aem/structural-static-assets-in-aem-as-client-library-resources" title="Structural Static Assets in AEM as Client Library Resources">click here</a>.
</div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/how-to-serve-static-assets-in-aem-as-client-library-resources">How to Serve Static Assets in AEM as Client Library Resources</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/how-to-serve-static-assets-in-aem-as-client-library-resources/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Structural Static Assets in AEM as Client Library Resources</title>
		<link>https://sourcedcode.com/blog/aem/structural-static-assets-in-aem-as-client-library-resources</link>
					<comments>https://sourcedcode.com/blog/aem/structural-static-assets-in-aem-as-client-library-resources#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Sun, 12 Jul 2020 10:39:39 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Assets]]></category>
		<category><![CDATA[Client Libraries]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=2007</guid>

					<description><![CDATA[<p>As developers, when we are building components or view logic, in typical scenarios require assets like background image patterns, icons, logos, typography, etc.. These assets are considered as structural assets. Structural assets are assets that support CSS styles or JavaScript view logic; which are also static assets. Structural assets should be stored and managed within [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/structural-static-assets-in-aem-as-client-library-resources">Structural Static Assets in AEM as Client Library Resources</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>As developers, when we are building components or view logic, in typical scenarios require assets like background image patterns, icons, logos, typography, etc.. These assets are considered as <strong>structural assets</strong>. Structural assets are assets that support CSS styles or JavaScript view logic; which are also static assets.</p>
<p>Structural assets should be stored and managed within the client library&#8217;s <strong>resources</strong> folder by the code package, and not in AEM Digital Assets Manager (DAM) &#8220;as content&#8221;. The AEM DAM is a very flexible AEM product where it allows users &#038; groups to freely manage (based on ACL permissions) assets to make available for the public. Sometimes developers may find the ease of storing structural assets in the DAM (with the help of content authors), so they can quickly make the structural asset publically available for consumption. But, in fact, this is the wrong pattern to follow.</p>
<p><strong>The reason why structural assets should <strong style="color:red;">not</strong> be stored &#8220;as content&#8221; and managed as DAM assets because:</strong></p>
<ul>
<li>It would be surfaced to AEM content authors (the customers) during image selection when they are editing an AEM page that requires an AEM DAM asset; they can be confused, and they can potentially select on the structural asset (because it&#8217;s available for selection).</li>
<li>It opens opportunities for interruption of our CSS styles or JavaScript view logic; where authors can actually delete/update a structural asset, and the website may look like its broken.</li>
<li>It would kickstart workflows; creating thumbnails, preview renditions, meta-data extractions, and other workflow processes&#8230; These are unnecessary asset processing&#8230; we do not want any thumbnails or renditions for the structural asset.</li>
<li>Code like CSS styles or JavaScript logic referenced assets &#8220;as content&#8221; is not ideal, as DAM assets are maintained by authors, and can be unpredictability changed at any time.</li>
</ul>
<div class="mention-block">
<strong>Mention!</strong><br />
<a href="https://sourcedcode.com/blog/aem/how-to-serve-static-assets-in-aem-as-client-library-resources" title="How to Serve Static Assets in AEM as Client Library Resources">Click here</a> to learn how to create a client library that only serves static assets.<br />
</strong>
</div>
<div class="mention-block">
<strong>Conclusion</strong><br />
Structural assets should be stored and managed within the client library&#8217;s <strong>resources</strong> folder by the code package. It allows developers to have full control of which structural asset gets added, updated, or removed. AEM authors have 0% chance of breaking accidentally removing one of these assets vs if structural content is stored &#8220;as content&#8221;, where assets can be managed and consumed in an unpredictable way.</div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/structural-static-assets-in-aem-as-client-library-resources">Structural Static Assets in AEM as Client Library Resources</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/structural-static-assets-in-aem-as-client-library-resources/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
