Requires

Provides

Expression.js

Adds layout capabilities to widget (parse and render widget trees from objects)

License:
Public domain (http://unlicense.org).
Authors:
Yaroslaff Fedin
  1. 23
  2. 24
  3. 25
  4. 26
  5. 27
  6. 28
  7. 29
  8. 30
  9. 31
  10. 32
  11. 33
  12. 34
  13. 35
  14. 36
  15. 37
  16. 38
  17. 39
  18. 40
  19. 41
  20. 42
  21. 43
  22. 44
  23. 45
  24. 46
  25. 47
  26. 48
  27. 49
  28. 50
  29. 51
  30. 52
  31. 53
  32. 54
  33. 55
  34. 56
  35. 57
  36. 58
  37. 59
  38. 60
  39. 61
  40. 62
  41. 63
  42. 64
  43. 65
  44. 66
  45. 67
  46. 68
  47. 69
  48. 70
  49. 71
  50. 72
  51. 73
  52. 74
  53. 75
  54. 76
  55. 77
  56. 78
  57. 79
  58. 80
  59. 81
  60. 82
  61. 83
  62. 84
  63. 85
  64. 86
  65. 87
  66. 88
  67. 89
  68. 90
  69. 91
  70. 92
  71. 93
  72. 94
  73. 95
  74. 96
  75. 97
  76. 98
  77. 99
  78. 100
  79. 101
  80. 102
  81. 103
  82. 104
  83. 105
  84. 106
  85. 107
  86. 108
  87. 109
  88. 110
  89. 111
  90. 112
  91. 113
  92. 114
  93. 115
  94. 116
  95. 117
LSD.Module.Layout = new Class({ options: { layout: { instance: null, extract: false, options: {}, transform: {} } }, initialize: function(element, options) { if ((element && !element.tagName) || (options && options.tagName)) { var el = options; options = element; element = el; } var opts = options && options.layout && options.layout.options; var clone = ((opts && opts.method) || this.options.layout.method) == 'clone'; var extract = (opts && opts.extract) || this.options.layout.extract; if (clone || extract) options = Object.append(options || {}, LSD.Layout.extract(element)); if (clone) { var layout = element; element = null } if (!layout) layout = element; this.childNodes = []; if (layout) LSD.Layout.converted[$uid(layout)] = this; this.addEvent('build', function() { LSD.Layout.converted[$uid(this.element)] = this; if (this.options.layout.children) this.buildLayout(this.options.layout.children) }); this.parent(element, options); if (this.options.layout.instance !== false) { if (layout) this.layout = new LSD.Layout(this, Array.prototype.slice.call(layout.childNodes, 0), this.options.layout.options) } if (!this.layout) this.layout = LSD.Layout.get(this); if (this.options.layout.self) this.applySelector(this.options.layout.self); for (var i in this.options.layout.transform) { this.addLayoutTransformations(this.options.layout.transform); break; } this.addEvent('DOMNodeInserted', this.buildLayout.bind(this)) }, applySelector: function(selector) { var parsed = Slick.parse(selector).expressions[0][0]; if (parsed.classes) { var klasses = parsed.classes.map(function(klass) { return klass.value }) this.classes.push.apply(this.classes, klasses); klasses.each(this.addClass.bind(this)); } var options = {}; if (parsed.id) options.id = parsed.id; if (parsed.attributes) { if (parsed.attributes) parsed.attributes.each(function(attribute) { options[attribute.key] = attribute.value || true; }); } if (parsed.attributes || parsed.id) Object.append(this.options, options); this.fireEvent('selector', [parsed, selector]); }, transformLayout: function(element, layout) { var query = {element: element, layout: layout, parent: this}; this.dispatchEvent('layoutTransform', query); if (query.transformation) return query.transformation; }, onLayoutTransform: function(query) { var element = query.element; var transformations = (this.layoutTransformations[LSD.toLowerCase(element.tagName)] || []).concat(this.layoutTransformations['*'] || []); for (var i = 0, transformation; transformation = transformations[i++];) { if (Slick.matchR(element, transformation[0])) query.transformation = transformation[1]; } }, addLayoutTransformations: function(transformations, value) { if (!this.layoutTransformations) this.layoutTransformations = {}; if (!this.onLayoutTransformHandler) this.addEvent('layoutTransform', this.onLayoutTransformHandler = this.onLayoutTransform.bind(this)); for (var selector in transformations) { selector.split(/\s*,\s*/).each(function(bit) { var parsed = Slick.parse(bit); var expression = parsed.expressions[0]; var tag = expression[expression.length - 1].tag; var group = this.layoutTransformations[tag]; if (!group) group = this.layoutTransformations[tag] = []; group.push([parsed, transformations[selector]]); }, this) } }, buildLayout: function(layout, parent) { return this.layout.render(layout, parent || this); } });