-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
172 lines (139 loc) · 5.35 KB
/
index.html
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Query String Maker</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style media="screen">
.header {
color: #FFF;
padding: 20px 0px;
}
.navbar {
margin-bottom: 50px;
}
input {
width: 100%;
}
.row {
padding-bottom: 20px;
}
span {
color: black;
}
button {
margin-top: 10px;
}
.generatedCode {
display: none;
}
</style>
</head>
<body>
<nav class="navbar navbar-inverse">
<div class="container">
<div class="row header text-center">
<h1><i class="glyphicon glyphicon-eye-close"></i> Query String Code Generator</h1>
<p>Create a hidden div that only appears when the URL has a query string</p>
</div>
</div>
</nav>
<div class="container">
<div class="row">
<div class="col-md-3 col-md-offset-3">
<label for="identifier">Identifier Name: </label>
<input class="form-control" type="text" name="identifier" value="" placeholder="Identifier Name">
</div>
<div class="col-md-3">
<label for="identifier">Query Name: </label>
<input class="form-control" type="text" name="name" value="" placeholder="Query Name">
</div>
<div class="col-md-6 col-md-offset-3 ">
<button type="button" id="generate" name="button" class="btn btn-primary">Generate</button>
</div>
</div>
<div class="generatedCode">
<div class="row">
<hr>
<div class="col-md-6 col-md-offset-3">
<h4>Hidden div: Paste where you want the code to show</h4>
<div class="well">
<code>
<div id="<span class="outId" style="color: black"></span>" style="display: none"><br/>
<!-- Insert hidden HTML Here --><br/>
</div>
</code>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6 col-md-offset-3">
<h4>JS Logic: Paste after the hidden div</h4>
<div class="well">
<code>
<script><br/>
var final_id;
var url = document.URL;
var ID_CHECK = /[?&]<span class="outId"></span>=([^&]+)/i;
var match = ID_CHECK.exec(url);
if (match != null) {
final_id = match[1];
if (final_id == "<span class="outName"></span>"){
document.getElementById("<span class="outId" ></span>").style.display = "block";
};
};
<br/>
</script>
</code>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6 col-md-offset-3">
<h4>Query String</h4>
<div class="well">
<div class="input-group">
<div class="input-group-addon">http://www.url.com/</div>
<input type="text" class="form-control" id="outUrl" placeholder="QueryString">
</div>
</div>
</div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<script type="text/javascript">
// Execute if button is clicked
$('#generate').click(function() {
var $id = $('input');
var $outId = $(".outId");
var $outName = $(".outName");
// Check if inputs are not empty, else alert user
if ($id[0].value != '' && $id[1].value != '') {
// Check if values are valid, else alert user
if (isValid($id[0].value) && isValid($id[1].value)) {
//populate fields
for (var i = 0; i < $outId.length; i++) {
$outId[i].innerHTML = $id[0].value;
}
for (var i = 0; i < $outName.length; i++) {
$outName[i].innerHTML = $id[1].value;
}
$("#outUrl").val("?" + $id[0].value + "=" + $id[1].value);
// show code
$(".generatedCode").slideDown();
} else {
alert("Special characters can not be used");
}
} else {
alert("Cannot have an empty Identifier or Name");
}
});
// Check for special characters
function isValid(str) {
return !/[~`!#$%\^&*+=\-\[\]\\';,/{}|\\":<>\?]/g.test(str);
}
</script>
</body>
</html>