-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
117 lines (93 loc) · 2.56 KB
/
main.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
function GET(url, callback) {
var peticion = new XMLHttpRequest();
peticion.open("GET", url , true);
peticion.send();
peticion.onreadystatechange = function() {
if (peticion.readyState == 4) {
if (peticion.status == 0 || peticion.status == 200) {
callback(peticion.responseText);
}
}
}
}
/* Url of the json stringified function returning the ff object. */
GET("https://raw.githubusercontent.com/StringManolo/ff/master/json/ff.json", function(resp, ff, ff2, fBody) {
/* resp is the json response. ff & ff2 & fBody are just void variables. */
/* Parse the downloaded json */
ff2 = JSON.parse(resp);
/* Find the function body from the parsed function as string. */
fBody = ff2.match(/function[^{]+\{([\s\S]*)\}$/)[1];
/* Create a new function */
ff = new Function([], fBody);
/* Call the function & asign the returned object to the ff variable */
ff = ff();
/* From here you can use the framework freely. */
ff.activateShortcuts();
ff.customTags = {
myMenu:`<section><article id="mainMenu"><a href="#home">HOME</a>
<a href="#overview">OVERVIEW</a>
<a href="#updates">UPDATES</a>
<a href="#about">ABOUT</a></article></section>`
};
var home = `<h1>Welcome!</h1>
Welcome to my page`;
var overview = `<h1>Overview!</h1>
This page is an example of fast framework usage.`;
var updates = `<h1>Updates!</h1>
The last change is this page.`;
var about = `<h1>About!</h1>
This work is made by <a href="#stringmanolo">String Manolo</a>.`;
ff.routes = {
route1: {
name: "home",
action: function() {
$("myViews").innerHTML = ff.customTags.myMenu + home;
}
},
route2: {
name: "overview",
action: function() {
$("myViews").innerHTML = ff.customTags.myMenu + overview;
}
},
route3: {
name: "updates",
action: function() {
$("myViews").innerHTML = ff.customTags.myMenu + updates;
}
},
route4: {
name: "about",
action: function() {
$("myViews").innerHTML = ff.customTags.myMenu + about;
}
},
route5: {
name: "stringmanolo",
action: function() {
alert("Github: https://github.com/stringmanolo");
}
},
amount: 5,
routeDefault: {
name: "default",
action: function() {
$("myViews").innerHTML = ff.customTags.myMenu;
}
}
};
ff.router.start();
ff.mustache.copyright = `<div class="copyright">© ${new Date().getFullYear()}</div>
<style>
.copyright {
bottom: 10px;
right: 10px;
position: fixed;
}
</style>
`;
ff.mustache.date = ""+new Date();
ff.getUnknownTags();
ff.getCustomTags();
ff.getMustacheSintax();
});