PageRenderTime 58ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/stylematters/app/assistants/list-assistant.js

https://github.com/danboy/palm
JavaScript | 547 lines | 511 code | 12 blank | 24 comment | 21 complexity | a1fd7287f9b63762ca44ec87929c1fab MD5 | raw file
Possible License(s): LGPL-2.1
  1. function exampleCategory (modelItem) {
  2. return $L(modelItem.category);
  3. }
  4. ListAssistant = Class.create( OrientationHandlerAssistant, {
  5. setup: function() {
  6. if (PalmSystem.setWindowOrientation) {
  7. PalmSystem.setWindowOrientation("free");
  8. }
  9. var sceneName;
  10. this.examplesModel = {listTitle: $L('Examples'), items:this.kExamples};
  11. this.controller.setupWidget('examples',
  12. {
  13. itemTemplate: 'example',
  14. dividerTemplate: 'divider',
  15. dividerFunction: exampleCategory,
  16. filterFunction: this.filterExamples.bind(this),
  17. renderLimit: 80
  18. },
  19. this.examplesModel);
  20. this.controller.listen('examples', Mojo.Event.listTap, this.handleListTap.bindAsEventListener(this));
  21. this.controller.get('mojo-info').innerHTML = Mojo.Version.use+" / "+Mojo.Versions["1"];
  22. },
  23. convertSceneName: function(sceneId) {
  24. return sceneId.gsub("_", "-");
  25. },
  26. activate: function() {
  27. ListAssistant.setSavedSceneName("");
  28. },
  29. filterExamples: function(filterString, listWidget, offset, count) {
  30. var matching, lowerFilter;
  31. if (filterString) {
  32. lowerFilter = filterString.toLocaleLowerCase();
  33. function matches (example) {
  34. if(example.title && example.title.toLocaleLowerCase().startsWith(lowerFilter)){
  35. return example.title.toLocaleLowerCase().startsWith(lowerFilter);
  36. }else if(example.keywords && example.keywords .toLocaleLowerCase().match(lowerFilter)){
  37. return example.keywords.toLocaleLowerCase().match(lowerFilter);
  38. }else{
  39. return false;
  40. }
  41. }
  42. matching = this.kExamples.findAll(matches);
  43. } else {
  44. matching = this.kExamples;
  45. }
  46. this.examplesModel.items = matching;
  47. listWidget.mojo.setLength(matching.length);
  48. listWidget.mojo.setCount(matching.length);
  49. listWidget.mojo.noticeUpdatedItems(0, matching);
  50. },
  51. listElementSelector: 'div[id^="line_"]',
  52. handleListTap: function(listTapEvent) {
  53. var example = listTapEvent.item;
  54. var sceneName = this.convertSceneName(example.name);
  55. var title = example.title;
  56. var description = example.description;
  57. var sceneTemplate = example.sceneTemplate;
  58. console.log(title + " " + description + " " + example.disabled);
  59. if (sceneName === 'test') {
  60. Mojo.Test.pushTestScene(this.controller.stageController);
  61. } else {
  62. if(listTapEvent.originalEvent.down.shiftKey) {
  63. this.showSceneHandler = this.showScene.bind(this, sceneName);
  64. Mojo.Controller.getAppController().createStageWithCallback({name: sceneName, lightweight: true}, this.showSceneHandler);
  65. } else if(!example.disabled){
  66. ListAssistant.showScene(sceneName, this.controller.stageController, title, description, sceneTemplate);
  67. }
  68. }
  69. listTapEvent.stop();
  70. }
  71. });
  72. ListAssistant.kSceneCookieName = "sceneCookie";
  73. ListAssistant.getSavedSceneName = function() {
  74. var sceneCookie = new Mojo.Model.Cookie(ListAssistant.kSceneCookieName);
  75. return sceneCookie.get();
  76. };
  77. ListAssistant.setSavedSceneName = function(sceneName) {
  78. var sceneCookie = new Mojo.Model.Cookie(ListAssistant.kSceneCookieName);
  79. sceneCookie.put(sceneName);
  80. };
  81. ListAssistant.showScene = function(sceneName, stageController, title, description, sceneTemplate) {
  82. if (sceneName === 'test') {
  83. Mojo.Test.pushTestScene(stageController);
  84. } else {
  85. if(title == null && description == null){
  86. for(var i=0;i<ListAssistant.prototype.kExamples.length;i++){
  87. if(ListAssistant.prototype.kExamples[i].name == sceneName){
  88. var title = ListAssistant.prototype.kExamples[i].title;
  89. var description = ListAssistant.prototype.kExamples[i].description;
  90. var sceneTemplate = ListAssistant.prototype.kExamples[i].sceneTemplate;
  91. break;
  92. }
  93. }
  94. }
  95. stageController.pushScene({'name': sceneName, 'sceneTemplate': sceneTemplate }, $L(title), $L(description));
  96. }
  97. ListAssistant.setSavedSceneName(sceneName);
  98. }
  99. ListAssistant.prototype.kExamples =
  100. [
  101. //scene basics
  102. {
  103. "name": "palmbackdrop",
  104. "category": "Scene Basics",
  105. "title": "Backdrop",
  106. "description": "the background of your scene",
  107. "sceneTemplate":"sublist",
  108. "keywords":"body background"
  109. },
  110. {
  111. "name": "palmmenudemo",
  112. "category": "Scene Basics",
  113. "title": "View &amp; Command menus",
  114. "description": "floating menu system at the top and bottom of your scene, and the gradient fades behind them",
  115. "sceneTemplate":"sublist",
  116. "keywords":"command menu button"
  117. },
  118. {
  119. "name": "fixed-header-example",
  120. "category": "Scene Basics",
  121. "title": "Fixed Header",
  122. "description": "floating header atop your scene; visually identical to the View Menu",
  123. "keywords":"header view menu"
  124. },
  125. {
  126. "name": "scrollfades-example",
  127. "category": "Scene Basics",
  128. "title": "Scroll Fades",
  129. "description": "in the absence of view or command menus, these fades at the edge of your scene indicate more content",
  130. "keywords":"fades gradient"
  131. },
  132. {
  133. "name": "palmpageheader-example",
  134. "category": "Scene Basics",
  135. "title": "Page Header",
  136. "description": "the topmost element of the scrollable content; commonly used atop preference scenes",
  137. "keywords":"header scrolling"
  138. },
  139. {
  140. "name": "scrims-example",
  141. "category": "Scene Basics",
  142. "title": "Scrims",
  143. "description": "a translucent layer used to obscure background UI, when modal foreground UI is layered on top of the current scene",
  144. "keywords":"transparent clear alpha"
  145. },
  146. //list basics
  147. {
  148. "name": "palmlist",
  149. "category": "List Basics",
  150. "title": "Lists &amp; Rows",
  151. "description": "rows stacked vertically within lists, designed for legibility and touch interaction",
  152. "sceneTemplate":"sublist",
  153. "keywords":"rows palm-row"
  154. },
  155. {
  156. "name": "separators-example",
  157. "category": "List Basics",
  158. "title": "Separators",
  159. "description": "thin lines which visually separate rows",
  160. "keywords":"lines dividers"
  161. },
  162. {
  163. "name": "touchfeedback-example",
  164. "category": "List Basics",
  165. "title": "Touch Feedback",
  166. "description": "displaying alternate background images and styling in response to user interaction",
  167. "keywords":"feedback tf"
  168. },
  169. {
  170. "name": "reorder-example",
  171. "category": "List Basics",
  172. "title": "Reordering List Items",
  173. "description": "the space in between reordered rows, and row you're moving",
  174. "keywords":""
  175. },
  176. {
  177. "name": "swipedelete-example",
  178. "category": "List Basics",
  179. "title": "Swipe to Delete Items",
  180. "description": "the row being deleted and confirmation buttons",
  181. "keywords":""
  182. },
  183. {
  184. "name": "add-remove-rows-example",
  185. "category": "List Basics",
  186. "title": "Add/Remove Rows",
  187. "description": "the 'add item' row appended to a list and 'remove item' button for removable rows",
  188. "keywords":""
  189. },
  190. //dividers
  191. {
  192. "name": "solid-dividers-example",
  193. "category": "Dividers",
  194. "title": "Solid Dividers",
  195. "description": "bold lines which divide a scene or list of rows",
  196. "keywords":"divider"
  197. },
  198. {
  199. "name": "labeleddividers-example",
  200. "category": "Dividers",
  201. "title": "Labeled Dividers",
  202. "description": "bold lines with labels which divide a scene or list of rows",
  203. "keywords":"divider"
  204. },
  205. {
  206. "name": "alphabetical-dividers-example",
  207. "category": "Dividers",
  208. "title": "Alphabetical Dividers",
  209. "description": "bold lines containing a single character which divide a scene or list of rows",
  210. "keywords":"divider"
  211. },
  212. {
  213. "name": "collapsibledividers",
  214. "category": "Dividers",
  215. "title": "Collapsible Dividers",
  216. "description": "dividers which control corresponding drawers of content",
  217. "sceneTemplate":"sublist",
  218. "keywords":"divider"
  219. },
  220. //Text
  221. {
  222. "name": "typography-font-families",
  223. "category": "Text",
  224. "title": "Fonts",
  225. "description": "Mojo uses the Prelude font family",
  226. "keywords":"text typeface prelude"
  227. },
  228. {
  229. "name": "typography-basic-styles",
  230. "category": "Text",
  231. "title": "Basic Text Styles",
  232. "description": "body copy and informational text styles",
  233. "keywords":"text body style copy"
  234. },
  235. {
  236. "name": "text-capitalization",
  237. "category": "Text",
  238. "title": "Capitalization",
  239. "description": "some Mojo widgets and styles shift strings to uppercase or apply capitalization",
  240. "keywords":"text uppercase title"
  241. },
  242. {
  243. "name": "text-truncation",
  244. "category": "Text",
  245. "title": "Truncation",
  246. "description": "force text to fit within the available space, with an ellipsis added as needed",
  247. "keywords":"text"
  248. },
  249. //page containers
  250. {
  251. "name": "labeledgroup",
  252. "category": "Page Containers",
  253. "title": "Labeled Group",
  254. "description": "visually group a list with a label",
  255. "keywords":"group container"
  256. },
  257. {
  258. "name": "unlabeledgroup-example",
  259. "category": "Page Containers",
  260. "title": "Unlabeled Group",
  261. "description": "visually group a list without a label",
  262. "keywords":"group container"
  263. },
  264. {
  265. "name": "drawers",
  266. "category": "Page Containers",
  267. "title": "Drawers",
  268. "description": "hide UI or lists with an area which animates open and closed",
  269. "sceneTemplate":"sublist",
  270. "keywords":"container hide"
  271. },
  272. //panels
  273. {
  274. "name": "dialog-example",
  275. "category": "Panels",
  276. "title": "Dialogs",
  277. "description": "a modal panel pinned to the bottom of the scene",
  278. "keywords":"panel"
  279. },
  280. {
  281. "name": "submenu-example",
  282. "category": "Panels",
  283. "title": "Submenus",
  284. "description": "a popup panel containing UI or lists, floating above all other scene UI",
  285. "keywords":"panel"
  286. },
  287. {
  288. "name": "menupanel-example",
  289. "category": "Panels",
  290. "title": "Menu Panels",
  291. "description": "a popup panel containing UI or lists, floating underneath the view or command menu",
  292. "keywords":""
  293. },
  294. {
  295. "name": "dashboard-panels-example",
  296. "category": "Panels",
  297. "title": "Dashboard Panels",
  298. "description": "",
  299. "keywords":"panel"
  300. },
  301. //ui widgets
  302. {
  303. "name": "checkboxes-example",
  304. "category": "UI Widgets",
  305. "title": "Checkboxes",
  306. "description": "",
  307. "keywords":"widgets"
  308. },
  309. {
  310. "name": "toggle-buttons-example",
  311. "category": "UI Widgets",
  312. "title": "Toggle Buttons",
  313. "description": "",
  314. "keywords":"widgets"
  315. },
  316. {
  317. "name": "buttons-example",
  318. "category": "UI Widgets",
  319. "title": "Buttons",
  320. "description": "",
  321. "keywords":"widgets"
  322. },
  323. {
  324. "name": "radio-buttons-example",
  325. "category": "UI Widgets",
  326. "title": "Radio Buttons",
  327. "description": "",
  328. "keywords":"widgets"
  329. },
  330. {
  331. "name": "widgetlistselectors-example",
  332. "category": "UI Widgets",
  333. "title": "List Selectors",
  334. "description": "",
  335. "keywords":"widgets"
  336. },
  337. {
  338. "name": "sliders",
  339. "category": "UI Widgets",
  340. "title": "Sliders",
  341. "description": "",
  342. "sceneTemplate":"sublist",
  343. "keywords":"widgets"
  344. },
  345. {
  346. "name": "activity-indicators",
  347. "category": "UI Widgets",
  348. "title": "Activity Indicators",
  349. "description": "",
  350. "sceneTemplate":"sublist",
  351. "keywords":"widgets"
  352. },
  353. {
  354. "name": "inline-progress-audio",
  355. "category": "UI Widgets",
  356. "title": "Inline Progress (Audio)",
  357. "description": "",
  358. "keywords":"widgets",
  359. "disabled":"disabled"
  360. },
  361. {
  362. "name": "multi-value-picker-single-picker",
  363. "category": "UI Widgets",
  364. "title": "Integer Picker",
  365. "description": ""
  366. },
  367. {
  368. "name": "multi-value-picker-date-picker",
  369. "category": "UI Widgets",
  370. "title": "Date Picker",
  371. "description": ""
  372. },
  373. {
  374. "name": "multi-value-picker-time-picker",
  375. "category": "UI Widgets",
  376. "title": "Time Picker",
  377. "description": ""
  378. },
  379. {
  380. "name": "filter-field-example",
  381. "category": "UI Widgets",
  382. "title": "Filter Field",
  383. "description": "",
  384. "keywords":"widgets"
  385. },
  386. // {
  387. // "name": "addressing-widget-example",
  388. // "category": "UI Widgets",
  389. // "title": "Addressing Widget",
  390. // "description": "",
  391. // "keywords":"widgets"
  392. // },
  393. // {
  394. // "name": "combobox-example",
  395. // "category": "UI Widgets",
  396. // "title": "Combobox",
  397. // "description": "",
  398. // "keywords":"widgets"
  399. // },
  400. {
  401. "name": "textfields",
  402. "category": "UI Widgets",
  403. "title": "Textfields",
  404. "description": "",
  405. "sceneTemplate":"sublist",
  406. "keywords":"widgets"
  407. },
  408. {
  409. "name": "file-download-progress-example",
  410. "category": "UI Widgets",
  411. "title": "Progress Pill",
  412. "description": "",
  413. "keywords":"widgets"
  414. },
  415. //iconography
  416. {
  417. "name": "checkmark-example",
  418. "category": "iconography",
  419. "title": "Checkmark",
  420. "description": "",
  421. "keywords":"icons"
  422. },
  423. {
  424. "name": "status-indicators-example",
  425. "category": "iconography",
  426. "title": "Status Indicators",
  427. "description": "",
  428. "keywords":"icons indicators availability online"
  429. },
  430. {
  431. "name": "account-icons-example",
  432. "category": "iconography",
  433. "title": "Account Icons",
  434. "description": "",
  435. "keywords":"icons"
  436. },
  437. {
  438. "name": "error-iconography",
  439. "category": "iconography",
  440. "title": "Error Iconography",
  441. "description": "",
  442. "keywords":"icons",
  443. "disabled":"disabled"
  444. },
  445. //HANDLING ERRORS
  446. {
  447. "name": "form-errors",
  448. "category": "HANDLING ERRORS",
  449. "title": "Form Errors",
  450. "description": "",
  451. "keywords":"errors",
  452. "disabled":"disabled"
  453. },
  454. {
  455. "name": "scene-errors",
  456. "category": "HANDLING ERRORS",
  457. "title": "Scene Errors",
  458. "description": "",
  459. "keywords":"errors",
  460. "disabled":"disabled"
  461. },
  462. {
  463. "name": "app-errors",
  464. "category": "HANDLING ERRORS",
  465. "title": "App Errors",
  466. "description": "",
  467. "keywords":"errors",
  468. "disabled":"disabled"
  469. },
  470. {
  471. "name": "error-iconography",
  472. "category": "HANDLING ERRORS",
  473. "title": "Error Iconography",
  474. "description": "",
  475. "keywords":"icons",
  476. "disabled":"disabled"
  477. },
  478. //tips & tricks
  479. {
  480. "name": "tips",
  481. "category": "tips &amp tricks",
  482. "title": "Touchability",
  483. "description": "",
  484. "keywords":"",
  485. "disabled":"disabled"
  486. },
  487. {
  488. "name": "tips",
  489. "category": "tips &amp tricks",
  490. "title": "Optimizing Images",
  491. "description": "",
  492. "keywords":"",
  493. "disabled":"disabled"
  494. },
  495. {
  496. "name": "tips",
  497. "category": "tips &amp tricks",
  498. "title": "9-tile Images",
  499. "description": "",
  500. "keywords":"",
  501. "disabled":"disabled"
  502. },
  503. {
  504. "name": "tips",
  505. "category": "tips &amp tricks",
  506. "title": "HTML Tables",
  507. "description": "",
  508. "keywords":"",
  509. "disabled":"disabled"
  510. },
  511. {
  512. "name": "tips",
  513. "category": "tips &amp tricks",
  514. "title": "Negative Property Values",
  515. "description": "",
  516. "keywords":"",
  517. "disabled":"disabled"
  518. },
  519. {
  520. "name": "tips",
  521. "category": "tips &amp tricks",
  522. "title": "Vertical Alignment",
  523. "description": "",
  524. "keywords":"",
  525. "disabled":"disabled"
  526. },
  527. {
  528. "name": "tips",
  529. "category": "tips &amp tricks",
  530. "title": "Unsupported CSS Properties",
  531. "description": "",
  532. "keywords":"not supported webkit-border-radius CSS opacity alpha",
  533. "disabled":"disabled"
  534. }
  535. ];