You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

932 lines
34 KiB

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Semantic Modules</title>
  5. <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  6. <meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
  7. <link rel="stylesheet" media="all" href="docco.css" />
  8. </head>
  9. <body>
  10. <div id="container">
  11. <div id="background"></div>
  12. <ul class="sections">
  13. <li id="section-1">
  14. <div class="annotation">
  15. <div class="pilwrap for-h1">
  16. <a class="pilcrow" href="#section-1">&#182;</a>
  17. </div>
  18. <h1>Semantic Modules</h1>
  19. <p>This particular pattern is useful for describing a group of elements which share behavior, for example a modal or a popup.
  20. The module is made up of three parts: <em>a group definition</em>, <em>a singular definition</em>, and a <em>settings object</em>.</p>
  21. <p>Semantic is unique in that all arbitrary data is a setting. Semantic modules also are self documenting, with module.debug calls serving to explain state, and log performance data.
  22. <a href="#">Read more about coding conventions</a></p>
  23. </div>
  24. <div class="content"><div class='highlight'><pre><span class="comment">/*
  25. * # Semantic Module 1.0
  26. * http://github.com/quirkyinc/semantic
  27. *
  28. *
  29. * Copyright 2013 Contributors
  30. * Released under the MIT license
  31. * http://jquery.org/license
  32. *
  33. * Released: April 17 2013
  34. */</span>
  35. ;(<span class="function"><span class="keyword">function</span> <span class="params">( $, window, document, undefined )</span> {</span>
  36. $.fn.example = <span class="keyword">function</span>(parameters) {</pre></div></div>
  37. </li>
  38. <li id="section-2">
  39. <div class="annotation">
  40. <div class="pilwrap for-h2">
  41. <a class="pilcrow" href="#section-2">&#182;</a>
  42. </div>
  43. <h2>Group</h2>
  44. <p>Some properties remain constant across all instances of a module.</p>
  45. </div>
  46. <div class="content"><div class='highlight'><pre> <span class="keyword">var</span></pre></div></div>
  47. </li>
  48. <li id="section-3">
  49. <div class="annotation">
  50. <div class="pilwrap ">
  51. <a class="pilcrow" href="#section-3">&#182;</a>
  52. </div>
  53. <p>Store a reference to the module group, this can be useful to refer to other modules inside each module</p>
  54. </div>
  55. <div class="content"><div class='highlight'><pre> $allModules = $(<span class="keyword">this</span>),</pre></div></div>
  56. </li>
  57. <li id="section-4">
  58. <div class="annotation">
  59. <div class="pilwrap ">
  60. <a class="pilcrow" href="#section-4">&#182;</a>
  61. </div>
  62. <p>Extend settings to merge run-time settings with defaults</p>
  63. </div>
  64. <div class="content"><div class='highlight'><pre> settings = $.extend(<span class="literal">true</span>, {}, $.fn.example.settings, parameters),</pre></div></div>
  65. </li>
  66. <li id="section-5">
  67. <div class="annotation">
  68. <div class="pilwrap ">
  69. <a class="pilcrow" href="#section-5">&#182;</a>
  70. </div>
  71. <p>Define namespaces for storing module instance and binding events</p>
  72. </div>
  73. <div class="content"><div class='highlight'><pre> eventNamespace = <span class="string">'.'</span> + settings.namespace,
  74. moduleNamespace = <span class="string">'module-'</span> + settings.namespace,</pre></div></div>
  75. </li>
  76. <li id="section-6">
  77. <div class="annotation">
  78. <div class="pilwrap ">
  79. <a class="pilcrow" href="#section-6">&#182;</a>
  80. </div>
  81. <p>Preserve selector from outside each scope and mark current time for performance tracking</p>
  82. </div>
  83. <div class="content"><div class='highlight'><pre> selector = $allModules.selector || <span class="string">''</span>,
  84. time = <span class="keyword">new</span> Date().getTime(),
  85. performance = [],</pre></div></div>
  86. </li>
  87. <li id="section-7">
  88. <div class="annotation">
  89. <div class="pilwrap ">
  90. <a class="pilcrow" href="#section-7">&#182;</a>
  91. </div>
  92. <p>Preserve original arguments to determine if a method is being invoked</p>
  93. </div>
  94. <div class="content"><div class='highlight'><pre> query = arguments[<span class="number">0</span>],
  95. methodInvoked = (<span class="keyword">typeof</span> query == <span class="string">'string'</span>),
  96. queryArguments = [].slice.call(arguments, <span class="number">1</span>),
  97. invokedResponse
  98. ;</pre></div></div>
  99. </li>
  100. <li id="section-8">
  101. <div class="annotation">
  102. <div class="pilwrap for-h2">
  103. <a class="pilcrow" href="#section-8">&#182;</a>
  104. </div>
  105. <h2>Singular</h2>
  106. <p>Iterate over all elements to initialize module</p>
  107. </div>
  108. <div class="content"><div class='highlight'><pre> $allModules
  109. .each(<span class="keyword">function</span>() {
  110. <span class="keyword">var</span></pre></div></div>
  111. </li>
  112. <li id="section-9">
  113. <div class="annotation">
  114. <div class="pilwrap ">
  115. <a class="pilcrow" href="#section-9">&#182;</a>
  116. </div>
  117. <p>Cache selectors using selector definitions for access inside instance of module</p>
  118. </div>
  119. <div class="content"><div class='highlight'><pre> $module = $(<span class="keyword">this</span>),
  120. $text = $module.find(settings.selector.text),</pre></div></div>
  121. </li>
  122. <li id="section-10">
  123. <div class="annotation">
  124. <div class="pilwrap ">
  125. <a class="pilcrow" href="#section-10">&#182;</a>
  126. </div>
  127. <p>Define private variables which can be used to maintain internal state, these cannot be changed from outside the module closure so use conservatively</p>
  128. </div>
  129. <div class="content"><div class='highlight'><pre> foo = <span class="literal">false</span>,</pre></div></div>
  130. </li>
  131. <li id="section-11">
  132. <div class="annotation">
  133. <div class="pilwrap ">
  134. <a class="pilcrow" href="#section-11">&#182;</a>
  135. </div>
  136. <p>Define variables used to track module state. Default values are set using <code>a || b</code> syntax</p>
  137. </div>
  138. <div class="content"><div class='highlight'><pre> instance = $module.data(moduleNamespace),
  139. element = <span class="keyword">this</span>,</pre></div></div>
  140. </li>
  141. <li id="section-12">
  142. <div class="annotation">
  143. <div class="pilwrap ">
  144. <a class="pilcrow" href="#section-12">&#182;</a>
  145. </div>
  146. <p>Alias settings object for convenience and performance</p>
  147. </div>
  148. <div class="content"><div class='highlight'><pre> namespace = settings.namespace,
  149. error = settings.error,
  150. className = settings.className,</pre></div></div>
  151. </li>
  152. <li id="section-13">
  153. <div class="annotation">
  154. <div class="pilwrap ">
  155. <a class="pilcrow" href="#section-13">&#182;</a>
  156. </div>
  157. <p>You may also find it useful to alias your own settings</p>
  158. </div>
  159. <div class="content"><div class='highlight'><pre> text = settings.text,
  160. module
  161. ;</pre></div></div>
  162. </li>
  163. <li id="section-14">
  164. <div class="annotation">
  165. <div class="pilwrap for-h2">
  166. <a class="pilcrow" href="#section-14">&#182;</a>
  167. </div>
  168. <h2>Module Behavior</h2>
  169. </div>
  170. <div class="content"><div class='highlight'><pre> module = {</pre></div></div>
  171. </li>
  172. <li id="section-15">
  173. <div class="annotation">
  174. <div class="pilwrap for-h3">
  175. <a class="pilcrow" href="#section-15">&#182;</a>
  176. </div>
  177. <h3>Required</h3>
  178. <h4>Initialize</h4>
  179. <p>Initialize attaches events and preserves each instance in html metadata</p>
  180. </div>
  181. <div class="content"><div class='highlight'><pre> initialize: <span class="keyword">function</span>() {
  182. module.verbose(<span class="string">'Initializing module for'</span>, element);
  183. $module
  184. .on(<span class="string">'click'</span> + eventNamespace, module.exampleBehavior)
  185. ;</pre></div></div>
  186. </li>
  187. <li id="section-16">
  188. <div class="annotation">
  189. <div class="pilwrap ">
  190. <a class="pilcrow" href="#section-16">&#182;</a>
  191. </div>
  192. <p>The instance is just a copy of the module definition, we store it in metadata so we can use it outside of scope, but also define it for immediate use</p>
  193. </div>
  194. <div class="content"><div class='highlight'><pre> instance = module;
  195. $module
  196. .data(moduleNamespace, instance)
  197. ;
  198. },</pre></div></div>
  199. </li>
  200. <li id="section-17">
  201. <div class="annotation">
  202. <div class="pilwrap for-h4">
  203. <a class="pilcrow" href="#section-17">&#182;</a>
  204. </div>
  205. <h4>Destroy</h4>
  206. <p>Removes all events and the instance copy from metadata</p>
  207. </div>
  208. <div class="content"><div class='highlight'><pre> destroy: <span class="keyword">function</span>() {
  209. module.verbose(<span class="string">'Destroying previous module for'</span>, element);
  210. $module
  211. .removeData(moduleNamespace)
  212. .off(eventNamespace)
  213. ;
  214. },</pre></div></div>
  215. </li>
  216. <li id="section-18">
  217. <div class="annotation">
  218. <div class="pilwrap for-h4">
  219. <a class="pilcrow" href="#section-18">&#182;</a>
  220. </div>
  221. <h4>Refresh</h4>
  222. <p>Selectors are cached so we sometimes need to manually refresh the cache</p>
  223. </div>
  224. <div class="content"><div class='highlight'><pre> refresh: <span class="keyword">function</span>() {
  225. module.verbose(<span class="string">'Refreshing selector cache for'</span>, element);
  226. $module = $(element);
  227. $text = $(<span class="keyword">this</span>).find(settings.selector.text);
  228. },</pre></div></div>
  229. </li>
  230. <li id="section-19">
  231. <div class="annotation">
  232. <div class="pilwrap for-h3">
  233. <a class="pilcrow" href="#section-19">&#182;</a>
  234. </div>
  235. <h3>Custom</h3>
  236. <h4>By Event</h4>
  237. <p>Sometimes it makes sense to call an event handler by its type if it is dependent on the event to behave properly</p>
  238. </div>
  239. <div class="content"><div class='highlight'><pre> event: {
  240. click: <span class="keyword">function</span>(event) {
  241. module.verbose(<span class="string">'Preventing default action'</span>);
  242. <span class="keyword">if</span>( !$module.hasClass(className.disabled) ) {
  243. module.behavior();
  244. }
  245. event.preventDefault();
  246. }
  247. },</pre></div></div>
  248. </li>
  249. <li id="section-20">
  250. <div class="annotation">
  251. <div class="pilwrap for-h4">
  252. <a class="pilcrow" href="#section-20">&#182;</a>
  253. </div>
  254. <h4>By Function</h4>
  255. <p>Other times events make more sense for methods to be called by their function if it is ambivalent to how it is invoked</p>
  256. </div>
  257. <div class="content"><div class='highlight'><pre> behavior: <span class="keyword">function</span>() {
  258. module.debug(<span class="string">'Changing the text to a new value'</span>, text);
  259. <span class="keyword">if</span>( !module.has.text() ) {
  260. module.set.text( text);
  261. }
  262. },</pre></div></div>
  263. </li>
  264. <li id="section-21">
  265. <div class="annotation">
  266. <div class="pilwrap for-h4">
  267. <a class="pilcrow" href="#section-21">&#182;</a>
  268. </div>
  269. <h4>Vocabulary</h4>
  270. <p>Custom methods should be defined with consistent vocabulary some useful terms: &quot;has&quot;, &quot;set&quot;, &quot;get&quot;, &quot;change&quot;, &quot;add&quot;, &quot;remove&quot;</p>
  271. <p>This makes it easier for new developers to get to know your module without learning your schema</p>
  272. </div>
  273. <div class="content"><div class='highlight'><pre> has: {
  274. text: <span class="keyword">function</span>(state) {
  275. module.verbose(<span class="string">'Checking whether text state exists'</span>, state);
  276. <span class="keyword">if</span>( text[state] === <span class="literal">undefined</span> ) {
  277. module.error(error.noText);
  278. <span class="keyword">return</span> <span class="literal">false</span>;
  279. }
  280. <span class="keyword">return</span> <span class="literal">true</span>;
  281. }
  282. },
  283. set: {
  284. text: <span class="keyword">function</span>(state) {
  285. module.verbose(<span class="string">'Setting text to new state'</span>, state);
  286. <span class="keyword">if</span>( module.has.text(state) ) {
  287. $text
  288. .text( text[state] )
  289. ;
  290. settings.onChange();
  291. }
  292. }
  293. },</pre></div></div>
  294. </li>
  295. <li id="section-22">
  296. <div class="annotation">
  297. <div class="pilwrap for-h3">
  298. <a class="pilcrow" href="#section-22">&#182;</a>
  299. </div>
  300. <h3>Standard</h3>
  301. <h4>Setting</h4>
  302. <p>Module settings can be read or set using this method</p>
  303. <p>Settings can either be specified by modifying the module defaults, by initializing the module with a settings object, or by changing a setting by invoking this method
  304. <code>$(.foo&#39;).example(&#39;setting&#39;, &#39;moduleName&#39;);</code></p>
  305. </div>
  306. <div class="content"><div class='highlight'><pre> setting: <span class="keyword">function</span>(name, value) {
  307. <span class="keyword">if</span>(value !== <span class="literal">undefined</span>) {
  308. <span class="keyword">if</span>( $.isPlainObject(name) ) {
  309. $.extend(<span class="literal">true</span>, settings, name);
  310. }
  311. <span class="keyword">else</span> {
  312. settings[name] = value;
  313. }
  314. }
  315. <span class="keyword">else</span> {
  316. <span class="keyword">return</span> settings[name];
  317. }
  318. },</pre></div></div>
  319. </li>
  320. <li id="section-23">
  321. <div class="annotation">
  322. <div class="pilwrap for-h4">
  323. <a class="pilcrow" href="#section-23">&#182;</a>
  324. </div>
  325. <h4>Internal</h4>
  326. <p>Module internals can be set or retrieved as well
  327. <code>$(.foo&#39;).example(&#39;internal&#39;, &#39;behavior&#39;, function() { // do something });</code></p>
  328. </div>
  329. <div class="content"><div class='highlight'><pre> internal: <span class="keyword">function</span>(name, value) {
  330. <span class="keyword">if</span>(value !== <span class="literal">undefined</span>) {
  331. <span class="keyword">if</span>( $.isPlainObject(name) ) {
  332. $.extend(<span class="literal">true</span>, module, name);
  333. }
  334. <span class="keyword">else</span> {
  335. module[name] = value;
  336. }
  337. }
  338. <span class="keyword">else</span> {
  339. <span class="keyword">return</span> module[name];
  340. }
  341. },</pre></div></div>
  342. </li>
  343. <li id="section-24">
  344. <div class="annotation">
  345. <div class="pilwrap for-h4">
  346. <a class="pilcrow" href="#section-24">&#182;</a>
  347. </div>
  348. <h4>Debug</h4>
  349. <p>Debug pushes arguments to the console formatted as a debug statement</p>
  350. </div>
  351. <div class="content"><div class='highlight'><pre> debug: <span class="keyword">function</span>() {
  352. <span class="keyword">if</span>(settings.debug) {
  353. module.performance.log(arguments[<span class="number">0</span>]);
  354. module.verbose = Function.prototype.bind.call(console.info, console, settings.moduleName + <span class="string">':'</span>);
  355. }
  356. },</pre></div></div>
  357. </li>
  358. <li id="section-25">
  359. <div class="annotation">
  360. <div class="pilwrap for-h4">
  361. <a class="pilcrow" href="#section-25">&#182;</a>
  362. </div>
  363. <h4>Verbose</h4>
  364. <p>Calling verbose internally allows for additional data to be logged which can assist in debugging</p>
  365. </div>
  366. <div class="content"><div class='highlight'><pre> verbose: <span class="keyword">function</span>() {
  367. <span class="keyword">if</span>(settings.verbose &amp;&amp; settings.debug) {
  368. module.performance.log(arguments[<span class="number">0</span>]);
  369. module.verbose = Function.prototype.bind.call(console.info, console, settings.moduleName + <span class="string">':'</span>);
  370. }
  371. },</pre></div></div>
  372. </li>
  373. <li id="section-26">
  374. <div class="annotation">
  375. <div class="pilwrap for-h4">
  376. <a class="pilcrow" href="#section-26">&#182;</a>
  377. </div>
  378. <h4>Error</h4>
  379. <p>Error allows for the module to report named error messages, it may be useful to modify this to push error messages to the user. Error messages are defined in the modules settings object.</p>
  380. </div>
  381. <div class="content"><div class='highlight'><pre> error: <span class="keyword">function</span>() {
  382. <span class="keyword">if</span>(console.log !== <span class="literal">undefined</span>) {
  383. module.error = Function.prototype.bind.call(console.log, console, settings.moduleName + <span class="string">':'</span>);
  384. }
  385. },</pre></div></div>
  386. </li>
  387. <li id="section-27">
  388. <div class="annotation">
  389. <div class="pilwrap for-h4">
  390. <a class="pilcrow" href="#section-27">&#182;</a>
  391. </div>
  392. <h4>Performance</h4>
  393. <p>This is called on each debug statement and logs the time since the last debug statement.</p>
  394. </div>
  395. <div class="content"><div class='highlight'><pre> performance: {
  396. log: <span class="keyword">function</span>(message) {
  397. <span class="keyword">var</span>
  398. currentTime,
  399. executionTime
  400. ;
  401. <span class="keyword">if</span>(settings.performance) {
  402. currentTime = <span class="keyword">new</span> Date().getTime();
  403. executionTime = currentTime - time;
  404. time = currentTime;
  405. performance.push({
  406. <span class="string">'Name'</span> : message,
  407. <span class="string">'Execution Time'</span> : executionTime
  408. });
  409. clearTimeout(module.performance.timer);
  410. module.performance.timer = setTimeout(module.performance.display, <span class="number">500</span>);
  411. }
  412. },</pre></div></div>
  413. </li>
  414. <li id="section-28">
  415. <div class="annotation">
  416. <div class="pilwrap ">
  417. <a class="pilcrow" href="#section-28">&#182;</a>
  418. </div>
  419. <p>Performance data is assumed to be complete 500ms after the last log message receieved</p>
  420. </div>
  421. <div class="content"><div class='highlight'><pre> display: <span class="keyword">function</span>() {
  422. <span class="keyword">var</span>
  423. title = settings.moduleName + <span class="string">' Performance ('</span> + selector + <span class="string">')'</span>,
  424. caption = settings.moduleName + <span class="string">': '</span> + selector + <span class="string">'('</span> + $allModules.size() + <span class="string">' elements)'</span>
  425. ;
  426. <span class="keyword">if</span>(console.group !== <span class="literal">undefined</span> &amp;&amp; performance.length &gt; <span class="number">0</span>) {
  427. console.groupCollapsed(title);
  428. <span class="keyword">if</span>(console.table) {
  429. console.table(performance);
  430. }
  431. <span class="keyword">else</span> {
  432. $.each(performance, <span class="keyword">function</span>(index, data) {
  433. console.log(data[<span class="string">'Name'</span>] + <span class="string">':'</span> + data[<span class="string">'Execution Time'</span>]);
  434. });
  435. }
  436. console.groupEnd();
  437. performance = [];
  438. }
  439. }
  440. },</pre></div></div>
  441. </li>
  442. <li id="section-29">
  443. <div class="annotation">
  444. <div class="pilwrap for-h4">
  445. <a class="pilcrow" href="#section-29">&#182;</a>
  446. </div>
  447. <h4>Invoke</h4>
  448. <p>Invoke is used to lookup and invoke a method or property by a dot notation string definition, for example
  449. <code>$(&#39;.foo&#39;).example(&#39;invoke&#39;, &#39;set.text&#39;, &#39;Foo&#39;)</code></p>
  450. </div>
  451. <div class="content"><div class='highlight'><pre> invoke: <span class="keyword">function</span>(query, passedArguments, context) {
  452. <span class="keyword">var</span>
  453. maxDepth,
  454. found
  455. ;
  456. passedArguments = passedArguments || queryArguments;
  457. context = element || context;
  458. <span class="keyword">if</span>(<span class="keyword">typeof</span> query == <span class="string">'string'</span> &amp;&amp; instance !== <span class="literal">undefined</span>) {
  459. query = query.split(<span class="string">'.'</span>);
  460. maxDepth = query.length - <span class="number">1</span>;
  461. $.each(query, <span class="keyword">function</span>(depth, value) {
  462. <span class="keyword">if</span>( $.isPlainObject( instance[value] ) &amp;&amp; (depth != maxDepth) ) {
  463. instance = instance[value];
  464. <span class="keyword">return</span> <span class="literal">true</span>;
  465. }
  466. <span class="keyword">else</span> <span class="keyword">if</span>( instance[value] !== <span class="literal">undefined</span> ) {
  467. found = instance[value];
  468. <span class="keyword">return</span> <span class="literal">true</span>;
  469. }
  470. module.error(error.method);
  471. <span class="keyword">return</span> <span class="literal">false</span>;
  472. });
  473. }
  474. <span class="keyword">if</span> ( $.isFunction( found ) ) {
  475. module.verbose(<span class="string">'Executing invoked function'</span>, found);
  476. <span class="keyword">return</span> found.apply(context, passedArguments);
  477. }
  478. <span class="keyword">return</span> found || <span class="literal">false</span>;
  479. }
  480. };</pre></div></div>
  481. </li>
  482. <li id="section-30">
  483. <div class="annotation">
  484. <div class="pilwrap for-h3">
  485. <a class="pilcrow" href="#section-30">&#182;</a>
  486. </div>
  487. <h3>Determining Intent</h3>
  488. <p>Invoking a method directly
  489. $(&#39;.foo&#39;).module(&#39;set.text&#39;, &#39;Ho hum&#39;);
  490. The module checks to see if you passed in a method name to call</p>
  491. </div>
  492. <div class="content"><div class='highlight'><pre> <span class="keyword">if</span>(methodInvoked) {
  493. <span class="keyword">if</span>(instance === <span class="literal">undefined</span>) {
  494. module.initialize();
  495. }
  496. invokedResponse = module.invoke(query);
  497. }</pre></div></div>
  498. </li>
  499. <li id="section-31">
  500. <div class="annotation">
  501. <div class="pilwrap ">
  502. <a class="pilcrow" href="#section-31">&#182;</a>
  503. </div>
  504. <p>If you didn&#39;t pass in anything it can assume you are initializing the module</p>
  505. </div>
  506. <div class="content"><div class='highlight'><pre> <span class="keyword">else</span> {
  507. <span class="keyword">if</span>(instance !== <span class="literal">undefined</span>) {
  508. module.destroy();
  509. }
  510. module.initialize();
  511. }
  512. })
  513. ;</pre></div></div>
  514. </li>
  515. <li id="section-32">
  516. <div class="annotation">
  517. <div class="pilwrap ">
  518. <a class="pilcrow" href="#section-32">&#182;</a>
  519. </div>
  520. <p>If you called invoke, you may have a returned value which shoudl be returned, otherwise allow the call to chain</p>
  521. </div>
  522. <div class="content"><div class='highlight'><pre> <span class="keyword">return</span> (invokedResponse)
  523. ? invokedResponse
  524. : <span class="keyword">this</span>
  525. ;
  526. };</pre></div></div>
  527. </li>
  528. <li id="section-33">
  529. <div class="annotation">
  530. <div class="pilwrap for-h2">
  531. <a class="pilcrow" href="#section-33">&#182;</a>
  532. </div>
  533. <h2>Settings</h2>
  534. <p>It is necessary to include a settings object which specifies the defaults for your module</p>
  535. </div>
  536. <div class="content"><div class='highlight'><pre>$.fn.example.settings = {</pre></div></div>
  537. </li>
  538. <li id="section-34">
  539. <div class="annotation">
  540. <div class="pilwrap for-h3">
  541. <a class="pilcrow" href="#section-34">&#182;</a>
  542. </div>
  543. <h3>Required</h3>
  544. <p>Used in debug statements to refer to the module itself</p>
  545. </div>
  546. <div class="content"><div class='highlight'><pre> moduleName : <span class="string">'Todo Module'</span>,</pre></div></div>
  547. </li>
  548. <li id="section-35">
  549. <div class="annotation">
  550. <div class="pilwrap ">
  551. <a class="pilcrow" href="#section-35">&#182;</a>
  552. </div>
  553. <p>Whether debug content should be outputted to console</p>
  554. </div>
  555. <div class="content"><div class='highlight'><pre> debug : <span class="literal">true</span>,</pre></div></div>
  556. </li>
  557. <li id="section-36">
  558. <div class="annotation">
  559. <div class="pilwrap ">
  560. <a class="pilcrow" href="#section-36">&#182;</a>
  561. </div>
  562. <p>Whether extra debug content should be outputted</p>
  563. </div>
  564. <div class="content"><div class='highlight'><pre> verbose : <span class="literal">true</span>,</pre></div></div>
  565. </li>
  566. <li id="section-37">
  567. <div class="annotation">
  568. <div class="pilwrap ">
  569. <a class="pilcrow" href="#section-37">&#182;</a>
  570. </div>
  571. <p>Whether to track performance data</p>
  572. </div>
  573. <div class="content"><div class='highlight'><pre> performance : <span class="literal">true</span>,</pre></div></div>
  574. </li>
  575. <li id="section-38">
  576. <div class="annotation">
  577. <div class="pilwrap ">
  578. <a class="pilcrow" href="#section-38">&#182;</a>
  579. </div>
  580. <p>A unique identifier used to namespace events,and preserve the module instance</p>
  581. </div>
  582. <div class="content"><div class='highlight'><pre> namespace : <span class="string">'example'</span>,</pre></div></div>
  583. </li>
  584. <li id="section-39">
  585. <div class="annotation">
  586. <div class="pilwrap for-h3">
  587. <a class="pilcrow" href="#section-39">&#182;</a>
  588. </div>
  589. <h3>Optional</h3>
  590. <p>Selectors used by your module</p>
  591. </div>
  592. <div class="content"><div class='highlight'><pre> selector : {
  593. example : <span class="string">'.example'</span>
  594. },</pre></div></div>
  595. </li>
  596. <li id="section-40">
  597. <div class="annotation">
  598. <div class="pilwrap ">
  599. <a class="pilcrow" href="#section-40">&#182;</a>
  600. </div>
  601. <p>Error messages returned by the module</p>
  602. </div>
  603. <div class="content"><div class='highlight'><pre> error: {
  604. noText : <span class="string">'The text you tried to display has not been defined.'</span>, method : <span class="string">'The method you called is not defined.'</span>
  605. },</pre></div></div>
  606. </li>
  607. <li id="section-41">
  608. <div class="annotation">
  609. <div class="pilwrap ">
  610. <a class="pilcrow" href="#section-41">&#182;</a>
  611. </div>
  612. <p>Class names which your module refers to</p>
  613. </div>
  614. <div class="content"><div class='highlight'><pre> className : {
  615. disabled : <span class="string">'disabled'</span>
  616. },</pre></div></div>
  617. </li>
  618. <li id="section-42">
  619. <div class="annotation">
  620. <div class="pilwrap ">
  621. <a class="pilcrow" href="#section-42">&#182;</a>
  622. </div>
  623. <p>Metadata stored or retrieved by your module. <code>$(&#39;.foo&#39;).data(&#39;value&#39;);</code></p>
  624. </div>
  625. <div class="content"><div class='highlight'><pre> metadata: {
  626. notUsed: <span class="string">'notUsed'</span>
  627. },</pre></div></div>
  628. </li>
  629. <li id="section-43">
  630. <div class="annotation">
  631. <div class="pilwrap for-h3">
  632. <a class="pilcrow" href="#section-43">&#182;</a>
  633. </div>
  634. <h3>Callbacks</h3>
  635. <p>Callbacks are often useful to include in your settings object</p>
  636. </div>
  637. <div class="content"><div class='highlight'><pre> onChange : <span class="keyword">function</span>() {},</pre></div></div>
  638. </li>
  639. <li id="section-44">
  640. <div class="annotation">
  641. <div class="pilwrap for-h3">
  642. <a class="pilcrow" href="#section-44">&#182;</a>
  643. </div>
  644. <h3>Definition Specific</h3>
  645. <p>You may also want to include settings specific to your module&#39;s function</p>
  646. </div>
  647. <div class="content"><div class='highlight'><pre> text: {
  648. hover : <span class="string">'You are hovering me now'</span>,
  649. click : <span class="string">'You clicked on me'</span>
  650. }
  651. };
  652. })( jQuery, window , document );</pre></div></div>
  653. </li>
  654. </ul>
  655. </div>
  656. </body>
  657. </html>