markup.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. Trex.MarkupTemplate = {};
  2. (function() {
  3. var __TEMPLATES = {};
  4. Trex.define(Trex.MarkupTemplate, {
  5. add: function(name, template) {
  6. __TEMPLATES[name] = template;
  7. },
  8. get: function(name) {
  9. if(!__TEMPLATES[name]) {
  10. return {
  11. evaluate: function() { return ""; },
  12. evaluateToDom: function() { return ""; }
  13. };
  14. }
  15. if(typeof(__TEMPLATES[name]) == 'string') {
  16. var _template = __TEMPLATES[name].replace(/@[\w\.]+/g, function(full) {
  17. return TXMSG(full);
  18. });
  19. __TEMPLATES[name] = new Template(_template);
  20. }
  21. return __TEMPLATES[name];
  22. },
  23. splitList: function(rows, cols, items){
  24. var _matrix = { 'row': [] };
  25. var _total = items.length;
  26. var _matrix_row = _matrix.row;
  27. for(var row=0; row<rows; row++) {
  28. _matrix_row.push({ 'col': [] });
  29. var _matrix_col = _matrix_row.last().col;
  30. for(var col=0; col<cols; col++) {
  31. var _item = {
  32. 'image': '',
  33. 'data': '&nbsp;',
  34. 'klass': ''
  35. };
  36. if(row * cols + col < _total) {
  37. if(typeof(items[row * cols + col]) == 'string') {
  38. _item.data = items[row * cols + col];
  39. } else {
  40. _item = Object.extend(_item ,items[row * cols + col]);
  41. }
  42. }
  43. _matrix_col.push(_item);
  44. }
  45. }
  46. return _matrix;
  47. }
  48. });
  49. })();