-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreview.js
137 lines (101 loc) · 3.59 KB
/
preview.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
assetsURL = "http://www.whodesign.com/core_present/";
InflectionJS = {
id_suffix: new RegExp('(_ids|_id)$', 'g'),
underbar: new RegExp('_', 'g')
}
if (!String.prototype.humanize)
{
String.prototype.humanize = function(lowFirstLetter)
{
var str = this.toLowerCase();
str = str.replace(InflectionJS.id_suffix, '');
str = str.replace(InflectionJS.underbar, ' ');
if (!lowFirstLetter)
{
str = str.capitalize();
}
return str;
};
}
if (!String.prototype.capitalize)
{
String.prototype.capitalize = function()
{
var str = this.toLowerCase();
str = str.substring(0, 1).toUpperCase() + str.substring(1);
return str;
};
}
// function addScript(url){
// var s = document.createElement("script");
// s.type = "text/javascript";
// s.src = url;
// $("head").append(s);
// //document.getElementsByTagName("head")[0].appendChild(s);
// }
function addCss(url){
var s = document.createElement("link");
s.type = "text/css";
s.href = url;
s.rel = "stylesheet";
$("head").append(s);
//document.getElementsByTagName("head")[0].appendChild(s);
}
function addScript(sScriptSrc, oCallback) {
var oHead = document.getElementsByTagName('head')[0];
var oScript = document.createElement('script');
oScript.type = 'text/javascript';
oScript.src = sScriptSrc;
// most browsers
oScript.onload = oCallback;
// IE 6 & 7
oScript.onreadystatechange = function() {
if (this.readyState == 'complete') {
oCallback();
}
}
oHead.appendChild(oScript);
}
function loadComplete(){
countLoad--;
if(countLoad == 0){
start();
}
}
$(document).ajaxError(function(event, request, settings){
alert("falta os ficheiros");
});
$(document).ready(function() {
countLoad = 1;
addScript(assetsURL+"src/facebox.js",loadComplete);
addCss(assetsURL+"src/facebox.css");
addCss(assetsURL+"css/preview_style.css");
});
function start(){
var targetFolder = "./export/";
r = window.location.pathname.split("/index.html")
var jsonDir = targetFolder;//r[0]+"/export/";
$.getJSON('export/data.json', function(data,s,st) {
result = data;
if(result == null){
console.log(result);
}else{
$.each(data.pages, function(i,item){
var created = $("<div class='pages'>").appendTo('.result');
created.append('<h3>'+data.pages[i].name.humanize()+'</h3>');
$.each(data.pages[i].states, function(ix,itemx){
var created2 = $("<div class='states'>").appendTo(created);
//created2.append('<a href="'+targetFolder+data.pages[i].name+'/'+data.pages[i].states[ix].state+'" rel="facebox"><img src="'+targetFolder+data.pages[i].name+'/'+data.pages[i].states[ix].state+'"></a>');
created2.append('<a href="index.html#/'+data.pages[i].name+'/'+data.pages[i].states[ix].state.substring(0,data.pages[i].states[ix].state.length-4).replace("_"+"+")+'"><img src="'+targetFolder+data.pages[i].name+'/'+data.pages[i].states[ix].state+'"></a>');
//index.html#/New+arrivals/Watch
var nameFile = data.pages[i].states[ix].state;
var nf = nameFile.substring(0,nameFile.length-4);
created2.append('<p>'+nf.humanize()+'</p>');
});
if(i == data.pages.length-1){
$('a[rel*=facebox]').facebox();
}
});
}
});
};