File tree 4 files changed +70
-10
lines changed
4 files changed +70
-10
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * api.js
3
+ *
4
+ * API For encoding and decoding URL hash objects
5
+ *
6
+ * Created by Jacob Strieb
7
+ * July 2020
8
+ */
9
+
10
+
11
+ /*******************************************************************************
12
+ * Global Variables
13
+ ******************************************************************************/
14
+
15
+ const LATEST_API_VERSION = "0.0.1" ;
16
+ // const LATEST_API_VERSION = "0.2.0";
17
+
18
+ var apiVersions = { } ;
19
+
20
+
21
+
22
+ /*******************************************************************************
23
+ * API Version 0.2.0 (Latest)
24
+ ******************************************************************************/
25
+
26
+ apiVersions [ "0.2.0" ] = {
27
+
28
+ VERSION : "0.2.0" ,
29
+
30
+ /* Return a link to view the page */
31
+ getViewLink : function ( pageData ) {
32
+ var urlData = {
33
+ version : this . VERSION ,
34
+ } ;
35
+
36
+ const hashObject = b64 . encode ( JSON . stringify ( urlData ) ) ;
37
+ return `http://jstrieb.github.io/urlpages/#${ hashObject } ` ;
38
+ } ,
39
+
40
+ }
41
+
42
+
43
+
44
+ /*******************************************************************************
45
+ * API Version 0.0.1 (Original)
46
+ ******************************************************************************/
47
+
48
+ apiVersions [ "0.0.1" ] = {
49
+
50
+ VERSION : "0.0.1" ,
51
+
52
+ /* Return a link to view the page */
53
+ getViewLink : function ( pageData ) {
54
+ return `http://jstrieb.github.io/urlpages/#${ b64 . encode ( pageData ) } ` ;
55
+ } ,
56
+
57
+ }
Original file line number Diff line number Diff line change 3
3
* in the documentation
4
4
*/
5
5
6
+ api = apiVersions [ LATEST_API_VERSION ]
7
+
6
8
7
9
8
10
/***
@@ -35,13 +37,6 @@ ${data["html"]}
35
37
}
36
38
37
39
38
- /* Return a link to view the page */
39
- function getViewLink ( pageData ) {
40
- return `http://jstrieb.github.io/urlpages/#${ b64 . encode ( pageData ) } ` ;
41
- }
42
-
43
-
44
-
45
40
/***
46
41
* Button press functions
47
42
***/
@@ -58,7 +53,7 @@ function setViewUrl() {
58
53
var html = encodeURIComponent ( getHTML ( data ) ) ;
59
54
60
55
// Update the URL for the "Short Link" button
61
- document . getElementById ( "url" ) . value = getViewLink ( html ) ;
56
+ document . getElementById ( "url" ) . value = api . getViewLink ( html ) ;
62
57
}
63
58
64
59
@@ -129,7 +124,7 @@ function update() {
129
124
window . location . hash = "#" + b64 . encode ( JSON . stringify ( data ) ) ;
130
125
131
126
// Update the URL for the "Get Link" button
132
- document . getElementById ( "getLinkLink" ) . href = getViewLink ( html ) ;
127
+ document . getElementById ( "getLinkLink" ) . href = api . getViewLink ( html ) ;
133
128
134
129
// Update the download link
135
130
document . getElementById ( "downloadLink" ) . href = `data:text/html,${ html } `
Original file line number Diff line number Diff line change 11
11
12
12
<!-- Scripts -->
13
13
< script src ="../b64.js " type ="text/javascript "> </ script >
14
+ < script src ="../api.js " type ="text/javascript "> </ script >
14
15
< script src ="editor.js " type ="text/javascript "> </ script >
15
16
</ head >
16
17
Original file line number Diff line number Diff line change 11
11
// Try to get page data from the URL if possible
12
12
var hash = window . location . hash . slice ( 1 ) ;
13
13
var data = b64 . decode ( hash ) ;
14
- document . write ( decodeURIComponent ( data ) ) ;
14
+
15
+ try {
16
+ var urlDataObject = JSON . parse ( data ) ;
17
+ var api = apiVersions [ urlDataObject . version ] ;
18
+ document . write ( api . decode ( urlDataObject ) ) ;
19
+ } catch ( err ) {
20
+ document . write ( decodeURIComponent ( data ) ) ;
21
+ }
15
22
} else {
16
23
// Otherwise redirect to the editor
17
24
window . location . replace ( "./editor" ) ;
You can’t perform that action at this time.
0 commit comments