<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:media="http://search.yahoo.com/mrss/"><channel><title><![CDATA[JavaScript - All your code are belong to us]]></title><description><![CDATA[Thoughts, stories and ideas on code and technology in general.<br>Blog title inspired by <a href="https://en.wikipedia.org/wiki/All_your_base_are_belong_to_us" target="_blank">this meme</a>]]></description><link>https://allurcode.com/</link><image><url>https://allurcode.com/favicon.png</url><title>JavaScript - All your code are belong to us</title><link>https://allurcode.com/</link></image><generator>Ghost 4.48</generator><lastBuildDate>Fri, 12 Jun 2026 05:19:19 GMT</lastBuildDate><atom:link href="https://allurcode.com/tag/javascript/rss/" rel="self" type="application/rss+xml"/><ttl>60</ttl><item><title><![CDATA[Create NodeJS command line script or app]]></title><description><![CDATA[Learn an extremely simple way of creating command line scripts or apps using NodeJS]]></description><link>https://allurcode.com/create-nodejs-command-line-script-or-app/</link><guid isPermaLink="false">5bc8884aa0c66e55d1ddf987</guid><category><![CDATA[nodejs]]></category><category><![CDATA[shell]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[script]]></category><dc:creator><![CDATA[Wojtek]]></dc:creator><pubDate>Sat, 15 Dec 2018 17:51:32 GMT</pubDate><content:encoded><![CDATA[<!--kg-card-begin: markdown--><p>I wanted to write a simple script that would convert multiple files from one encoding to another. I didn&apos;t want anything big or running in the browser. Command line script seemed like the right approach. Coming from a web developer background my first thought was a script written in PHP and converted to a command line app. Just saying that sounds awful. After a bit of googling, it turned out NodeJS is surprisingly easy and straightforward to write command line apps.</p>
<h3 id="initiatetheapp">Initiate the app</h3>
<p>Running <code>npm init</code> will ask you a few basic questions about your app and result in creating <code>package.json</code> file.</p>
<pre><code>$ npm init

name: cldemo
version: 0.0.1
description: Simple command line script
entry point: index.js
test command:
git repository:
keywords:
author: SixBytesUnder
license: (ISC)
</code></pre>
<p>Edit the newly created <code>package.json</code> and add &quot;bin&quot; section. The property key will be the command you&apos;ll type in to run your app. In our case <code>cldemo</code>. The value is a relative path to the entry point file. That&apos;s the file our code will reside in.</p>
<pre><code class="language-javascript">...
&quot;author&quot;: &quot;SixBytesUnder&quot;,
&quot;license&quot;: &quot;ISC&quot;,
&quot;bin&quot;: {
  &quot;cldemo&quot;: &quot;./index.js&quot;
}
</code></pre>
<p>Next, create <code>index.js</code> file or any other file you have provided as an &quot;entry point&quot; above. Paste example code show below.</p>
<pre><code class="language-javascript">#!/usr/bin/env node
&apos;use strict&apos;;

