snipt

Ctrl+h for KB shortcuts

JavaScript

Pad numbers to fixed places

1
2
3
4
function zeroPad(num, places) {
    var zero = places - num.toString().length + 1;
    return Array(+(zero > 0 && zero)).join("0") + num;
}
https://snipt.net/embed/e7ba08b4a2a6ccb74e3f6633346c8e18/
/raw/e7ba08b4a2a6ccb74e3f6633346c8e18/
e7ba08b4a2a6ccb74e3f6633346c8e18
js
JavaScript
4
2019-08-20T02:05:27
True
False
False
/api/public/snipt/107386/
pad-numbers-to-fixed-places
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="kd">function</span> <span class="nx">zeroPad</span><span class="p">(</span><span class="nx">num</span><span class="p">,</span> <span class="nx">places</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-2"><a name="L-2"></a> <span class="kd">var</span> <span class="nx">zero</span> <span class="o">=</span> <span class="nx">places</span> <span class="o">-</span> <span class="nx">num</span><span class="p">.</span><span class="nx">toString</span><span class="p">().</span><span class="nx">length</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span> </span><span id="L-3"><a name="L-3"></a> <span class="k">return</span> <span class="nb">Array</span><span class="p">(</span><span class="o">+</span><span class="p">(</span><span class="nx">zero</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="o">&amp;&amp;</span> <span class="nx">zero</span><span class="p">)).</span><span class="nx">join</span><span class="p">(</span><span class="s2">&quot;0&quot;</span><span class="p">)</span> <span class="o">+</span> <span class="nx">num</span><span class="p">;</span> </span><span id="L-4"><a name="L-4"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
js, number, pad, places

JavaScript

jQuery datepicker localization

1
2
3
4
5
6
7
$('#date').datepicker({
	showAnim: 'fold',
	dayNamesMin: [ "Ned", "Pon", "Uto", "Sri", "Čet", "Pet", "Sub" ],
	monthNames: [ "Siječanj", "Veljača", "Ožujak", "Travanj", "Svibanj", "Lipanj", "Srpanj", "Kolovoz", "Rujan", "Listopad", "Studeni", "Prosinac" ],
	dateFormat: 'dd.mm.yy',
	firstDay: 1
});
https://snipt.net/embed/003373c31578bb1a098d60852e9c771c/
/raw/003373c31578bb1a098d60852e9c771c/
003373c31578bb1a098d60852e9c771c
js
JavaScript
7
2019-07-31T20:46:38
True
False
False
/api/public/snipt/79176/
jquery-datepicker-localization
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="nx">$</span><span class="p">(</span><span class="s1">&#39;#date&#39;</span><span class="p">).</span><span class="nx">datepicker</span><span class="p">({</span> </span><span id="L-2"><a name="L-2"></a> <span class="nx">showAnim</span><span class="o">:</span> <span class="s1">&#39;fold&#39;</span><span class="p">,</span> </span><span id="L-3"><a name="L-3"></a> <span class="nx">dayNamesMin</span><span class="o">:</span> <span class="p">[</span> <span class="s2">&quot;Ned&quot;</span><span class="p">,</span> <span class="s2">&quot;Pon&quot;</span><span class="p">,</span> <span class="s2">&quot;Uto&quot;</span><span class="p">,</span> <span class="s2">&quot;Sri&quot;</span><span class="p">,</span> <span class="s2">&quot;Čet&quot;</span><span class="p">,</span> <span class="s2">&quot;Pet&quot;</span><span class="p">,</span> <span class="s2">&quot;Sub&quot;</span> <span class="p">],</span> </span><span id="L-4"><a name="L-4"></a> <span class="nx">monthNames</span><span class="o">:</span> <span class="p">[</span> <span class="s2">&quot;Siječanj&quot;</span><span class="p">,</span> <span class="s2">&quot;Veljača&quot;</span><span class="p">,</span> <span class="s2">&quot;Ožujak&quot;</span><span class="p">,</span> <span class="s2">&quot;Travanj&quot;</span><span class="p">,</span> <span class="s2">&quot;Svibanj&quot;</span><span class="p">,</span> <span class="s2">&quot;Lipanj&quot;</span><span class="p">,</span> <span class="s2">&quot;Srpanj&quot;</span><span class="p">,</span> <span class="s2">&quot;Kolovoz&quot;</span><span class="p">,</span> <span class="s2">&quot;Rujan&quot;</span><span class="p">,</span> <span class="s2">&quot;Listopad&quot;</span><span class="p">,</span> <span class="s2">&quot;Studeni&quot;</span><span class="p">,</span> <span class="s2">&quot;Prosinac&quot;</span> <span class="p">],</span> </span><span id="L-5"><a name="L-5"></a> <span class="nx">dateFormat</span><span class="o">:</span> <span class="s1">&#39;dd.mm.yy&#39;</span><span class="p">,</span> </span><span id="L-6"><a name="L-6"></a> <span class="nx">firstDay</span><span class="o">:</span> <span class="mi">1</span> </span><span id="L-7"><a name="L-7"></a><span class="p">});</span> </span></pre></div> </td></tr></table>
datepicker, jQuery, js, localization

JavaScript

IE friendly addEventListener

1
2
3
4
5
if (window.addEventListener) {
    
} else if (window.attachEvent) {

}
https://snipt.net/embed/25a59766ebbc55486598c5e1a7c025f8/
/raw/25a59766ebbc55486598c5e1a7c025f8/
25a59766ebbc55486598c5e1a7c025f8
js
JavaScript
6
2019-08-20T02:39:27
True
False
False
/api/public/snipt/77414/
ie-friendly-addeventlistener
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="k">if</span> <span class="p">(</span><span class="nb">window</span><span class="p">.</span><span class="nx">addEventListener</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="nb">window</span><span class="p">.</span><span class="nx">attachEvent</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
addEventListener, compatibility, ie, javascript, js