javascript.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. ace.define("ace/snippets/javascript",[], function(require, exports, module) {
  2. "use strict";
  3. exports.snippetText = "# Prototype\n\
  4. snippet proto\n\
  5. ${1:class_name}.prototype.${2:method_name} = function(${3:first_argument}) {\n\
  6. ${4:// body...}\n\
  7. };\n\
  8. # Function\n\
  9. snippet fun\n\
  10. function ${1?:function_name}(${2:argument}) {\n\
  11. ${3:// body...}\n\
  12. }\n\
  13. # Anonymous Function\n\
  14. regex /((=)\\s*|(:)\\s*|(\\()|\\b)/f/(\\))?/\n\
  15. snippet f\n\
  16. function${M1?: ${1:functionName}}($2) {\n\
  17. ${0:$TM_SELECTED_TEXT}\n\
  18. }${M2?;}${M3?,}${M4?)}\n\
  19. # Immediate function\n\
  20. trigger \\(?f\\(\n\
  21. endTrigger \\)?\n\
  22. snippet f(\n\
  23. (function(${1}) {\n\
  24. ${0:${TM_SELECTED_TEXT:/* code */}}\n\
  25. }(${1}));\n\
  26. # if\n\
  27. snippet if\n\
  28. if (${1:true}) {\n\
  29. ${0}\n\
  30. }\n\
  31. # if ... else\n\
  32. snippet ife\n\
  33. if (${1:true}) {\n\
  34. ${2}\n\
  35. } else {\n\
  36. ${0}\n\
  37. }\n\
  38. # tertiary conditional\n\
  39. snippet ter\n\
  40. ${1:/* condition */} ? ${2:a} : ${3:b}\n\
  41. # switch\n\
  42. snippet switch\n\
  43. switch (${1:expression}) {\n\
  44. case '${3:case}':\n\
  45. ${4:// code}\n\
  46. break;\n\
  47. ${5}\n\
  48. default:\n\
  49. ${2:// code}\n\
  50. }\n\
  51. # case\n\
  52. snippet case\n\
  53. case '${1:case}':\n\
  54. ${2:// code}\n\
  55. break;\n\
  56. ${3}\n\
  57. \n\
  58. # while (...) {...}\n\
  59. snippet wh\n\
  60. while (${1:/* condition */}) {\n\
  61. ${0:/* code */}\n\
  62. }\n\
  63. # try\n\
  64. snippet try\n\
  65. try {\n\
  66. ${0:/* code */}\n\
  67. } catch (e) {}\n\
  68. # do...while\n\
  69. snippet do\n\
  70. do {\n\
  71. ${2:/* code */}\n\
  72. } while (${1:/* condition */});\n\
  73. # Object Method\n\
  74. snippet :f\n\
  75. regex /([,{[])|^\\s*/:f/\n\
  76. ${1:method_name}: function(${2:attribute}) {\n\
  77. ${0}\n\
  78. }${3:,}\n\
  79. # setTimeout function\n\
  80. snippet setTimeout\n\
  81. regex /\\b/st|timeout|setTimeo?u?t?/\n\
  82. setTimeout(function() {${3:$TM_SELECTED_TEXT}}, ${1:10});\n\
  83. # Get Elements\n\
  84. snippet gett\n\
  85. getElementsBy${1:TagName}('${2}')${3}\n\
  86. # Get Element\n\
  87. snippet get\n\
  88. getElementBy${1:Id}('${2}')${3}\n\
  89. # console.log (Firebug)\n\
  90. snippet cl\n\
  91. console.log(${1});\n\
  92. # return\n\
  93. snippet ret\n\
  94. return ${1:result}\n\
  95. # for (property in object ) { ... }\n\
  96. snippet fori\n\
  97. for (var ${1:prop} in ${2:Things}) {\n\
  98. ${0:$2[$1]}\n\
  99. }\n\
  100. # hasOwnProperty\n\
  101. snippet has\n\
  102. hasOwnProperty(${1})\n\
  103. # docstring\n\
  104. snippet /**\n\
  105. /**\n\
  106. * ${1:description}\n\
  107. *\n\
  108. */\n\
  109. snippet @par\n\
  110. regex /^\\s*\\*\\s*/@(para?m?)?/\n\
  111. @param {${1:type}} ${2:name} ${3:description}\n\
  112. snippet @ret\n\
  113. @return {${1:type}} ${2:description}\n\
  114. # JSON.parse\n\
  115. snippet jsonp\n\
  116. JSON.parse(${1:jstr});\n\
  117. # JSON.stringify\n\
  118. snippet jsons\n\
  119. JSON.stringify(${1:object});\n\
  120. # self-defining function\n\
  121. snippet sdf\n\
  122. var ${1:function_name} = function(${2:argument}) {\n\
  123. ${3:// initial code ...}\n\
  124. \n\
  125. $1 = function($2) {\n\
  126. ${4:// main code}\n\
  127. };\n\
  128. }\n\
  129. # singleton\n\
  130. snippet sing\n\
  131. function ${1:Singleton} (${2:argument}) {\n\
  132. // the cached instance\n\
  133. var instance;\n\
  134. \n\
  135. // rewrite the constructor\n\
  136. $1 = function $1($2) {\n\
  137. return instance;\n\
  138. };\n\
  139. \n\
  140. // carry over the prototype properties\n\
  141. $1.prototype = this;\n\
  142. \n\
  143. // the instance\n\
  144. instance = new $1();\n\
  145. \n\
  146. // reset the constructor pointer\n\
  147. instance.constructor = $1;\n\
  148. \n\
  149. ${3:// code ...}\n\
  150. \n\
  151. return instance;\n\
  152. }\n\
  153. # class\n\
  154. snippet class\n\
  155. regex /^\\s*/clas{0,2}/\n\
  156. var ${1:class} = function(${20}) {\n\
  157. $40$0\n\
  158. };\n\
  159. \n\
  160. (function() {\n\
  161. ${60:this.prop = \"\"}\n\
  162. }).call(${1:class}.prototype);\n\
  163. \n\
  164. exports.${1:class} = ${1:class};\n\
  165. # \n\
  166. snippet for-\n\
  167. for (var ${1:i} = ${2:Things}.length; ${1:i}--; ) {\n\
  168. ${0:${2:Things}[${1:i}];}\n\
  169. }\n\
  170. # for (...) {...}\n\
  171. snippet for\n\
  172. for (var ${1:i} = 0; $1 < ${2:Things}.length; $1++) {\n\
  173. ${3:$2[$1]}$0\n\
  174. }\n\
  175. # for (...) {...} (Improved Native For-Loop)\n\
  176. snippet forr\n\
  177. for (var ${1:i} = ${2:Things}.length - 1; $1 >= 0; $1--) {\n\
  178. ${3:$2[$1]}$0\n\
  179. }\n\
  180. \n\
  181. \n\
  182. #modules\n\
  183. snippet def\n\
  184. define(function(require, exports, module) {\n\
  185. \"use strict\";\n\
  186. var ${1/.*\\///} = require(\"${1}\");\n\
  187. \n\
  188. $TM_SELECTED_TEXT\n\
  189. });\n\
  190. snippet req\n\
  191. guard ^\\s*\n\
  192. var ${1/.*\\///} = require(\"${1}\");\n\
  193. $0\n\
  194. snippet requ\n\
  195. guard ^\\s*\n\
  196. var ${1/.*\\/(.)/\\u$1/} = require(\"${1}\").${1/.*\\/(.)/\\u$1/};\n\
  197. $0\n\
  198. ";
  199. exports.scope = "javascript";
  200. });
  201. (function() {
  202. ace.require(["ace/snippets/javascript"], function(m) {
  203. if (typeof module == "object" && typeof exports == "object" && module) {
  204. module.exports = m;
  205. }
  206. });
  207. })();