// your whole code goes here
console.log(&apos;Hello World!&apos;)
</code></pre>
<p>The most basic command line script is done.</p>
<h3 id="registeryourscript">Register your script</h3>
<p>Next command will register your app as a shell command. <strong>Note</strong>, on Windows you need to open command prompt as an admin, navigate to the home directory of your app and run below.</p>
<pre><code>$ npm install -g
</code></pre>
<p>That&apos;s it, it&apos;s a simple as that. Now you should be able to run your script from command line globally.</p>
<pre><code>$ cldemo
Hello World!
</code></pre>
<p>If you make any changes to your source files, remember to register your app again, so that latest version is copied to the global path.</p>
<p>To uninstall your script just type:</p>
<pre><code>$ npm uninstall -g cldemo
</code></pre>
<!--kg-card-end: markdown-->]]></content:encoded></item><item><title><![CDATA[Multiple dynamic Facebook like buttons on one page]]></title><description><![CDATA[<!--kg-card-begin: markdown--><p>Putting one like button on a page is very simple and comes down to pasting the code from Facebook like button generator found <a href="https://developers.facebook.com/docs/plugins/like-button">here</a>.<br>
It gets a bit more complicated when we need to add more than one button on a page along with a dynamically generated content. Best example</p>]]></description><link>https://allurcode.com/multiple-dynamic-facebook-like-buttons-on-one-page/</link><guid isPermaLink="false">5b7b0aa2b52b43084c9ea13b</guid><category><![CDATA[Facebook]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[like button]]></category><dc:creator><![CDATA[Wojtek]]></dc:creator><pubDate>Thu, 30 Jun 2011 13:11:04 GMT</pubDate><content:encoded><![CDATA[<!--kg-card-begin: markdown--><p>Putting one like button on a page is very simple and comes down to pasting the code from Facebook like button generator found <a href="https://developers.facebook.com/docs/plugins/like-button">here</a>.<br>
It gets a bit more complicated when we need to add more than one button on a page along with a dynamically generated content. Best example I can think of is a search results page where every search result has it&#x2019;s own like button.</p>
<h3 id="prepare">Prepare</h3>
<p>Put this somewhere in your page. Official Facebook documentation changes it&#x2019;s recommendation from time to time, so let&#x2019;s say just put it right after opening <code>&lt;body&gt;</code> tag.</p>
<pre><code class="language-html">&lt;div id=&quot;fb-root&quot;&gt;&lt;/div&gt;
</code></pre>
<h3 id="pasteyourlikebuttonscode">Paste your Like buttons code</h3>
<pre><code class="language-html">&lt;fb:like href=&quot;http://example.com&quot; send=&quot;false&quot; layout=&quot;button_count&quot; show_faces=&quot;false&quot;&gt;&lt;/fb:like&gt;
</code></pre>
<h3 id="initializelikebuttons">Initialize Like buttons</h3>
<p>In your JavaScript code after inserting all the <code>fb:like</code> tags you need to initialize all those buttons. You can do that by running below code</p>
<pre><code class="language-javascript">window.fbAsyncInit = function() {
  FB.init({appId: &apos;your_app_id&apos;, status: true, cookie: true, xfbml: true});
};
(function() {
  var e = document.createElement(&apos;script&apos;);
  e.async = true;
  e.src = document.location.protocol + &apos;//connect.facebook.net/en_US/all.js&apos;;
  document.getElementById(&apos;fb-root&apos;).appendChild(e);
}());
</code></pre>
<p>Remember to change &quot;your_app_id&quot; to your actual app id.</p>
<!--kg-card-end: markdown-->]]></content:encoded></item><item><title><![CDATA[Hot off the workshop vol. 2]]></title><description><![CDATA[<!--kg-card-begin: markdown--><p><img src="https://allurcode.com/content/images/2011/03/tkmaxx_rebrand.jpg" alt="TK Maxx website rebranding" title="TK Maxx website rebranding" loading="lazy"></p>
<p>Website redesign for TK Maxx. Launched just yesterday.<br>
Venda coding all the way in the back end and HTML, JavaScript and CSS in the front end.<br>
<a href="https://www.tkmaxx.com/">Visit live site</a></p>
<h3 id="whativelearnt">What I&#x2019;ve learnt</h3>
<p>The biggest challenge was to make the site work in Internet Explorer 6 and 7. One</p>]]></description><link>https://allurcode.com/hot-off-the-workshop-vol-2/</link><guid isPermaLink="false">5b7b0aa2b52b43084c9ea138</guid><category><![CDATA[CSS]]></category><category><![CDATA[HTML]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[TK Maxx]]></category><category><![CDATA[Venda]]></category><dc:creator><![CDATA[Wojtek]]></dc:creator><pubDate>Tue, 22 Mar 2011 22:45:50 GMT</pubDate><content:encoded><![CDATA[<!--kg-card-begin: markdown--><p><img src="https://allurcode.com/content/images/2011/03/tkmaxx_rebrand.jpg" alt="TK Maxx website rebranding" title="TK Maxx website rebranding" loading="lazy"></p>
<p>Website redesign for TK Maxx. Launched just yesterday.<br>
Venda coding all the way in the back end and HTML, JavaScript and CSS in the front end.<br>
<a href="https://www.tkmaxx.com/">Visit live site</a></p>
<h3 id="whativelearnt">What I&#x2019;ve learnt</h3>
<p>The biggest challenge was to make the site work in Internet Explorer 6 and 7. One particularly annoying issue was to make the logo stay on top of the sliding main homepage image. All other browsers were fine, but in IE6 and 7 the logo was hidden behind the image.</p>
<div style="float:left; width:50%; text-align:center;">
    <img src="https://allurcode.com/content/images/2011/03/tkmaxx_rebrand_1.jpg" alt="Before" title="TK Maxx website rebranding, logo bug">
    <em>Logo behind the image</em>
