157 lines
4 KiB
Text
157 lines
4 KiB
Text
priority -50
|
|
|
|
############
|
|
# COMMON #
|
|
############
|
|
|
|
# The smart snippets use a global options called
|
|
# "g:ultisnips_javascript.{option}" which can control the format
|
|
# of trailing semicolon, space before function paren, etc.
|
|
#
|
|
# e.g.
|
|
# let g:ultisnips_javascript = {
|
|
# \ 'keyword-spacing': 'always',
|
|
# \ 'semi': 'never',
|
|
# \ 'space-before-function-paren': 'always',
|
|
# \ }
|
|
|
|
|
|
global !p
|
|
from javascript_snippets import (
|
|
semi, space_before_function_paren, keyword_spacing
|
|
)
|
|
endglobal
|
|
|
|
###########################################################################
|
|
# TextMate Snippets #
|
|
###########################################################################
|
|
snippet get "Get Elements"
|
|
getElement${1/(T)|(C)|.*/(?1:s)(?2:s)/}By${1:T}${1/(T)|(I)|(C).*/(?1:agName)(?2:d)(?3:lassName)/}('$2')
|
|
endsnippet
|
|
|
|
snippet '':f "object method string"
|
|
'${1:${2:#thing}:${3:click}}': function`!p snip.rv = space_before_function_paren(snip)`(element) {
|
|
${VISUAL}$0
|
|
}${10:,}
|
|
endsnippet
|
|
|
|
snippet :f "Object Method"
|
|
${1:method_name}: function`!p snip.rv = space_before_function_paren(snip)`(${3:attribute}) {
|
|
${VISUAL}$0
|
|
}${10:,}
|
|
endsnippet
|
|
|
|
snippet :, "Object Value JS"
|
|
${1:value_name}: ${0:value},
|
|
endsnippet
|
|
|
|
snippet : "Object key key: 'value'"
|
|
${1:key}: ${2:"${3:value}"}${4:, }
|
|
endsnippet
|
|
|
|
snippet proto "Prototype (proto)"
|
|
${1:class_name}.prototype.${2:method_name} = function`!p snip.rv = space_before_function_paren(snip)`(${3:first_argument}) {
|
|
${VISUAL}$0
|
|
}`!p snip.rv = semi(snip)`
|
|
|
|
endsnippet
|
|
|
|
snippet fun "function (named)" b
|
|
function ${1:function_name}`!p snip.rv = space_before_function_paren(snip)`(${2:argument}) {
|
|
${VISUAL}$0
|
|
}
|
|
endsnippet
|
|
|
|
snippet vf "function (assigned to var)"
|
|
${1:var }${2:function_name} = function $2`!p snip.rv = space_before_function_paren(snip)`($3) {
|
|
${VISUAL}$0
|
|
}`!p snip.rv = semi(snip)`
|
|
endsnippet
|
|
|
|
# Drop priority so this only triggers when not beginning of line.
|
|
priority -51
|
|
snippet fun "function (anonymous)" w
|
|
function`!p snip.rv = space_before_function_paren(snip)`($1) {
|
|
${VISUAL}$0
|
|
}$2
|
|
endsnippet
|
|
priority -50
|
|
|
|
snippet anf "function (anonymous)" i
|
|
function`!p snip.rv = space_before_function_paren(snip)`($1) {
|
|
${VISUAL}$0
|
|
}
|
|
endsnippet
|
|
|
|
snippet iife "Immediately-Invoked Function Expression (iife)"
|
|
(function`!p snip.rv = space_before_function_paren(snip)`(${1:window}) {
|
|
${VISUAL}$0
|
|
}(${2:$1}))`!p snip.rv = semi(snip)`
|
|
endsnippet
|
|
|
|
snippet ;fe "Minify safe iife"
|
|
;(function`!p snip.rv = space_before_function_paren(snip)`(${1}) {
|
|
${VISUAL}$0
|
|
}(${2}))
|
|
endsnippet
|
|
|
|
snippet timeout "setTimeout function"
|
|
setTimeout(function`!p snip.rv = space_before_function_paren(snip)`() {
|
|
${VISUAL}$0
|
|
}${2:.bind(${3:this})}, ${1:10})`!p snip.rv = semi(snip)`
|
|
endsnippet
|
|
|
|
snippet fi "for prop in obj using hasOwnProperty" b
|
|
for`!p snip.rv = keyword_spacing(snip)`(${1:prop} in ${2:obj}){
|
|
if`!p snip.rv = keyword_spacing(snip)`($2.hasOwnProperty($1)) {
|
|
${VISUAL}$0
|
|
}
|
|
}
|
|
endsnippet
|
|
|
|
snippet if "if (condition) { ... }"
|
|
if`!p snip.rv = keyword_spacing(snip)`(${1:true}) {
|
|
${VISUAL}$0
|
|
}
|
|
endsnippet
|
|
|
|
snippet ife "if (condition) { ... } else { ... }"
|
|
if`!p snip.rv = keyword_spacing(snip)`(${1:true}) {
|
|
${VISUAL}$0
|
|
}`!p snip.rv = keyword_spacing(snip)`else`!p snip.rv = keyword_spacing(snip)`{
|
|
${2}
|
|
}
|
|
endsnippet
|
|
|
|
snippet switch
|
|
switch`!p snip.rv = keyword_spacing(snip)`(${VISUAL}${1:expression}) {
|
|
case '${VISUAL}${3:case}':
|
|
${4}
|
|
break`!p snip.rv = semi(snip)`
|
|
${0}
|
|
default:
|
|
${2}
|
|
}
|
|
endsnippet
|
|
|
|
snippet case "case 'xyz': ... break"
|
|
case`!p snip.rv = keyword_spacing(snip)`'${VISUAL}${1:case}':
|
|
${VISUAL}$0
|
|
break`!p snip.rv = semi(snip)`
|
|
endsnippet
|
|
|
|
snippet do "do { ... } while (condition)"
|
|
do`!p snip.rv = keyword_spacing(snip)`{
|
|
${VISUAL}$0
|
|
}`!p snip.rv = keyword_spacing(snip)`while`!p snip.rv = keyword_spacing(snip)`(${1:/* condition */})`!p snip.rv = semi(snip)`
|
|
endsnippet
|
|
|
|
snippet ret "Return statement"
|
|
return ${VISUAL}$0`!p snip.rv = semi(snip)`
|
|
endsnippet
|
|
|
|
snippet us
|
|
'use strict'`!p snip.rv = semi(snip)`
|
|
endsnippet
|
|
|
|
# vim:ft=snippets:
|