Skip to content

Instantly share code, notes, and snippets.

View fschell's full-sized avatar

Folker Schellenberg fschell

View GitHub Profile
@fschell
fschell / IIFE.js
Created September 24, 2015 13:47
Immediately-Invoked Function Expression (IIFE)
// IIFE
(function(){ /* code */ }()); // Crockford recommends this one
(function(){ /* code */ })(); // But this one works just as well
// if you use mootools and jQuery in compat mode and mootools exposes $ and jQuery jQuery like so:
<script src="mootools.js"></script>
<script src="jquery.js"></script>
var jQuery = jQuery.noConflict();
// then you can use legacy code which uses jQuery like so
@fschell
fschell / joomGetLang.php
Last active September 24, 2015 13:31
Joomla get Language
// get language
$lang = JFactory::getLanguage()->getLocale()[4];
if ($lang === 'en') {
...
}
//-----------------------------------------------------------------------------------
// inject it into javascript global namespace (e.g. in joomla template index.php)
@fschell
fschell / Magento_Backend_Logo
Created September 18, 2015 10:49
Magento Backend Logo
@fschell
fschell / NodeListToArray.js
Last active September 15, 2015 13:58
NodeList to Array
// create array from NodeList without modifying NodeList Prototype
var arr = Array.prototype.slice.call( document.querySelectorAll('div') );
// extend NodeList prototype...
NodeList.prototype.array = function() {
return Array.prototype.slice.call(this);
};
// ...and use it as chained method
var arr = document.querySelectorAll('div').array();
@fschell
fschell / mapReduce
Created September 10, 2015 15:05
map reduce, javascript
var users = [
{name:'johndoe', password: 'secret', displayName: 'John Doe'},
{name:'elladoe', password: 'secret', displayName: 'Ella Doe'},
{name:'minidoe', password: 'secret', displayName: 'Mini Doe'}
];
var username = 'johndoe';
// return current user or null if not found
var user = users.map(function(user){
@fschell
fschell / mageStoreDetails
Last active August 29, 2015 14:08
Magento Store Details
<?php
// Gets the current store's details
$store = Mage::app()->getStore();
// Gets the current store's id
$storeId = Mage::app()->getStore()->getStoreId();
// Gets the current store's code
$storeCode = Mage::app()->getStore()->getCode();
@fschell
fschell / joomlaAddTmplQS.js
Created March 4, 2014 10:13
joomla! plain component output - add tmpl=component to query string
$('a').each(function(){
var $this = $(this);
$this.attr('href',$this.attr('href') + '?tmpl=component');
});
@fschell
fschell / injectJQ.js
Created March 4, 2014 10:10
inject jQuery into console
var jq = document.createElement('script');
jq.src = "//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
jQuery.noConflict();
@fschell
fschell / capitalize.js
Created March 4, 2014 09:54
capitalize.js
// capitalize string
String.prototype.cap = function(){
return this.replace( /(^|\s)([a-z])/g , function(m,p1,p2){return p1+p2.toUpperCase();});
};
@fschell
fschell / trim.js
Created March 4, 2014 09:53
trim.js
if (!String.prototype.trim) {
String.prototype.trim = function () {
return this.replace(/^\s+|\s+$/g, '');
};
}