-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript2bottom.js
More file actions
61 lines (54 loc) · 2.63 KB
/
script2bottom.js
File metadata and controls
61 lines (54 loc) · 2.63 KB
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
'use strict';
var STATIC_MODE = feather.config.get('staticMode');
var REG = /<script[\s\S]*?feather-script2bottom\b[\s\S]*?<\/script>/g;
module.exports = function(ret, conf, setting, opt){
var debug = opt.dest == 'preview', suffix = '.' + feather.config.get('template.suffix');
feather.util.map(ret.src, function(subpath, file){
if(file.isHtmlLike){
var content = file.getContent(), stack = [];
content = content.replace(REG, function(all){
if(STATIC_MODE){
stack.push(all);
return '';
}else{
return "<?php ob_start();?>"
+ all
+ "<?php "
+ "if(!$FEATHER_SCRIPT2BOTTOMS = $this->get('FEATHER_SCRIPT2BOTTOMS')){"
+ "$FEATHER_SCRIPT2BOTTOMS = array();"
+ "}"
+ "$FEATHER_SCRIPT2BOTTOMS[] = ob_get_contents();ob_end_clean();"
+ "$this->set('FEATHER_SCRIPT2BOTTOMS', $FEATHER_SCRIPT2BOTTOMS);"
+ "?>";
}
});
if(STATIC_MODE){
if(!file.isPageletLike){
if(/<\/body>/i.test(content)){
content = content.replace(/<\/body>/i, function(){
return stack.join('') + '</body>';
});
}else{
content += stack.join('');
}
}else{
content += stack.join('');
}
}else{
if(file.isPageletLike){
content += "<!--FEATHER STATIC2BOTTOM--><?php $this->load('/component/resource/usescript" + suffix + "', array('inline' => $this->get('FEATHER_SCRIPT2BOTTOMS')));?><!--FEATHER STATIC POSITION END-->";
}else{
content = content.replace(/<!--FEATHER STATIC POSITION:BOTTOM-->[\s\S]*?<!--FEATHER STATIC POSITION END-->/i, function(all){
return all + [
"<!--FEATHER STATIC2BOTTOM--><?php " + (debug ? " if(!$this->get('FEATHER_SCRIPT2BOTTOMS_LOADED')){" : ""),
"$this->load('/component/resource/usescript" + suffix + "', array('inline' => $this->get('FEATHER_SCRIPT2BOTTOMS')));",
(debug ? "$this->set('FEATHER_SCRIPT2BOTTOMS_LOADED', true);}" : "") + "?>",
"<!--FEATHER_SCRIPT2BOTTOMS END-->"
].join("");
});
}
}
file.setContent(content);
}
});
};