HTML, CSS and JS snippets for your Sublime Text 2 & 3
To install through package control, search for Steven Snippets or typically the keywords js or javascript are suitable.
If you prefer to install it manually, you can download the package and put it inside your Packages
directory. It should work but will not update automatically.
Go to your Sublime Text 2 Packages directory and clone the repository using the command below:
git clone git://github.com/wangwen1220/steven-snippets.git steven-snippets
console.warn(${1:msg});
${1:document}.addEventListener('${2:event}', function(e) {
$3
});
${1:document}.appendChild(${2:elem});
${1:document}.removeChild(${2:elem});
${1:document}.insertBefore(${2:elem}, ${3:null});
${1:document}.createElement(${2:elem});
${1:document}.createDocumentFragment(${2:elem});
${1:document}.classList.add('${2:class}');
${1:document}.classList.toggle('${2:class}');
${1:document}.classList.remove('${2:class}');
${1:document}.getElementById('${2:id}');
${1:document}.getElementsByClassName('${2:class}');
${1:document}.getElementsByTagName('${2:tag}');
${1:document}.getAttribute('${2:attr}');
${1:document}.setAttribute('${2:attr}', ${3:value});
${1:document}.removeAttribute('${2:attr}');
${1:document}.innerHTML = '${2:elem}';
${1:document}.textContent = '${2:content}';
${1:document}.querySelector('${2:selector}');
${1:document}.querySelectorAll('${2:selector}');
${1:myArray}.forEach(function(${2:elem}) {
${3}
});
for (${1:prop} in ${2:obj}) {
if (${2:obj}.hasOwnProperty(${1:prop})) {
${3}
}
}
function ${1:methodName}(${2:arguments}) {
${3}
}
function(${1:arguments}) {
${2}
}
(function($1) {
$2
})($0);
(function($) {
$0
})(jQuery);
${1:ClassName}.prototype.${2:methodName} = function(${3:arguments}) {
${4}
}
(function(window, document, undefined) {
${1}
})(window, document);
${1:methodName}.call(${2:context}, ${3:arguments})
${1:methodName}.apply(${2:context}, [${3:arguments}])
${1:functionName}: function (${2:arguments}) {
${3}
}
setInterval(function() {
${2}
}, ${1:delay});
setTimeout(function() {
${2}
}, ${1:delay});
assert.equal(${1:actual}, ${2:expected});
assert.deepEqual(${1:actual}, ${2:expected});
assert.notEqual(${1:actual}, ${2:expected});
process.exit(${1:code});
prompt(${1:'msg'});
do
do {
${1:expression}
} while (${2:condition});
if
if (${1:condition}) {
$2
}
ife
if (${1:condition}) {
$2
} else {
$3
}
ifeif
if (${1:condition}) {
$2
} else if {
$3
} else {
$4
}
for
for (${1:var i = 0}; ${2:i < ${3:elements.length}}; ${4:i++}) {
${5:expression}
}
log
console.log(${1:'test'});
alt
alert(${1:'test'});
ls
if (localStorage.${1:item}) {
var ${1:item} = localStorage.${1:item};
$2
}
.pd
.preventDefault();
.sp
.stopPropagation();
rand
Math.floor(Math.random() * ${1:10})
switch
switch(${1:var}) {
case $2:
$3
break;
case $4:
$5
break;
default:
{$6:break};
}
setInterval
setInterval(function() {
$2
}, ${1:millis});
setTimeout
setTimeout(function() {
$2
}, ${1:millis});
while
while (${1:condition}) {
${2:expression}
};