Skip to content

Commit b20ac8e

Browse files
committed
Changed the syntax to the new spec and the parser now recognises slot pseudo-elements.
1 parent f3f2bfc commit b20ac8e

18 files changed

Lines changed: 680 additions & 190 deletions

js/almcss3/almcss.js

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,20 @@ var ALMCSS = function() {
1111

1212
var SCRIPT_NAME = 'almcss.js';
1313

14+
if (!Object.create) {
15+
Object.create = function(o) {
16+
var F = function() {};
17+
F.prototype = o;
18+
return new F();
19+
}
20+
}
21+
22+
if (!String.prototype.trim) {
23+
String.prototype.trim = function() {
24+
return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
25+
};
26+
}
27+
1428
// AlmcssError
1529
// -----------
1630
//
@@ -68,7 +82,12 @@ var ALMCSS = function() {
6882
var loadedModules = [];
6983

7084
var isAlreadyLoaded = function(file) {
71-
return loadedModules.indexOf(file) !== -1;
85+
for (var i = 0; i < loadedModules.length; i++) {
86+
if (loadedModules[i] === file) {
87+
return true;
88+
}
89+
}
90+
return false;
7291
};
7392

7493
// This function is the responsible of dynamically loading all the specified
@@ -120,9 +139,6 @@ var ALMCSS = function() {
120139
var doLayout = function() {
121140

122141
var templates = ALMCSS.template.templates,
123-
computeWidths = ALMCSS.template.layout.computeTemplateWidths,
124-
computeHeights = ALMCSS.template.layout.computeTemplateHeights,
125-
paint = ALMCSS.template.dom.paint,
126142
LoggerLevel = ALMCSS.debug.LoggerLevel,
127143
logger = ALMCSS.debug.getLogger('Layout', LoggerLevel.all);
128144

@@ -131,14 +147,6 @@ var ALMCSS = function() {
131147
logger.group('Starting layout...');
132148
for (i = 0; i < templates.length; i++) {
133149
templates[i].doLayout();
134-
/*
135-
logger.group('Layout of template ' + templates[i].getId());
136-
computeWidths(templates[i]);
137-
computeHeights(templates[i]);
138-
paint(templates[i]);
139-
logger.info('Template %s finished', templates[i].getId());
140-
logger.groupEnd();
141-
*/
142150
}
143151
logger.info('All done!');
144152
logger.groupEnd();
@@ -208,7 +216,6 @@ var ALMCSS = function() {
208216
var include = module.include;
209217

210218
include([
211-
//'../../lib/firebug-lite/content/firebug-lite-dev.js',
212219
'config.js', // Global configuration parameters.
213220
'debug.js', // Assertions and logging.
214221

js/almcss3/config.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,24 @@ var ALMCSS = ALMCSS || {};
33
ALMCSS.Config = {
44

55
DEBUG : true,
6-
76
VISUAL_DEBUG : true,
87

8+
ASTERISK : '*',
9+
DEFAULT_SLOT : '*',
10+
FLOW : 'flow',
11+
GRID : 'grid',
12+
SLOT_PSEUDO : 'slot',
13+
914
TEMPLATE_ID : 'almcss_tpl',
1015
SLOT_ID : 'slot_',
1116
TEMPLATE_CLASS : 'almcss-template',
1217
SLOT_CLASS : 'almcss-slot',
18+
1319
TEMPLATE_LABEL_CLASS : 'almcss-template-label',
14-
SLOT_LABEL_CLASS : 'almcss-slot-label'
20+
SLOT_LABEL_CLASS : 'almcss-slot-label',
21+
TEMPLATE_COLOR : '#8A9B0F',
22+
SLOT_COLOR : '#F8CA00',
23+
TEMPLATE_BORDER_WIDTH : '8px',
24+
SLOT_BORDER_WIDTH : '4px'
1525

1626
};

js/almcss3/debug.js

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,42 +127,56 @@ ALMCSS.debug = function () {
127127

128128
return {
129129
log: function(object /* , object, object... */) {
130-
if (console && isVisible(LoggerLevel.log)) {
131-
console.log.apply(console, arguments);
130+
if (debug && console && console.log) {
131+
if (isVisible(LoggerLevel.log)) {
132+
console.log.apply(console, arguments);
133+
}
132134
}
133135
},
134136
info: function(object /* , object, object... */) {
135-
if (console && isVisible(LoggerLevel.info)) {
136-
console.info.apply(console, arguments);
137+
if (debug && console && console.info) {
138+
if (isVisible(LoggerLevel.info)) {
139+
console.info.apply(console, arguments);
140+
} else {
141+
this.log(arguments);
142+
}
137143
}
138144
},
139145
warn: function(object /* , object, object... */) {
140-
if (console && isVisible(LoggerLevel.warn)) {
141-
console.warn.apply(console, arguments);
146+
if (debug && console && console.warn) {
147+
if (isVisible(LoggerLevel.warn)) {
148+
console.warn.apply(console, arguments);
149+
} else {
150+
this.log(arguments);
151+
}
142152
}
143153
},
144154
error: function(object /* , object, object... */) {
145-
if (console && isVisible(LoggerLevel.error)) {
146-
console.error.apply(console, arguments);
155+
if (debug && console && console.error) {
156+
if (isVisible(LoggerLevel.error)) {
157+
console.error.apply(console, arguments);
158+
} else {
159+
this.log(arguments);
160+
}
147161
}
148162
},
149163
group: function(object /* , object, object... */) {
150-
if (console) {
164+
if (debug && console && console.group) {
151165
console.group.apply(console, arguments);
152166
}
153167
},
154168
groupCollapsed: function(object /* , object, object... */) {
155-
if (console) {
169+
if (debug && console && console.groupCollapsed) {
156170
console.groupCollapsed.apply(console, arguments);
157171
}
158172
},
159173
groupEnd: function(object /* , object, object... */) {
160-
if (console) {
174+
if (debug && console && console.groupEnd) {
161175
console.groupEnd.apply(console, arguments);
162176
}
163177
},
164178
trace: function(object /* , object, object... */) {
165-
if (console) {
179+
if (debug && console && console.trace) {
166180
console.trace.apply(console, arguments);
167181
}
168182
}

js/almcss3/domUtils.js

Lines changed: 71 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,78 @@ ALMCSS.domUtils = function() {
99

1010
var assert = ALMCSS.debug.assert;
1111

12-
13-
1412
// Computed Height and Widths
1513
// --------------------------
14+
//
15+
// The `getComputedWidth` and `getComputedHeight` functions of this module
16+
// return the computed value for the `width` and `height` respectively of
17+
// a given element. There are several reasons for using these functions
18+
// instead of simple calling directly to the `getComputedStyle` function
19+
// of the DOM from those places in the code where theses values are needed
20+
// (apart from brevity and legibility of the code):
21+
//
22+
// - First, `getComputedStyle` returns a string that contains both the
23+
// value and the unit. So this functions extract the part of the string
24+
// that is a number, which is what they return, ignoring the unit. Note
25+
// that __they are assuming that it is always pixels__. If it were not
26+
// so, there have been to call to do an extra step to convert it to the
27+
// correct numeric value in pixels for a given length (or percentage).
28+
// - More important, these functions take into consideration not only the
29+
// _width_ of the element, but also its related horizontal _margins,
30+
// paddings and borders_ (the specified element is supposed to be part
31+
// of the contents of a slot).
32+
33+
34+
var getComputedStyleOf = function(element, property) {
35+
var result, stringValue;
36+
stringValue = getComputedStyle(element, null).getPropertyValue(property);
37+
result = parseInt(stringValue.match(/\d+/), 10);
38+
assert(!isNaN(result), "The value of property '" + property + "' is not " +
39+
"something can be converted to a number (pixels was expected): " + stringValue);
40+
return result;
41+
};
1642

17-
// This function simply returns the computed value of the `width` property
18-
// of CSS for the specified HTML element. The reason for using a function
19-
// for that instead of simply calling directly to the `getComputedStyle`
20-
// function of the DOM from those places in the code where this value is
21-
// needed is not (only) for brevity, but because `getComputedStyle` returns
22-
// a string that contains both the value and the unit (we are assuming that
23-
// the unit is always pixels). So this function performs the additional
24-
// task of extracting the part of the string which is a number and converting
25-
// it to a numeric value, which is what it returns.
43+
// Returns the computed width of an element, using not only the value
44+
// of its _width_ property but also its margins, paddings and borders.
2645

2746
var getComputedWidth = function(element) {
28-
var result;
29-
result = getComputedStyle(element, null).getPropertyValue('width');
30-
result = parseInt(result.match(/\d+/), 10);
31-
assert(!isNaN(result));
32-
return result;
47+
var width, marginLeft, marginRight, paddingLeft, paddingRight,
48+
borderLeft, borderRight;
49+
50+
width = getComputedStyleOf(element, 'width');
51+
marginLeft = getComputedStyleOf(element, 'margin-left');
52+
marginRight = getComputedStyleOf(element, 'margin-right');
53+
paddingLeft = getComputedStyleOf(element, 'padding-left');
54+
paddingRight = getComputedStyleOf(element, 'padding-right');
55+
borderLeft = getComputedStyleOf(element, 'border-left-width');
56+
borderRight = getComputedStyleOf(element, 'border-right-width');
57+
return width + marginLeft + marginRight +
58+
paddingLeft + paddingRight + borderLeft + borderRight;
3359
};
3460

3561
// The same function than above, but for the computed height of a given
3662
// HTML element.
3763

3864
var getComputedHeight = function(element) {
39-
var result;
40-
result = getComputedStyle(element, null).getPropertyValue('height');
41-
result = parseInt(result.match(/\d+/), 10);
42-
assert(!isNaN(result));
43-
return result;
65+
var height, marginTop, marginBottom, paddingTop, paddingBottom,
66+
borderTop, borderBottom;
67+
68+
element.style.height = 'auto';
69+
70+
//element.style.borderTopWidth = '1px';
71+
//element.style.borderBottomWidth = '1px';
72+
height = getComputedStyleOf(element, 'height');
73+
return height;
74+
/*
75+
marginTop = getComputedStyleOf(element, 'margin-top');
76+
marginBottom = getComputedStyleOf(element, 'margin-bottom');
77+
paddingTop = getComputedStyleOf(element, 'padding-top');
78+
paddingBottom = getComputedStyleOf(element, 'padding-bottom');
79+
borderTop = getComputedStyleOf(element, 'border-top-width');
80+
borderBottom = getComputedStyleOf(element, 'border-bottom-width');
81+
return height + marginTop + marginBottom +
82+
paddingTop + paddingBottom + borderTop + borderBottom;
83+
*/
4484
};
4585

4686

@@ -70,6 +110,15 @@ ALMCSS.domUtils = function() {
70110
// ------------------------------------------------
71111

72112
var computeIntrinsicPreferredWidth = function(element) {
113+
var floatValue, intrinsicPreferredWidth;
114+
floatValue = getComputedStyle(element, null).getPropertyValue('float');
115+
element.style.cssFloat = 'left';
116+
intrinsicPreferredWidth = getComputedWidth(element);
117+
element.style.cssFloat = floatValue;
118+
return intrinsicPreferredWidth;
119+
};
120+
121+
var computeIntrinsicPreferredWidth2 = function(element) {
73122
var intrinsicPreferredWidth;
74123
element.style.cssFloat = 'left';
75124
intrinsicPreferredWidth = getComputedWidth(element);
@@ -152,6 +201,7 @@ ALMCSS.domUtils = function() {
152201
// ----------------------------------------
153202

154203
return {
204+
getComputedStyleOf: getComputedStyleOf,
155205
getComputedWidth: getComputedWidth,
156206
getComputedHeight: getComputedHeight,
157207
lengthToPixels: lengthToPixels,

0 commit comments

Comments
 (0)