<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Javascript on Laïla Atrmouh</title>
    <link>/en/tags/javascript/</link>
    <description>Recent content in Javascript on Laïla Atrmouh</description>
    <generator>Hugo</generator>
    <language>en</language>
    <copyright>&lt;a href=&#34;https://creativecommons.org/licenses/by-nc/4.0/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;CC BY-NC 4.0&lt;/a&gt;</copyright>
    <lastBuildDate>Fri, 13 May 2016 20:37:49 +0000</lastBuildDate>
    <atom:link href="/en/tags/javascript/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Prototype Cheat Sheet</title>
      <link>/en/posts/2016/05/prototype-cheat-sheet/</link>
      <pubDate>Fri, 13 May 2016 20:37:49 +0000</pubDate>
      <guid>/en/posts/2016/05/prototype-cheat-sheet/</guid>
      <description>&lt;blockquote&gt;&#xA;&lt;p&gt;👴 &lt;em&gt;Careful&lt;/em&gt; You&amp;rsquo;re reading an old article ! Some links might be broken and content may be outdated&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;I had to deal with Prototype while working with Magento. Here’s a little cheat sheet of some very simple stuff I had to do.&lt;/p&gt;&#xA;&lt;h2 id=&#34;make-an-ajax-requestwithparameters&#34;&gt;Make an Ajax Request with parameters&lt;/h2&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;new&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;Ajax&lt;/span&gt;.&lt;span style=&#34;color:#a6e22e&#34;&gt;Request&lt;/span&gt;(&lt;span style=&#34;color:#a6e22e&#34;&gt;url&lt;/span&gt;, {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                   &lt;span style=&#34;color:#a6e22e&#34;&gt;method&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;:&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;get&amp;#39;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                   &lt;span style=&#34;color:#a6e22e&#34;&gt;params&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;:&lt;/span&gt; { &lt;span style=&#34;color:#a6e22e&#34;&gt;data1&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;:&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;myParam&amp;#39;&lt;/span&gt; }&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                   &lt;span style=&#34;color:#a6e22e&#34;&gt;onSuccess&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;:&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;function&lt;/span&gt;(&lt;span style=&#34;color:#a6e22e&#34;&gt;xhr&lt;/span&gt;){&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                    &lt;span style=&#34;color:#a6e22e&#34;&gt;console&lt;/span&gt;.&lt;span style=&#34;color:#a6e22e&#34;&gt;log&lt;/span&gt;(&lt;span style=&#34;color:#a6e22e&#34;&gt;xhr&lt;/span&gt;.&lt;span style=&#34;color:#a6e22e&#34;&gt;responseText&lt;/span&gt;); &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                    &lt;span style=&#34;color:#66d9ef&#34;&gt;var&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;json&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;JSON&lt;/span&gt;.&lt;span style=&#34;color:#a6e22e&#34;&gt;parse&lt;/span&gt;(&lt;span style=&#34;color:#a6e22e&#34;&gt;transport&lt;/span&gt;.&lt;span style=&#34;color:#a6e22e&#34;&gt;responseText&lt;/span&gt;);&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                    }&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;});&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;change-value-of-an-input&#34;&gt;Change value of an input&lt;/h2&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;$&lt;/span&gt;(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;ID OF THE ELEMENT&amp;#39;&lt;/span&gt;).&lt;span style=&#34;color:#a6e22e&#34;&gt;setValue&lt;/span&gt;(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;The new value&amp;#39;&lt;/span&gt;);&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;change-data-within-a-span-tag&#34;&gt;Change data within a span tag&lt;/h2&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;$&lt;/span&gt;(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;ID OF THE ELEMENT&amp;#39;&lt;/span&gt;).&lt;span style=&#34;color:#a6e22e&#34;&gt;update&lt;/span&gt;(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;Your new data&amp;#39;&lt;/span&gt;);&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description>
    </item>
    <item>
      <title>How to add a new stock option in Woocommerce</title>
      <link>/en/posts/2016/03/how-to-add-a-new-stock-option-in-woocommerce/</link>
      <pubDate>Tue, 22 Mar 2016 18:53:53 +0000</pubDate>
      <guid>/en/posts/2016/03/how-to-add-a-new-stock-option-in-woocommerce/</guid>
      <description>&lt;blockquote&gt;&#xA;&lt;p&gt;👴 &lt;em&gt;Careful&lt;/em&gt; You&amp;rsquo;re reading an old article ! Some links might be broken and content may be outdated&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;Sometimes, clients can come up with some pretty creative ways to handle their inventory … It was the case for me with a customer who was using WooCommerce.&lt;/p&gt;&#xA;&lt;p&gt;I had to add a third option but the stock options was not customizable. I ended up deleting the native dropdown of stock options and I implemented a custom field.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Look for a word in a group of div using only jQuery</title>
      <link>/en/posts/2016/03/look-for-a-word-in-a-group-of-div-using-only-jquery/</link>
      <pubDate>Tue, 22 Mar 2016 18:44:23 +0000</pubDate>
      <guid>/en/posts/2016/03/look-for-a-word-in-a-group-of-div-using-only-jquery/</guid>
      <description>&lt;blockquote&gt;&#xA;&lt;p&gt;👴 &lt;em&gt;Careful&lt;/em&gt; You&amp;rsquo;re reading an old article ! Some links might be broken and content may be outdated&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;For an old project, I had to implement a search tool in a static page. No option for me to use any server side language, I had to implement that search tool using Javascript / jQuery.&lt;/p&gt;&#xA;&lt;p&gt;The following function&amp;rsquo;s purpose is to :&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Search amongst a group of divs that have the class qa-faqs if a word is present in the content&lt;/li&gt;&#xA;&lt;li&gt;Exclude stop-words in french and in english from the query entered by the user&lt;/li&gt;&#xA;&lt;li&gt;List of words to exclude is in the var words_to_exclude&lt;/li&gt;&#xA;&lt;li&gt;Order the divs by data-relevance (times the searched word appears in each div)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;Please note that the following function uses the awesome plugin &lt;a href=&#34;http://bartaz.github.io/sandbox.js/jquery.highlight.html&#34;&gt;jQuery.highlight&lt;/a&gt;&lt;/p&gt;</description>
    </item>
    <item>
      <title>Convert an image into a base64 string Javascript</title>
      <link>/en/posts/2013/12/convert-an-image-into-a-base64-string-javascript/</link>
      <pubDate>Sun, 22 Dec 2013 23:26:54 +0000</pubDate>
      <guid>/en/posts/2013/12/convert-an-image-into-a-base64-string-javascript/</guid>
      <description>&lt;blockquote&gt;&#xA;&lt;p&gt;👴 &lt;em&gt;Careful&lt;/em&gt; You&amp;rsquo;re reading an old article ! Some links might be broken and content may be outdated&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;Here is a little function I did to convert an image into a base64 string (JavaScript only): &lt;a href=&#34;http://pastebin.com/Dfb8TR4g&#34;&gt;http://pastebin.com/Dfb8TR4g&lt;/a&gt;&lt;/p&gt;</description>
    </item>
    <item>
      <title>Parsing errors JSON</title>
      <link>/en/posts/2013/06/parsing-errors-json/</link>
      <pubDate>Tue, 25 Jun 2013 23:26:03 +0000</pubDate>
      <guid>/en/posts/2013/06/parsing-errors-json/</guid>
      <description>&lt;blockquote&gt;&#xA;&lt;p&gt;👴 &lt;em&gt;Careful&lt;/em&gt; You&amp;rsquo;re reading an old article ! Some links might be broken and content may be outdated&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;Parsing JSON with the jQuery method &lt;code&gt;$.parseJSON&lt;/code&gt; can be tricky to debug, specially when you’re using a mobile device.&lt;/p&gt;&#xA;&lt;p&gt;Here is a list of errors I encoutered, and the reason why they were raised.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Unexpected token u&lt;/strong&gt;&#xA;The method tries to parse a undefined variable&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Unexpected token o&lt;/strong&gt;&#xA;The method tries to parse [Object object]&lt;/p&gt;</description>
    </item>
    <item>
      <title>Best ways to debug Javascript</title>
      <link>/en/posts/2013/03/best-ways-to-debug-javascript/</link>
      <pubDate>Mon, 18 Mar 2013 23:20:37 +0000</pubDate>
      <guid>/en/posts/2013/03/best-ways-to-debug-javascript/</guid>
      <description>&lt;blockquote&gt;&#xA;&lt;p&gt;👴 &lt;em&gt;Careful&lt;/em&gt; You&amp;rsquo;re reading an old article ! Some links might be broken and content may be outdated&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;I was looking for an equivalent of PHP’s print_r to debug Javascript Objects and I found this very cool method:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;JSON&lt;/span&gt;.&lt;span style=&#34;color:#a6e22e&#34;&gt;stringify&lt;/span&gt;(&lt;span style=&#34;color:#a6e22e&#34;&gt;whatever_obj&lt;/span&gt;);&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;How about you ? How do you debug objects in Javascript ?&lt;/p&gt;</description>
    </item>
    <item>
      <title>Passing arguments in an event handler Javascript</title>
      <link>/en/posts/2013/02/passing-arguments-in-an-event-handler-javascript/</link>
      <pubDate>Tue, 26 Feb 2013 23:19:15 +0000</pubDate>
      <guid>/en/posts/2013/02/passing-arguments-in-an-event-handler-javascript/</guid>
      <description>&lt;blockquote&gt;&#xA;&lt;p&gt;👴 &lt;em&gt;Careful&lt;/em&gt; You&amp;rsquo;re reading an old article ! Some links might be broken and content may be outdated&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;I had this problem while working on Leaflet but I think it can be generalized to the issue of passing parameters to an event handler in Javascript. With the « bind » method of jQuery, you can pass parameters by using the data property of event (the object sent when an event is triggered) :&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
