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.

407 lines
16 KiB

10 years ago
10 years ago
  1. ---
  2. layout : 'default'
  3. css : ''
  4. element : 'tab'
  5. elementType : 'module'
  6. title : 'Tab'
  7. description : 'A tab is a section of content tied to a navigation menu'
  8. type : 'UI Module'
  9. themes : ['Default']
  10. ---
  11. <script src="/javascript/tab.js"></script>
  12. <%- @partial('header', { tabs: { usage: 'Usage', examples: 'Examples', settings: 'Settings' } }) %>
  13. <div class="main container">
  14. <!--
  15. <div class="ui tab" data-tab="definition">
  16. <div class="peek">
  17. <div class="ui vertical pointing secondary menu">
  18. <a class="active item">Types</a>
  19. </div>
  20. </div>
  21. </div>
  22. -->
  23. <div class="ui active tab" data-tab="usage">
  24. <h2 class="ui dividing header">Initializing Tabs</h2>
  25. <p>Tabs are usually used in concert with an element that activates the tab. Tabs are initialized on the activating item instead of the tab.</p>
  26. <p>If there are no menus that activate tab elements on the page, tabs can be initialized globally by using <code>$.tab()</code> and activated programmatically using <code>$.tab('change tab', path);</code></p>
  27. <p>Tabs are connected to their activators with a metadata attribute <code>data-tab</code>. This should be added to both the activating element and the tab itself.</p>
  28. <div class="ignored ui info message">
  29. <h4 class="ui header">Default tabs</h4>
  30. <p>After any tab is opened it will look for a default tab to open inside of the current tab. This is the first tab that begins with the same stem url as the parent tab. For example a tab with the path <code>data-tab="home"</code> might open a tab automatically <code>data-tab="/home/inbox"</code>.</p>
  31. <p>This will happen recursively for every tab open, allowing as many levels of tabs as you like.</p>
  32. </div>
  33. <h2 class="ui dividing header">Managing State</h2>
  34. <h4 class="ui header">...with Hash Tags</h4>
  35. <p>Hash tags use in page links and <code>onhashstatechange</code> to create history events for each tab. This is sometimes easier to use than the more advanced push state, because it does not require you to route those URLs on your server. All in page links will route to the same url.</p>
  36. <div class="code">
  37. $('.ui.menu .item')
  38. .tab({
  39. history: true,
  40. historyType: 'state'
  41. })
  42. ;
  43. </div>
  44. <h4 class="ui header">...with HTML5 State</h4>
  45. <p>Tabs can can use html5 push state to manage page state without using <code>#/foo</code> links. When a user refreshes a page using push state the server will be queried for the new url. This means you must set up appropriate routes in your backend to match each link.</p>
  46. <p>Tabs use Asual's <a href="https://github.com/asual/jquery-address">Address library</a> to provide cross-browser push state support. This makes sure in browser that don't support push state, <code>hashchange</code> is used with in page anchors to provide history functionality.</p>
  47. <div class="code">
  48. $('.ui.menu .item')
  49. .tab({
  50. history: true,
  51. historyType: 'state'
  52. path: '/modules/tab.html'
  53. })
  54. ;
  55. </div>
  56. <h4 class="ui header">Setting Paths</h4>
  57. <p>Make sure when you use history to specify the path. This is required for determining the stem url from the part of the url maintaining in page history. The path is the <b>base URL without any internal state</b>. This cannot be set automatically to <code>window.location</code> because refreshing the page will change future page refreshes the URL may include an internal link. </p>
  58. <div class="ui warning message">Using the incorrect path will cause the module to work incorrectly, producing unexpected results.</div>
  59. <h2 class="ui dividing header">AJAX Content</h2>
  60. <h3 class="ui header">...with automatic routing</h3>
  61. <p>Specifying the setting <code>auto: true</code>, will automatically retrieve content at a remote url matching the url set in the browser.</p>
  62. <p>So for example the tab <code>inbox</code> will retrieve content from the URL <code>base-url/inbox/</code></p>
  63. <p>The URL will receive an addition HTTP Header <code>'X-Remote': true</code>. You can use this on your server's back-end to determine whether a request is an AJAX request from a tab, or a full page request.</p>
  64. <p>Queries with <code>'X-Remote': true</code> should refresh only the tabbed content, while queries without are normal resources and should refresh <b>the entire page contents</b></p>
  65. <p>This uses a similar technique to <a href="https://github.com/defunkt/jquery-pjax">pJax</a> or Rail's <a href="https://github.com/rails/turbolinks/">turbolinks</a>.</p>
  66. <div class="ignored ui info message">There are a variety of settings for configuring dynamic content behavior. Visit the tab settings section for more information</div>
  67. <div class="code" data-type="javascript">
  68. $('.dynamic.example .menu .item')
  69. .tab({
  70. context : '.dynamic.example',
  71. auto : true,
  72. path : '/modules/tab.html'
  73. })
  74. ;
  75. </div>
  76. <h3 class="ui header">...with an API Behavior</h3>
  77. <p>Tabs provide an optional coupling with API which allow you to specify a templated API endpoint that a tab can query</p>
  78. <p>Tabs will automatically pass the url variable <code>{$tab}</code> which can be replaced for RESTful API links.</p>
  79. <h2 class="ui dividing header">Behavior</h2>
  80. All the following <a href="/module.html#/behavior">behaviors</a> can be called using the syntax <code>$('.foo').tab('behavior name', argumentOne, argumentTwo)</code>
  81. <table class="ui definition celled table segment">
  82. <tr>
  83. <td>attach events(selector, event)</td>
  84. <td>Attaches tab action to given selector. Default event if none specified is toggle</td>
  85. </tr>
  86. <tr>
  87. <td>show</td>
  88. <td>Shows tab</td>
  89. </tr>
  90. <tr>
  91. <td>hide</td>
  92. <td>Hides tab</td>
  93. </tr>
  94. <tr>
  95. <td>toggle</td>
  96. <td>Toggles visibility of tab</td>
  97. </tr>
  98. <tr>
  99. <td>is open</td>
  100. <td>Returns whether tab is open</td>
  101. </tr>
  102. <tr>
  103. <td>is closed</td>
  104. <td>Returns whether tab is closed</td>
  105. </tr>
  106. </table>
  107. </div>
  108. <div class="ui tab" data-tab="examples">
  109. <div class="first example">
  110. <h4 class="ui header">Multi-level Tabs with Defaults</h4>
  111. <p>This example shows how default tabs are opened recursively for multiple tiers of tabs</p>
  112. <div class="ui info message">Each of these examples is initialized with a context to prevent contamination with other tab examples on this page. This is not necessary unless using multiple tab systems on a single page.</div>
  113. <div class="ignored code" data-type="javascript">
  114. $('.first.example .menu .item')
  115. .tab({
  116. context: '.first.example'
  117. })
  118. ;
  119. </div>
  120. <div class="ui pointing secondary menu">
  121. <a class="active item" data-tab="first">First</a>
  122. <a class="item" data-tab="second">Second</a>
  123. <a class="item" data-tab="third">Third</a>
  124. </div>
  125. <div class="ui active tab segment" data-tab="first">
  126. <div class="ui top attached tabular menu">
  127. <a class="active item" data-tab="first/a">1A</a>
  128. <a class="item" data-tab="first/b">1B</a>
  129. <a class="item" data-tab="first/c">1C</a>
  130. </div>
  131. <div class="ui bottom attached active tab segment" data-tab="first/a">1A</div>
  132. <div class="ui bottom attached tab segment" data-tab="first/b">1B</div>
  133. <div class="ui bottom attached tab segment" data-tab="first/c">1C</div>
  134. </div>
  135. <div class="ui tab segment" data-tab="second">
  136. <div class="ui top attached tabular menu">
  137. <a class="item" data-tab="second/a">2A</a>
  138. <a class="item" data-tab="second/b">2B</a>
  139. <a class="item" data-tab="second/c">2C</a>
  140. </div>
  141. <div class="ui bottom attached tab segment" data-tab="second/a">2A</div>
  142. <div class="ui bottom attached tab segment" data-tab="second/b">2B</div>
  143. <div class="ui bottom attached tab segment" data-tab="second/c">2C</div>
  144. </div>
  145. <div class="ui tab segment" data-tab="third">
  146. <div class="ui top attached tabular menu">
  147. <a class="item" data-tab="third/a">3A</a>
  148. <a class="item" data-tab="third/b">3B</a>
  149. <a class="item" data-tab="third/c">3C</a>
  150. </div>
  151. <div class="ui bottom attached tab segment" data-tab="third/a">3A</div>
  152. <div class="ui bottom attached tab segment" data-tab="third/b">3B</div>
  153. <div class="ui bottom attached tab segment" data-tab="third/c">3C</div>
  154. </div>
  155. </div>
  156. <div class="history example">
  157. <h4>Example with hash page history</h4>
  158. <div class="code" data-type="javascript">
  159. $('.history.example .menu .item')
  160. .tab({
  161. context : '.history.example',
  162. history : true
  163. })
  164. ;
  165. </div>
  166. <div class="ui pointing secondary menu">
  167. <a class="active item" data-tab="first">First</a>
  168. <a class="item" data-tab="second">Second</a>
  169. <a class="item" data-tab="third">Third</a>
  170. </div>
  171. <div class="ui active tab segment" data-tab="first">
  172. <div class="ui top attached tabular menu">
  173. <a class="active item" data-tab="first/a">1A</a>
  174. <a class="item" data-tab="first/b">1B</a>
  175. <a class="item" data-tab="first/c">1C</a>
  176. </div>
  177. <div class="ui bottom attached active tab segment" data-tab="first/a">1A</div>
  178. <div class="ui bottom attached tab segment" data-tab="first/b">1B</div>
  179. <div class="ui bottom attached tab segment" data-tab="first/c">1C</div>
  180. </div>
  181. <div class="ui tab segment" data-tab="second">
  182. <div class="ui top attached tabular menu">
  183. <a class="item" data-tab="second/a">2A</a>
  184. <a class="item" data-tab="second/b">2B</a>
  185. <a class="item" data-tab="second/c">2C</a>
  186. </div>
  187. <div class="ui bottom attached tab segment" data-tab="second/a">2A</div>
  188. <div class="ui bottom attached tab segment" data-tab="second/b">2B</div>
  189. <div class="ui bottom attached tab segment" data-tab="second/c">2C</div>
  190. </div>
  191. <div class="ui tab segment" data-tab="third">
  192. <div class="ui top attached tabular menu">
  193. <a class="item" data-tab="third/a">3A</a>
  194. <a class="item" data-tab="third/b">3B</a>
  195. <a class="item" data-tab="third/c">3C</a>
  196. </div>
  197. <div class="ui bottom attached tab segment" data-tab="third/a">3A</div>
  198. <div class="ui bottom attached tab segment" data-tab="third/b">3B</div>
  199. <div class="ui bottom attached tab segment" data-tab="third/c">3C</div>
  200. </div>
  201. </div>
  202. <div class="dynamic no example">
  203. <h4 class="header">Retreiving Dynamic Tab Content</h4>
  204. <div class="code">
  205. $('.dynamic.example .menu .item')
  206. .tab({
  207. context : '.dynamic.example',
  208. auto : true,
  209. path : '/modules/tab.html'
  210. })
  211. ;
  212. </div>
  213. <div class="ui pointing secondary menu">
  214. <a class="active item" data-tab="first">First</a>
  215. <a class="item" data-tab="second">Second</a>
  216. <a class="item" data-tab="third">Third</a>
  217. </div>
  218. <div class="ui active tab segment" data-tab="first">
  219. <div class="ui top attached tabular menu">
  220. <a class="active item" data-tab="first/a">1A</a>
  221. <a class="item" data-tab="first/b">1B</a>
  222. <a class="item" data-tab="first/c">1C</a>
  223. </div>
  224. <div class="ui bottom attached active tab segment" data-tab="first/a"></div>
  225. <div class="ui bottom attached tab segment" data-tab="first/b"></div>
  226. <div class="ui bottom attached tab segment" data-tab="first/c"></div>
  227. </div>
  228. <div class="ui tab segment" data-tab="second">
  229. <div class="ui top attached tabular menu">
  230. <a class="item" data-tab="second/a">2A</a>
  231. <a class="item" data-tab="second/b">2B</a>
  232. <a class="item" data-tab="second/c">2C</a>
  233. </div>
  234. <div class="ui bottom attached tab segment" data-tab="second/a"></div>
  235. <div class="ui bottom attached tab segment" data-tab="second/b"></div>
  236. <div class="ui bottom attached tab segment" data-tab="second/c"></div>
  237. </div>
  238. <div class="ui tab segment" data-tab="third">
  239. <div class="ui top attached tabular menu">
  240. <a class="item" data-tab="third/a">3A</a>
  241. <a class="item" data-tab="third/b">3B</a>
  242. <a class="item" data-tab="third/c">3C</a>
  243. </div>
  244. <div class="ui bottom attached tab segment" data-tab="third/a"></div>
  245. <div class="ui bottom attached tab segment" data-tab="third/b"></div>
  246. <div class="ui bottom attached tab segment" data-tab="third/c"></div>
  247. </div>
  248. </div>
  249. </div>
  250. <div class="ui tab" data-tab="settings">
  251. <h3 class="ui header">
  252. Transition Settings
  253. <div class="sub header">Form settings modify the transition behavior</div>
  254. </h3>
  255. <table class="ui red celled sortable definition table segment">
  256. <thead>
  257. <th>Setting</th>
  258. <th class="four wide">Default</th>
  259. <th>Description</th>
  260. </thead>
  261. <tbody>
  262. <tr>
  263. <td>overlay</td>
  264. <td>false</td>
  265. <td>Whether tab should overlay page instead of pushing page to the side</td>
  266. </tr>
  267. <tr>
  268. <td>useCSS</td>
  269. <td>true</td>
  270. <td>Whether to use css animations or fallback javascript animations</td>
  271. </tr>
  272. <tr>
  273. <td>duration</td>
  274. <td>300</td>
  275. <td>Duration of side bar animation</td>
  276. </tr>
  277. </tbody>
  278. </table>
  279. <h3 class="ui header">
  280. DOM Settings
  281. <div class="sub header">DOM settings specify how this module should interface with the DOM</div>
  282. </h3>
  283. <table class="ui celled purple definition table segment">
  284. <thead>
  285. <th>Setting</th>
  286. <th class="six wide">Default</th>
  287. <th>Description</th>
  288. </thead>
  289. <tbody>
  290. <tr>
  291. <td>namespace</td>
  292. <td>tab</td>
  293. <td>Event namespace. Makes sure module teardown does not effect other events attached to an element.</td>
  294. </tr>
  295. <tr>
  296. <td>className</td>
  297. <td>
  298. <div class="code">
  299. className: {
  300. active : 'active',
  301. pushed : 'pushed',
  302. top : 'top',
  303. left : 'left',
  304. right : 'right',
  305. bottom : 'bottom'
  306. }
  307. </div>
  308. </td>
  309. <td>Class names used to attach style to state</td>
  310. </tr>
  311. </tbody>
  312. </table>
  313. <div class="ui horizontal divider"><i class="icon setting"></i></div>
  314. <h3 class="ui header">
  315. Debug Settings
  316. <div class="sub header">Debug settings controls debug output to the console</div>
  317. </h3>
  318. <table class="ui blue celled sortable definition table segment">
  319. <thead>
  320. <th>Setting</th>
  321. <th class="four wide">Default</th>
  322. <th>Description</th>
  323. </thead>
  324. <tbody>
  325. <tr>
  326. <td>name</td>
  327. <td>Tab</td>
  328. <td>Name used in debug logs</td>
  329. </tr>
  330. <tr>
  331. <td>debug</td>
  332. <td>True</td>
  333. <td>Provides standard debug output to console</td>
  334. </tr>
  335. <tr>
  336. <td>performance</td>
  337. <td>True</td>
  338. <td>Provides standard debug output to console</td>
  339. </tr>
  340. <tr>
  341. <td>verbose</td>
  342. <td>True</td>
  343. <td>Provides ancillary debug output to console</td>
  344. </tr>
  345. <tr>
  346. <td>errors</td>
  347. <td colspan="2">
  348. <div class="code">
  349. error : {
  350. method : 'The method you called is not defined.',
  351. notFound : 'There were no elements that matched the specified selector'
  352. }
  353. </div>
  354. </td>
  355. </tr>
  356. </tbody>
  357. </table>
  358. </div>
  359. </div>
  360. </body>
  361. </html>