-
Notifications
You must be signed in to change notification settings - Fork 26
/
index.html
349 lines (316 loc) · 16.2 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
<!DOCTYPE html>
<html xmlns:ng="http://angularjs.org" id="ng-app" ng-app="testApp">
<head>
<meta charset="UTF-8">
<title>angular-shims-placeholder</title>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/normalize/3.0.1/normalize.min.css">
<style type="text/css">
/* Demo page styles */
body { margin: 4em 2em; }
a,a:visited { color: black; }
h5 { margin: 1px 0; font-weight: normal; color: #333; }
input, textarea { width: 140px; vertical-align: middle; margin: 2px 0px; }
button { width: 70px; margin-right: 1px; vertical-align: middle; }
.container { max-width: 600px; margin: auto; }
.group + .group { margin-top: 4px; }
.column { display: inline-block; min-width: 146px; min-height: 45px; vertical-align: top; }
.example { display: inline-block; padding: 1px; border: solid 1px transparent; }
.ng-dirty { background-color: lightcyan; }
.ng-invalid { border-color: red; }
input:invalid { box-shadow: none; } /* suppress Firefox default style */
/* Recommended placeholder styles */
.empty { color: #a9a9a9; }
[readonly].empty { cursor: default; }
/* Emulate IE `onselectstart=return false` for demo */
[disabled].empty {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
/* Hide browser placeholders for demo */
::-webkit-input-placeholder { color: transparent; }
:-moz-placeholder { /* Firefox 18- */ color: transparent; }
::-moz-placeholder { /* Firefox 19+ */ color: transparent; }
:-ms-input-placeholder { color: transparent; }
</style>
</head>
<body>
<div class="container">
<h1>angular-shims-placeholder</h1>
<div>Placeholder polyfill for IE9, IE8, IE7, and others. Written in AngularJS.</div>
<p>For this demo, browser placeholders are hidden, and the polyfill is force enabled. Usually, it would only be active in browsers that don't support the placeholder attribute. Visit the <a href="https://github.com/cvn/angular-shims-placeholder">repo</a> for more information.</p>
<a href="https://github.com/cvn/angular-shims-placeholder"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"></a>
<div id="group-separate" class="group has-placeholder has-model separate-models">
<h5>Separate models</h5>
<input type="text" placeholder="text" ng-model="test.empty1">
<input type="password" placeholder="password" ng-model="test.empty2">
<input type="email" placeholder="email" ng-model="test.empty3">
<textarea rows="1" placeholder="textarea" ng-model="test.empty4"></textarea>
</div>
<div id="group-shared" class="group has-placeholder has-model shared-model">
<h5>Shared model</h5>
<input type="text" placeholder="text" ng-model="test.linked" ng-trim="false">
<input type="password" placeholder="password" ng-model="test.linked" ng-trim="false">
<input type="email" placeholder="email" ng-model="test.linked" ng-trim="false">
<textarea rows="1" placeholder="textarea" ng-model="test.linked" ng-trim="false"></textarea>
</div>
<div id="group-nomodel" class="group has-placeholder no-model">
<h5>No model</h5>
<input type="text" placeholder="text">
<input type="password" placeholder="password">
<input type="email" placeholder="email">
<textarea rows="1" placeholder="textarea"></textarea>
</div>
<div id="group-separate-prefilled" class="group has-placeholder has-model separate-models pre-filled">
<h5>Pre-filled by model</h5>
<input type="text" placeholder="text" ng-model="test.text">
<input type="password" placeholder="password" ng-model="test.password">
<button ng-click="test.text = (test.password = 'filler')">fill</button>
<button ng-click="test.text = (test.password = '')">clear</button>
</div>
<div id="group-nomodel-prefilled" class="group has-placeholder no-model pre-filled">
<h5>No model, pre-filled by value</h5>
<input type="text" placeholder="text" id="np1" value="Hello, Betty">
<input type="password" placeholder="password" id="np2" value="secret2">
<button onclick="fillElements('#np1,#np2', 'filler')">fill</button>
<button onclick="fillElements('#np1,#np2', '')">clear</button>
</div>
<p><h5>
Key:
<span class="example empty">empty</span>
<span class="example ng-dirty">ng-dirty</span>
<span class="example ng-invalid">ng-invalid</span>
</h5></p>
<br>
<div id="group-separate-ref" class="group no-placeholder has-model separate-models">
<h5>Separate models, no placeholder (for reference)</h5>
<input type="text" ng-model="test.empty11">
<input type="password" ng-model="test.empty12">
<input type="email" ng-model="test.empty13">
<textarea rows="1" ng-model="test.empty14"></textarea>
</div>
<div id="group-shared-ref" class="group no-placeholder has-model shared-model">
<h5>Shared model, no placeholder (for reference)</h5>
<input type="text" ng-model="test.linked2" ng-trim="false">
<input type="password" ng-model="test.linked2" ng-trim="false">
<input type="email" ng-model="test.linked2" ng-trim="false">
<textarea rows="1" ng-model="test.linked2" ng-trim="false"></textarea>
</div>
<br>
<div id="group-ngdisabled" class="group has-placeholder has-model separate-models has-ngdisabled">
<h5>ngDisabled</h5>
<input type="text" placeholder="text" ng-model="test.disabled_empty1" ng-disabled="test.disabled_emptys">
<input type="password" placeholder="password" ng-model="test.disabled_empty2" ng-disabled="test.disabled_emptys">
<input type="email" placeholder="email" ng-model="test.disabled_empty3" ng-disabled="test.disabled_emptys">
<textarea rows="1" placeholder="textarea" ng-model="test.disabled_empty4" ng-disabled="test.disabled_emptys"></textarea>
</div>
<div id="group-disabled-attribute" class="group has-placeholder no-model has-disabled">
<h5>Disabled attribute</h5>
<input type="text" placeholder="text" disabled="disabled">
<input type="password" placeholder="password" disabled="disabled">
<input type="email" placeholder="email" disabled="disabled">
<textarea rows="1" placeholder="textarea" disabled="disabled"></textarea>
</div>
<div id="group-ngdisabled-prefilled" class="group has-placeholder pre-filled has-model separate-models has-ngdisabled">
<h5>Pre-filled by model with ngDisabled </h5>
<input type="text" placeholder="text" ng-model="test.disabled_text" ng-disabled="test.disabled_prefilleds">
<input type="password" placeholder="password" ng-model="test.disabled_password" ng-disabled="test.disabled_prefilleds">
<button ng-click="test.disabled_text = (test.disabled_password = 'filler')">fill</button>
<button ng-click="test.disabled_text = (test.disabled_password = '')">clear</button>
<button ng-click="test.disabled_prefilleds = false">enable</button>
<button ng-click="test.disabled_prefilleds = true">disable</button>
</div>
<div id="group-disabled-attribute-prefilled" class="group has-placeholder pre-filled no-model has-disabled">
<h5>No model, pre-filled by value with disabled attribute</h5>
<input type="text" placeholder="text" disabled="disabled" id="dp1" value="Hello, Des'ree">
<input type="password" placeholder="password" disabled="disabled" id="dp2" value="secret4">
<button onclick="fillElements('#dp1,#dp2', 'filler')">fill</button>
<button onclick="fillElements('#dp1,#dp2', '')">clear</button>
<button onclick="disableElements('#dp1,#dp2', false)">enable</button>
<button onclick="disableElements('#dp1,#dp2', true)">disable</button>
</div>
<br>
<div id="group-ngreadonly" class="group has-placeholder has-model separate-models has-ngreadonly">
<h5>ngReadonly</h5>
<input type="text" placeholder="text" ng-model="test.readonly_empty1" ng-readonly="test.readonly_emptys">
<input type="password" placeholder="password" ng-model="test.readonly_empty2" ng-readonly="test.readonly_emptys">
<input type="email" placeholder="email" ng-model="test.readonly_empty3" ng-readonly="test.readonly_emptys">
<textarea rows="1" placeholder="textarea" ng-model="test.readonly_empty4" ng-readonly="test.readonly_emptys"></textarea>
</div>
<div id="group-ngreadonly-prefilled" class="group has-placeholder pre-filled has-model separate-models has-ngreadonly">
<h5>Pre-filled by model with ngReadonly</h5>
<input type="text" placeholder="text" ng-model="test.readonly_text" ng-readonly="test.readonly_prefilleds">
<input type="password" placeholder="password" ng-model="test.readonly_password" ng-readonly="test.readonly_prefilleds">
<button ng-click="test.readonly_text = (test.readonly_password = 'filler')">fill</button>
<button ng-click="test.readonly_text = (test.readonly_password = '')">clear</button>
<button ng-click="test.readonly_prefilleds = false">r/w</button>
<button ng-click="test.readonly_prefilleds = true">r/o</button>
</div>
<br>
<div id="group-ngrequired" class="group has-placeholder has-model separate-models has-ngrequired">
<h5>ngRequired</h5>
<input type="text" placeholder="text" ng-model="test.required_empty1" ng-required="test.required_emptys">
<input type="password" placeholder="password" ng-model="test.required_empty2" ng-required="test.required_emptys">
<input type="email" placeholder="email" ng-model="test.required_empty3" ng-required="test.required_emptys">
<textarea rows="1" placeholder="textarea" ng-model="test.required_empty4" ng-required="test.required_emptys"></textarea>
</div>
<div id="group-ngrequired-prefilled" class="group has-placeholder pre-filled has-model separate-models has-ngrequired">
<h5>Pre-filled by model with ngRequired</h5>
<input type="text" placeholder="text" ng-model="test.required_text" ng-required="test.required_prefilleds">
<input type="password" placeholder="password" ng-model="test.required_password" ng-required="test.required_prefilleds">
<button ng-click="test.required_text = (test.required_password = 'filler')">fill</button>
<button ng-click="test.required_text = (test.required_password = '')">clear</button>
<button ng-click="test.required_prefilleds = false">optional</button>
<button ng-click="test.required_prefilleds = true">required</button>
</div>
<br>
<div id="group-ngshowhide" class="group has-placeholder has-model separate-models has-ngshowhide">
<h5>ngShow/ngHide password stress test</h5>
<div class="column">
<h5>ngShow</h5>
<input type="password" placeholder="password" ng-model="test.show_empty" ng-show="test.show_inputs">
</div>
<div class="column">
<h5>ngHide</h5>
<input type="password" placeholder="password" ng-model="test.hide_empty" ng-hide="test.show_inputs">
</div>
<div class="column pre-filled ">
<h5>ngShow prefilled</h5>
<input type="password" placeholder="password" ng-model="test.show_password" ng-show="test.show_inputs">
</div>
<div class="column pre-filled ">
<h5>ngHide prefilled</h5>
<input type="password" placeholder="password" ng-model="test.hide_password" ng-hide="test.show_inputs">
</div>
<div>
<button ng-click="test.show_inputs = !test.show_inputs">toggle</button>
<button ng-click="test.show_empty = (test.hide_empty = (test.show_password = (test.hide_password = 'filler')))">fill</button>
<button ng-click="test.show_empty = (test.hide_empty = (test.show_password = (test.hide_password = '')))">clear</button>
</div>
</div>
<br>
<div id="group-dynamic" class="group has-placeholder has-dynamic">
<h5>Dynamic placeholder</h5>
<input type="text" placeholder="{{test.dynamic_text}}">
<input type="text" ng-model="test.dynamic_text">
<input type="password" placeholder="{{test.dynamic_password}}">
<input type="text" ng-model="test.dynamic_password">
</div>
<div id="group-dynamic-nomodel" class="group has-placeholder no-model">
<h5>No model, change placeholder manually</h5>
<input type="text" placeholder="text" id="nd1">
<input type="password" placeholder="password" id="nd2">
<button onclick="fillElements('#nd1,#nd2', 'filler')">fill</button>
<button onclick="fillElements('#nd1,#nd2', '')">clear</button>
<button onclick="updatePlaceholders('#nd1,#nd2', +new Date())">change</button>
</div>
<br>
<div id="group-ngattr" class="group has-placeholder has-dynamic has-ngattr">
<h5>ngAttrPlaceholder</h5>
<input type="text" ng-attr-placeholder="{{test.dynamic_text}}">
<input type="password" ng-attr-placeholder="{{test.dynamic_password}}">
</div>
<br>
<div id="group-template" class="group has-placeholder has-model shared-model has-template">
<h5>As template, pre-filled by model</h5>
<span test-template="text"></span>
<span test-template="password"></span>
</div>
</div><!-- /.container -->
<!-- Load angular.js from CDN if local copy is missing. http://stackoverflow.com/a/5531821/490592 -->
<script src="bower_components/angular/angular.js"></script>
<!--[if lte IE 7]><script>var cdnVersion = '1.0.8';</script><![endif]-->
<!--[if IE 8]><script>var cdnVersion = '1.2.28';</script><![endif]-->
<!--[if gte IE 9]><!--><script>var cdnVersion = '1.5.9';</script><!--<![endif]-->
<script>if (!window.angular && window.console) { console.log('Local angular.js unavailable. Will attempt to load v'+cdnVersion+' from CDN.'); }</script>
<script>window.angular || document.write('<script src="//ajax.googleapis.com/ajax/libs/angularjs/' + cdnVersion + '/angular.js">\x3C/script>');</script>
<script src="lib/angular-placeholder.js"></script>
<script>
angular.module(['testApp'], ['ng.shims.placeholder'])
.run(function($rootScope, placeholderSniffer){
$rootScope.test = {
text: 'Hello, Ang',
password: 'secret1',
disabled_text: 'Hello, Carl',
disabled_password: 'secret3',
disabled_emptys: true,
disabled_prefilleds: true,
readonly_text: 'Hello, Eden',
readonly_password: 'secret5',
readonly_emptys: true,
readonly_prefilleds: true,
required_text: 'Hello, Fyodor',
required_password: 'secret6',
required_emptys: true,
required_prefilleds: true,
show_password: 'secret7',
hide_password: 'secret8',
show_inputs: true,
dynamic_text: 'text',
dynamic_password: 'password'
};
// Force enable polyfill in all browsers for demo
placeholderSniffer.hasPlaceholder = function () { return false; };
})
.directive('testTemplate', function () {
return {
template: function (elem, attrs) {
return '<input type="'+attrs.testTemplate+'" placeholder="'+attrs.testTemplate+'" ng-model="template_text" />';
},
link: function (scope) {
scope.template_text='Hello, Gary';
}
}
});
function fillElements (selector, str) {
var elements = document.querySelectorAll(selector);
for (var i = 0; i < elements.length; i++) {
angular.element(elements[i])
.val(str)
.triggerHandler('change');
}
}
function disableElements (selector, bool) {
var elements = document.querySelectorAll(selector);
for (var i = 0; i < elements.length; i++) {
angular.element(elements[i])
.prop('disabled', bool)
.triggerHandler('change');
}
}
function updatePlaceholders (selector, str) {
var elements = document.querySelectorAll(selector);
angular.element(elements)
.attr('placeholder', str)
.triggerHandler('change');
}
// polyfill for IE7 support (only necessary for demo functions)
if (!document.querySelectorAll) {
document.querySelectorAll = function (selectors) {
var style = document.createElement('style'), elements = [], element;
document.documentElement.firstChild.appendChild(style);
document._qsa = [];
style.styleSheet.cssText = selectors + '{x-qsa:expression(document._qsa && document._qsa.push(this))}';
window.scrollBy(0, 0);
style.parentNode.removeChild(style);
while (document._qsa.length) {
element = document._qsa.shift();
element.style.removeAttribute('x-qsa');
elements.push(element);
}
document._qsa = null;
return elements;
};
}
if (!document.querySelector) {
document.querySelector = function (selectors) {
var elements = document.querySelectorAll(selectors);
return (elements.length) ? elements[0] : null;
};
}
</script>
</body>
</html>