forked from bschug/poedit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathurlArgs.js
65 lines (57 loc) · 1.95 KB
/
urlArgs.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
function UrlArgs() {
this.codePastebin = new Pastebin();
this.itemsPastebin = new Pastebin();
this.hasCodePastebin = function() {
// If we already know that the code pastebin id is invalid, we treat it as not having one.
if (this.codePastebin.status === 'Error') {
return false;
}
return getCodePastebinId() !== null;
}
this.hasItemsPastebin = function() {
// If we already know that the items pastebin id is invalid, we treat it as not having one.
if (this.itemsPastebin.status === 'Error') {
return false;
}
return getItemsPastebinId() !== null;
}
function getCodePastebinId () {
var args = getHashArgs();
if (args === null || args.length === 0) {
return null;
}
// Code pastebin must always come first, so if first argument is items pastebin,
// we know that there is no code pastebin.
if (StrUtils.startsWith( args[0], 'items=' )) {
return null;
}
return args[0];
}
function getItemsPastebinId () {
var args = getHashArgs();
if (args === null) {
return null;
}
// Find the first arg with items= prefix
for (var i=0; i < args.length; i++) {
if (StrUtils.startsWith( args[i], 'items=' )) {
return args[i].substring( 'items='.length );
}
}
return null;
}
this.loadCodePastebin = function (successCb, errorCb) {
var self = this;
self.codePastebin.load( getCodePastebinId(), successCb, errorCb );
}
this.loadItemsPastebin = function (successCb, errorCb) {
var self = this;
self.itemsPastebin.load( getItemsPastebinId(), successCb, errorCb );
}
function getHashArgs() {
if (!window.location.hash) {
return null;
}
return window.location.hash.substring(1).split( ',' );
}
}