-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconfig.js
92 lines (79 loc) · 2.76 KB
/
config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
(function() {
var logger = Meeko.logger;
var _ = Meeko.stuff;
var DOM = Meeko.DOM, $id = DOM.$id, $$ = DOM.$$;
var URL = DOM.URL, baseURL = URL(document.URL);
function toArray(list) { var a = []; for (var n=list.length, i=0; i<n; i++) a[i] = list[i]; return a; }
Meeko.decor.config({
/*
You SHOULD REMOVE the `detect(doc)` option and
REPLACE IT WITH a `lookup(url)` option:
lookup: function(url) { return decorURL; }
The decorURL can be dependent on anything, for-instance
+ device / window dimensions
- to provide optimal layout
+ browser
- to give minimal support to old browsers
+ a theme setting from cookie or localStorage
- allows you to test a decor-document on the live site
*/
detect: function(doc) { return getDecorURL(doc); }
});
Meeko.panner.config({
normalize: function(doc, details) { // details contains the request `url` and `method`
// This removes fallback <style> and <link>, determined by their @title
var nodecorTitle = 'nodecor'; // This is the (case-insensitive) value for the fallback @title
var srcHead = doc.head;
_.forEach(toArray(srcHead.childNodes), function(node) { // remove nodes that match specified conditions
switch(DOM.tagName(node)) {
case "style": case "link":
var title = _.lc(_.trim(node.title));
if (title != nodecorTitle) return;
break;
default: return;
}
srcHead.removeChild(node);
});
// YOUR NORMALIZE CODE GOES HERE
},
// These SHOULD be set by your decor-document(s). This is just for backwards compat
duration: 0,
nodeRemoved: { before: hide, after: show },
nodeInserted: { before: hide, after: show },
pageOut: { before: noop, after: noop },
pageIn: { before: noop, after: noop }
});
function getDecorURL(doc) {
var link = getDecorLink(doc);
if (!link) return null; // FIXME warning message
var href = link.getAttribute("href");
return baseURL.resolve(href); // FIXME href should already be absolute
}
function getDecorLink(doc) {
var matchingLinks = [];
var link, specificity = 0;
_.forEach($$("link", doc.head), function(el) {
var tmp, sp = 0;
if (el.nodeType != 1) return;
var type = el.type.toLowerCase();
if (!/^\s*MEEKO-DECOR\s*$/i.test(el.rel)) return;
if (type == "text/html" || type == "") sp += 1;
else {
logger.warn("Invalid decor document type: " + type);
return;
}
if (tmp = el.getAttribute("media")) { // FIXME polyfill for matchMedia??
if (window.matchMedia && window.matchMedia(tmp).matches) sp += 2;
else return; // NOTE if the platform doesn't support media queries then this decor is rejected
}
if (sp > specificity) {
specificity = sp;
link = el;
}
});
return link;
}
function hide(msg) { msg.node.setAttribute("hidden", "hidden"); }
function show(msg) { msg.node.removeAttribute("hidden"); }
function noop(msg) { }
})();