</div>
<div style="float:left; width:50%; text-align:center;">
    <img src="https://allurcode.com/content/images/2011/03/tkmaxx_rebrand_2.jpg" alt="After" title="TK Maxx website rebranding, logo bug">
    <em>Logo on top of the image</em>
</div>
<p>The trick was simple yet not obvious. <code>&lt;div&gt;</code> containing the logo needs not only its z-index set to a higher value than sliding image, but also we have to make sure IE treats it seriously and make our CSS rule important.</p>
<pre><code class="language-css">#logo { z-index: 1000; }
</code></pre>
<p>Above will not work whereas below will work like a charm.</p>
<pre><code class="language-css">#logo { z-index: 1000 !important; }
</code></pre>
<!--kg-card-end: markdown-->]]></content:encoded></item><item><title><![CDATA[Hot off the workshop vol. 1]]></title><description><![CDATA[<!--kg-card-begin: markdown--><p>Just launched. TK Maxx and Red Nose Day campaign applications.</p>
<h3 id="facebookquiz">Facebook quiz</h3>
<p><a href="https://apps.facebook.com/red_nose_tshirt/"><img src="https://allurcode.com/content/images/2011/02/portfolio_1_1.jpg" alt loading="lazy"></a></p>
<p>Fun quiz to find out your perfect Red Nose Day t-shirt.<br>
<a href="https://apps.facebook.com/red_nose_tshirt/">View site</a></p>
<h3 id="websiteapplication">Website application</h3>
<p><a href="https://apps.facebook.com/red_nose_tshirt/"><img src="https://allurcode.com/content/images/2011/02/portfolio_1_2.jpg" alt loading="lazy"></a></p>
<p>Upload you photo with Flash uploader, resize it and pan it around with JavaScript then save your results with PHP.<br>
<a href="https://apps.facebook.com/red_nose_tshirt/">View site</a></p>
<!--kg-card-end: markdown-->]]></description><link>https://allurcode.com/hot-off-the-workshop-vol-1/</link><guid isPermaLink="false">5b7b0aa2b52b43084c9ea132</guid><category><![CDATA[CSS]]></category><category><![CDATA[Facebook]]></category><category><![CDATA[HTML]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[MySQL]]></category><category><![CDATA[PHP]]></category><dc:creator><![CDATA[Wojtek]]></dc:creator><pubDate>Wed, 23 Feb 2011 11:51:53 GMT</pubDate><content:encoded><![CDATA[<!--kg-card-begin: markdown--><p>Just launched. TK Maxx and Red Nose Day campaign applications.</p>
<h3 id="facebookquiz">Facebook quiz</h3>
<p><a href="https://apps.facebook.com/red_nose_tshirt/"><img src="https://allurcode.com/content/images/2011/02/portfolio_1_1.jpg" alt loading="lazy"></a></p>
<p>Fun quiz to find out your perfect Red Nose Day t-shirt.<br>
<a href="https://apps.facebook.com/red_nose_tshirt/">View site</a></p>
<h3 id="websiteapplication">Website application</h3>
<p><a href="https://apps.facebook.com/red_nose_tshirt/"><img src="https://allurcode.com/content/images/2011/02/portfolio_1_2.jpg" alt loading="lazy"></a></p>
<p>Upload you photo with Flash uploader, resize it and pan it around with JavaScript then save your results with PHP.<br>
<a href="https://apps.facebook.com/red_nose_tshirt/">View site</a></p>
<!--kg-card-end: markdown-->]]></content:encoded></item><item><title><![CDATA[Self executing function in JavaScript]]></title><description><![CDATA[<!--kg-card-begin: markdown--><p>In my last project I needed a function in JavaScript that will execute itself as soon as it&#x2019;s ready. My first idea was something like that:</p>
<pre><code class="language-js">// declare function
function myFunction() {
  alert(&apos;Hello world!&apos;);
}
// run it when DOM is ready with help of jQuery
$(document).ready(function(</code></pre>]]></description><link>https://allurcode.com/self-executing-function-in-javascript/</link><guid isPermaLink="false">5b7b0aa2b52b43084c9ea12b</guid><category><![CDATA[function]]></category><category><![CDATA[JavaScript]]></category><dc:creator><![CDATA[Wojtek]]></dc:creator><pubDate>Thu, 30 Sep 2010 11:37:51 GMT</pubDate><content:encoded><![CDATA[<!--kg-card-begin: markdown--><p>In my last project I needed a function in JavaScript that will execute itself as soon as it&#x2019;s ready. My first idea was something like that:</p>
<pre><code class="language-js">// declare function
function myFunction() {
  alert(&apos;Hello world!&apos;);
}
// run it when DOM is ready with help of jQuery
$(document).ready(function() {
  myFunction();
});
</code></pre>
<p>but in the back of my mind I knew there is a better way, without any dependancies. A little bit of googling resulted in something unbelievably simple like this:</p>
<pre><code class="language-js">(function() {
  alert(&apos;Hello world!&apos;);
})();
</code></pre>
<p>If you want, you can pass arguments as you&#x2019;d normally do:</p>
<pre><code class="language-js">(function( arg ) {
  alert(&apos;Hello world! &apos;+arg);
})(9999);
// result: &quot;Hello world! 9999&quot;
</code></pre>
<p>Quick and simple &#x1F642;</p>
<!--kg-card-end: markdown-->]]></content:encoded></item><item><title><![CDATA[JavaScript, return index of an element in array]]></title><description><![CDATA[<!--kg-card-begin: markdown--><p>Recently I&#x2019;ve been working on a <a href="http://lookbook.monsoon-accessorize.co.uk/">project</a> with HTML5&apos;s <code>&lt;video&gt;</code> tag event handling and I needed to check if an element exists in the array. Quick googling resulted in neat native JavaScript method <code>Array.indexOf</code>. It returns the first index at which a given</p>]]></description><link>https://allurcode.com/javascript-return-index-of-an-element-in-array/</link><guid isPermaLink="false">5b7b0aa2b52b43084c9ea12a</guid><category><![CDATA[array]]></category><category><![CDATA[bug]]></category><category><![CDATA[fix]]></category><category><![CDATA[ie]]></category><category><![CDATA[index]]></category><category><![CDATA[indexOf]]></category><category><![CDATA[JavaScript]]></category><dc:creator><![CDATA[Wojtek]]></dc:creator><pubDate>Mon, 30 Aug 2010 19:41:20 GMT</pubDate><content:encoded><![CDATA[<!--kg-card-begin: markdown--><p>Recently I&#x2019;ve been working on a <a href="http://lookbook.monsoon-accessorize.co.uk/">project</a> with HTML5&apos;s <code>&lt;video&gt;</code> tag event handling and I needed to check if an element exists in the array. Quick googling resulted in neat native JavaScript method <code>Array.indexOf</code>. It returns the first index at which a given element can be found in an array, or -1 if it is not present. It all worked just fine in Firefox, Chrome and such.<br>
Why wasn&#x2019;t I surprised when my script behaved a bit weird in Internet Explorer. After many hours of &quot;fun&quot; with IE JavaScript debugger, I found that none of IE versions support the <code>Array.indexOf</code> method.</p>
<p>Thanks to <a href="http://soledadpenades.com/2007/05/17/arrayindexof-in-internet-explorer/">this post</a> I was able to quickly fix it by adding below code to my script.</p>
<pre><code class="language-js">if(!Array.indexOf) {
  Array.prototype.indexOf = function(obj) {
    for(var i=0; i&lt;this.length; i++) {
      if(this[i]===obj) {
        return i;
      }
    }
    return -1;
  }
}
</code></pre>
<p>and the world was beautiful again.</p>
<!--kg-card-end: markdown-->]]></content:encoded></item><item><title><![CDATA[Simple JavaScript popup window]]></title><description><![CDATA[<!--kg-card-begin: markdown--><p>Over the years I used a lot of JavaScript functions to open PopUp windows. Some time ago I wrote this simple function and I use it everywhere where I need to open a new window.<br>
Add the following to your JavaScript file or embed it in the <code>&lt;script type=</code></p>]]></description><link>https://allurcode.com/simple-javascript-popup-window/</link><guid isPermaLink="false">5b7b0aa2b52b43084c9ea10d</guid><category><![CDATA[JavaScript]]></category><dc:creator><![CDATA[Wojtek]]></dc:creator><pubDate>Sat, 19 Apr 2008 13:43:33 GMT</pubDate><content:encoded><![CDATA[<!--kg-card-begin: markdown--><p>Over the years I used a lot of JavaScript functions to open PopUp windows. Some time ago I wrote this simple function and I use it everywhere where I need to open a new window.<br>
Add the following to your JavaScript file or embed it in the <code>&lt;script type=&quot;text/javascript&quot;&gt;&lt;/script&gt;</code> tag somewhere on your website:</p>
<pre><code class="language-javascript">function popUp(strURL, strName, strType, strTop, strLeft, strWidth, strHeight) {
  var strOptions = &quot;&quot;;
  if (strType == &quot;console&quot;) strOptions = &quot;resizable, top=&quot;+strTop+&quot;, left=&quot;+strLeft+&quot;, width=&quot;+strWidth+&quot;, height=&quot;+strHeight;
  if (strType == &quot;fixed&quot;) strOptions = &quot;status, top=&quot;+strTop+&quot;, left=&quot;+strLeft+&quot;, width=&quot;+strWidth+&quot;, height=&quot;+strHeight;
  if (strType == &quot;elastic&quot;) strOptions = &quot;toolbar, menubar, scrollbars, resizable, location, top=&quot;+strTop+&quot;, left=&quot;+strLeft+&quot;, width=&quot;+strWidth+&quot;, height=&quot;+strHeight;
  var newWin = window.open(strURL, strName, strOptions); newWin.focus();
}
</code></pre>
<p>and to run it simply write:</p>
<pre><code class="language-html">&lt;a href=&quot;/file.php&quot; onclick=&quot;popUp(&apos;https://some_url&apos;, &apos;frame name&apos;, &apos;console&apos;, 100, 100, 300, 300)&quot;&gt;your link&lt;/a&gt;
</code></pre>
<p>You can easily pass variables to this file like that:</p>
<pre><code class="language-html">&lt;a href=&quot;/file.php?id=9&quot; onclick=&quot;popUp(&apos;https://some_url&apos;, &apos;frame name&apos;, &apos;console&apos;, 100, 100, 300, 300)&quot;&gt;your link&lt;/a&gt;
</code></pre>
<p>Enjoy!</p>
<!--kg-card-end: markdown-->]]></content:encoded></item></channel></rss>