-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain-script.js
More file actions
6743 lines (5625 loc) · 253 KB
/
main-script.js
File metadata and controls
6743 lines (5625 loc) · 253 KB
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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//Credit: https://github.com/behnammodi/polyfill/blob/master/math.polyfill.js
Math.sign || (Math.sign = function ( x ) {
return ( (x > 0 ) - ( x < 0 ) ) || + x;
});
//Credit: https://stackoverflow.com/questions/31533963/polyfill-for-push-method-in-javascript
Array.push || (Array.prototype.push = function() {
for ( var i = 0; i < arguments.length; i++ ) {
this[this.length] = arguments[i];
}
return this.length;
});
//Credit: https://stackoverflow.com/questions/4775722/how-can-i-check-if-an-object-is-an-array
Array.isArray || (Array.isArray = function( arr ) {
return Object.prototype.toString.call( arr ) === '[object Array]';
});
//Credit: https://stackoverflow.com/questions/8511281/check-if-a-value-is-an-object-in-javascript
Object.isObject || (Object.isObject = function( obj ) {
return Object.prototype.toString.call( obj ) === '[object Object]' && null !== obj;
});
Object.hasOwnProperty || (Object.prototype.hasOwnProperty = function( prop ) {
return 'undefined' !== typeof this[ prop ];
});
Object.hasOwn || (Object.hasOwn = function( obj, prop ) {
//Use Object.prototype's hasOwnProperty method here just in case in obj has its own "hasOwnProperty" method, a direct method.
return Object.prototype.hasOwnProperty.call( obj, prop );
});
String.trim || (String.prototype.trim = function() {
return String( this ).replace( /^\s+|\s+$/,'' );
});
//Credit: https://learnersbucket.com/examples/interview/polyfill-for-array-foreach/
Array.forEach || (Array.prototype.forEach = function ( callback, context ) {
for ( var i = 0; i < this.length; i++ ) {
// This is primarily to check if the item exists in the array.
if ( this.indexOf( this[i] ) > -1) {
callback.call( context, this[i], i, this );
}
}
});
//Credit: https://medium.com/nerd-for-tech/polyfill-for-array-map-filter-and-reduce-e3e637e0d73b
Array.map || (Array.prototype.map = function( callbackFn ) {
var arr = [],
p = this,
len = p.length,
i = 0;
for ( ; i < len; i++ ) {
/* call the callback function for every value of this array and push the returned value into our resulting array*/
arr[ i ] = callbackFn( p[ i ], i, p );
}
return arr;
});
//Array.includes polyfill
Array.includes || (Array.prototype.includes = function( e ) {
if ( ! e ) return false;
var i = 0;
while( i < this.length ) {
if ( e == this[i++] ) return true;
}
return false;
});
//Capitalizes first letter of a string.
String.prototype.capitalize = function() {
return this.substring( 0, 1 ).toUpperCase() + this.slice(1);
};
(function( $, win ) {
/**
* Parses JSON data into JavaScript object.
*
* @param JSON obj JSON data to parse
* @return JavaScript object, parameter otherwise.
*/
win.isJson = function( obj ) {
try {
JSON.parse( obj );
} catch ( e ) {
return obj;
}
return JSON.parse( obj );
};
win.describr || ( win.describr = {} );
var sanitizeTxt = function ( faultyTxt ) {
faultyTxt = 'undefined' === typeof faultyTxt ? '' : faultyTxt;
var div = document.createElement('div'), txt;
div.innerHTML = String( faultyTxt );
txt = div.textContent || div.innerText || '';
return txt.trim();
},
//Similar to WordPress' map_deep()
sanitize = function ( dirty ) {
if ( Object.isObject( dirty ) ) {
for ( var n in dirty ) {
if ( 'userImage' !== n ) {
dirty[sanitizeTxt(n)] = sanitize( dirty[n] );
}
}
} else if ( Array.isArray( dirty ) ) {
var i = 0,
len = dirty.length;
while ( i < len ) {
dirty[i] = sanitize( dirty[i] );
i++;
}
} else {
dirty = sanitizeTxt( dirty );
}
return dirty;
},
i18n = sanitize( describri18n ),
i18nGen = i18n.general,
i18nChoose = i18n.choose,
describrBio,
tagline_len = describr.tagline_len ? parseInt( describr.tagline_len ) : 20,
textarea_LG = describr.textarea_LG ? parseInt( describr.textarea_LG ) : 1000,
textarea_SM = describr.textarea_SM ? parseInt( describr.textarea_SM ) : 300,
ptFndTxtBx = 'input[type="text"]',
ptLocs = ['current_city','hometown','lived_cities'],
describrLangsArr = [],
px = ptSep,//___, triple underscore: separator
pz = '__',//double underscore: separate layers in classes' attributes.
$tru = true,
flg = false,
$soc$ = 'socialnetworks',
ptSep = '___',
ptSrch = 'search',
phoneSep = '_',
plugin = 'describr',
hid = 'hidden',
ahid = ' aria-hidden="true"',
dpurp = 'data-purp',//Identifies input elements of type hidden that submit data
dataAtrr = ' data-plugin="' + plugin + '"',
$fne = plugin + 'phone',
$ext = plugin + 'ext',
fneCntry = 'phonecountry',
xToBool = function ( string ) {
if ( 'undefined' === typeof string ) {
string = '';
}
if ( $tru === string || 1 === string || '1' === string ) {
return $tru;
} else if ( flg === string || 0 === string || '0' === string || '' === String( string ).trim() || 'false' === string || 'undefined' === string ) {
return flg;
} else {
return $tru;
}
},
isMobile = Object.hasOwn( describr, 'isMobile' ) ? xToBool( describr.isMobile ) : flg,
canEdit = describr.profile && Object.hasOwn( describr.profile, 'canEdit' ) && xToBool( describr.profile.canEdit ),
mainDescribr = function ( $, _ ) {
var clr = i18nGen[28],
tStart = 'touchstart',
selOpt = ' selected="selected"',
selctMenu = plugin + pz + 'selectmenu',
errorTimeout,
/**
* Removes notices after eight seconds.
*/
noticesDismiss = function () {
clearTimeout( errorTimeout );
errorTimeout = setTimeout( function() {
doc.find( 'button[data-action="' + plugin + 'dismisserror"]' ).closest( 'div' ).remove();
}, 20000 );
},
/**
* Displays important notices to users.
*
* Notices are html formatted.
*
* @param string noticeType Portion of html class that indicates the type of notice: success or error, for example.
* Another class can be added to adjoined a class that will be used by JavaScript to remove
* the notice.
* @param string message The notice to display.
* @param bool autoClearMsg Whether the notice should be automatically removed from the Web page.
* @return string The notice to show the user.
*/
notices = function ( noticeType, message, autoClearMsg ) {
if ( ! autoClearMsg ) noticesDismiss();
var m = '<div class="is-dismissible ' + plugin + pz + 'notice notice-';
m += noticeType;
m += '"><p>';
m += message;
m += '</p><button' + dataAtrr + ' data-purp="dismisserror" data-action="' + plugin + 'dismisserror" type="button" class="notice-dismiss"><span class="screen-reader-text">' + i18nGen[49] + '</span></button></div>';
return m
},
html = {
el : function( HTML, ATTR, el ) {
el = el || 'div';
var htm = '<' + el;
if ( ATTR ) {
for( var j in ATTR ) {
htm += ' ' + j + '="' + ATTR[ j ] + '"';
}
}
htm += '>';
HTML && ( htm += HTML );
htm += '</' + el + '>';
return htm;
},//el
/**
* Creates template for each profile section.
*
* @param object obj {
* string header The header for the section (optional).
* string id ID for main container (optional).
* string clss Class for the main container.
* array table[{
* string th Table header
* string id ID for the profile section.
* string clss class for the profile section.
* string for Label "for" attribute containing the ID for the element that the label element labels
* array body [{
* object attr Contains attributes, class, id, etc, for the <td> tag (optional).
* string cntnt <td>'s content.
* }]
* }]
* }
* @return string Section's html layout with accompanying content.
*/
template : function( obj ) {
var isLbl = Object.hasOwn( obj, 'for' ) ? $tru : flg,
header = Object.hasOwn( obj, 'header' ),
htm = '';
if ( header ) {
htm += '<div';
if ( Object.hasOwn( obj, 'id' ) ) {
htm += ' id="' + obj.id + '"'
}
if ( Object.hasOwn( obj, 'clss' ) ) {
htm += ' class="' + obj.clss + '"';
}
htm += '><h3>' + obj.header + '</h3>';
}
obj.table.forEach( function( table ) {
var body = table.body,
isLbl = table.for || flg,
wr = table.id || table.clss ? 1 : 0;
if ( wr ) {
htm += '<div';
if ( table.id ) {
htm += ' id="' + table.id + '"';
}
if ( table.clss) {
htm += ' class="' + table.clss + '"';
}
htm += '>';
}
htm += '<table role="presentation" class="form-table"><tr><th scope="row">';
if ( isLbl ) {
htm += '<label for="' + table.for + '">';
}
if ( table.th ) {
htm += table.th;
}
if ( isLbl ) {
htm += '</label>';
}
htm += '</th>';
body.forEach( function( td ) {
htm += '<td';
if ( Object.hasOwn( td, 'attr' ) && Object.isObject( td.attr ) ) {
for ( var j in td.attr ) {
htm += ' ' + j + '="' + td.attr[ j ] + '"';
}
}
htm += '>';
htm += td.cntnt;
htm += '</td>';
});
htm += '</tr></table>';
if ( wr ) {
htm += '</div>';
}
});
if ( header ) {
htm += '</div>';
}
return htm;
},//template
input : function( attr ) {
var bx = '<input' + dataAtrr, n;
for ( n in attr ) {
bx += ' ' + n + '="' + attr[n] + '"';
}
bx += '>';
return bx;
},
cbxWr : function( elem, attr ) {
var bx = '<div';
if ( attr ) {
if ( Object.isObject( attr ) ) {
for ( var n in attr ) {
bx += ' ' + n + "='" + attr[ n ] + "'";
}
} else {
bx += attr;
}
}
bx += '>';
bx += elem;
bx +='</div>';
return bx;
}
},//html
/**
* Converts YYYY-MM-DD formatted date into array.
*
* @param string Date.
* @return array An array in which each section of the date is located at unique index.
*/
splitDate = function( date ) {
return ( date + '' ).split( '-' ).map( function( datePart ) {
return int( datePart );
});
},
time = {
lbl : [ i18n.date[0], i18n.date[1], i18n.date[2], i18nChoose[10], i18nChoose[11], i18nChoose[12] ],
s : 1000,
i : 60,
h : 60*60,
d : 60*60*24,
w : 60*60*24*7,
m : 60*60*24*7*4,
y: function() {
return this.d * ( this.isLpYr() ? 366 : 365 );
} ,
checkYears : function( t ) {
return Math.floor( t/this.y() );
},
checkMnths : function( t ) {
return Math.floor( t/this.m );
},
checkWks : function( t ) {
return Math.floor( t/this.w );
},
checkDays : function( t ) {
return Math.floor( t/this.d );
},
checkHrs : function( t ) {
return Math.floor( t/this.h );
},
checkMins : function( t ) {
return Math.floor( t/this.i );
},
/**
* Provides the current year or a year in the past.
*
* @param int ago The number of years to subtract from the current year.
* @return int The current year or a year in the past.
*/
newY : function( ago ) {
var yr = new Date().getFullYear();
if ( ago ) {
yr -= ago;
}
return yr
},
//Object of months of the year, with 2-digit represention of months as properties and text represention of months as values.
months : i18n.months,
/**
* Creates the number of years, as options, to show the user.
*
* @param int latestYear The latest year from which to start, decrementing until 1900, the earliest year.
* @return array Years to display.
*/
years : function( latestYear ) {
latestYear = latestYear || this.newY();
for ( var years = [], i = 0 ; latestYear >= 1900 ; i++, latestYear-- ) {
years[i] = latestYear;
}
return years;
},
//Checks if year is a leap year. Returns true if year is a leap year, false otherwise.
isLpYr : function( year ) {
var y = year || this.newY();
return ( ( y % 4 == 0 ) && ( y % 100 != 0 ) ) || ( y % 400 == 0 );
},
/**
* Finds month of the year.
*
* Converts month value (00) to that of array index.
*
* The index will likely to be used to find text representation of a specific month.
*
* The converted value is reduced by one as array indexing begins at 0.
*
* @param string month The value to convert.
* @return int Array index.
*/
findMonth : function( month ) {
//Uses the character at index 1 if the first character is zero.
if ( 2 == month.length && 0 == month[0] ) {
month = month[1];
}
month -=1;//Reduces number by one to find correct element in array.
month = this.months[month];
return month;
},
/**
* Removed disallowed characters from dates, with only characters "0-9" and "-" allowed.
*
* @param string date The date to escape.
* @return string The date, with disallowed characters removed.
*/
escDate : function( date ) {
return date.replace( /[^0-9-]/, '' );
},
/**
* Sets up the html date's part, so the user can select year, month, or day.
*
* @param object obj{
* string class The main class for the parts.
* string date An existing date that will be shown instead of the defaults values.
* string id The main ID for the parts. Each part will add to ensure each part has a unique ID.
* string nameAttr The input element's name attribute's value. This will only be added if the user is in admin.
* string ago An earlier date from which to start showing years, instead of starting from the current year.
* string sctn The profile section to which the parts belong.
* }
* @return string Date's parts for choosing a date, otherwise empty.
*/
setupDate : function( obj ) {
var u = this,
clss2 = obj.class || '',//main class
sctn = obj.sctn || '',//section (eg., birthdate)
ago = obj.ago || '',//earlier year from which to start?
date = obj.date ? u.splitDate( obj.date ) : [],//any existing date?
len = date.length,
htm = '',//Store html to return.
obj1 = {},
pick = u.datePickr(),
p;
pick.class = clss2;
pick.note = sctn;
if ( obj.id ) {
pick.id = obj.id;
}
//Add upper-limit year for time periods.
if ( obj.to ) {
pick.future = obj.future;
}
if ( ! len ) {
date[len] = u.newY( ago );
}
pick.date = date;
pick.wrap = !0;
htm += pick.year();
htm += pick.month();
htm += pick.day();
p = date[0];
if ( 1 < len ) {
p += '-' + date[1];
}
if ( 2 < len ) {
p += '-' + date[2];
}
obj1.type = hid;
obj1.name = obj.nameAttr;
obj1.value = p;
obj1[dpurp] = 'submit';
htm += html.input( obj1 );
return htm;
},//setupDate
datePickr : function() {
var time1 = this;
return {
curYr : new Date().getFullYear(),
startYr : function () {
var u = this,
yr = u.curYr;
if ( u.future ) {
yr += u.future;
} else if ( u.ago ) {
yr -= u.ago;
}
return yr;
},
year : function() {
var u = this,
date = u.date,
label = time1.lbl[0],
p = 'year',
clss1 = u.class + pz + p,
year = date.length ? date[0] : u.curYr,
offsetYr = '',
htm = '';
if ( u.future || u.ago ) {
offsetYr = u.startYr();
}
time1.years( offsetYr ).forEach( function( i ) {
htm += '<option';
if ( year == i ) {
htm += selOpt;
}
htm += ' value="' + i + '">' + i + '</option>';
});
if ( u.wrap ) {
htm = u.btn( htm, label, p, clss1 );
}
return htm;
},
month : function() {
var u = this,
date = u.date,
p = 'month',
label = time1.lbl[1],
clss1 = u.class + pz + p,
month = 1 < date.length ? date[1] : '',
htm = '';
for ( var i = 0, v, mn = time1.months, len = mn.length; i < len; i++ ) {
v = i + 1;
//Convert month to two digits if less than 10.
if ( 10 > v ) {
v = '0' + v;
}
htm += '<option';
if ( v == month ) {
htm += selOpt;
}
htm += ' value="' + v + '">' + mn[i] + '</option>';
};
htm = '<option value="">' + label + '</option>' + htm;
if ( u.wrap ) {
htm = u.btn( htm, label, p, clss1 );
}
return htm;
},
day : function() {
var u = this,
date = u.date,
p = 'day',
label = time1.lbl[2],
clss1 = u.class + pz + p,
isLpYr = time1.isLpYr(),
len = date.length,
month = 1 < len ? date[1] : '',
day = 2 < len ? date[2] : '',
htm = '';
for ( var i = 1, $i; i <= 31; i++ ) {
//If both the current year is a leap year and the month is February, break before day 30, giving February 29 days.
if ( isLpYr ) {
if ( '02' == month && 30 == i ) {
break;
}
} else if( '02' == month ) { //If month is February, break before day 29, giving February 28 days.
if ( 29 == i ) {
break;
}
} else if ( 31 == i && ( '04' == month || '06' == month || '09' == month || '11' == month ) ) {
//If the month is either April, June, September, or November, break before day 31, giving either month 30 days.
break;
}
htm += '<option';
$i = i;
if ( 10 > i ) {
$i = '0' + i;
}
if ( $i == day ) {
htm += selOpt;
}
//Prepends number 0 to months that have fewer than 2 digits, always obeying 2-digit-month format.
htm += ' value="' + $i + '">' + i + '</option>';
}
htm = '<option value="">' + label + '</option>' + htm;
if ( u.wrap ) {
htm = u.btn( htm, label, p, clss1, day );
}
return htm;
},//day
btn : function ( options, label, part, clss, curVal ) {
var u = this,
htm = '<select data-purp="date" data-activity="';
htm += u.note;
htm += '" data-part="';
htm += part;
htm += '" aria-label="';
htm += label;
htm += '" id="';
if ( u.id ) {
htm += u.id + '-' + part;
} else {
htm += class2Id( clss );
}
htm += '" class="';
htm += clss;
htm += ' ';
htm += selctMenu;
htm += '"';
//If day, set default value, which is used in jquery selectmenu to decide whether the menu button will be automatically shown.
if ( 'day' == part ) {
htm += ' data-curval="';
if ( '' === curVal ) {
curVal = '-';
}
htm += curVal;
htm += '"';
}
htm += '>';
htm += options;
htm += '</select>';
return htm;
}
}//return
}//datePickr
},//time
/**
* Creates dashicon.
* @param object obj{
* string class Additional class to add to the dashicon element.
* string icon The specific icon to display.
* }
* @return string The dashicon to display.
*/
icons = {
init : function( obj ) {
htm = '<span' + ahid + ' class="';
if ( obj.class ) {
htm += obj.class;
}
htm += pz + 'icon dashicons dashicons-' + obj.icon + '"></span>';
return htm;
},
warning : function( obj, $section$ ) {
obj = obj || {};
var icon = 'warning';
obj.icon = icon;
if ( obj.class ) {
obj.class += pz + icon;
}
return '<p class="' + obj.class + '">' + sprintf( i18nGen[34], $section$ ) + '</p>';
},
/**
* Generates html button element.
*
* @param attr Object with properties as the button's attributes and values as the button's attributes' values.
* @return string html button element.
*/
btnGen : function( attr ) {
var btn = '<button' + dataAtrr,
type = 'button',
a,
p;
for ( a in attr ) {
p = attr[a];
//Changes the type from the default, 'button,' to the type passed in the argument.
if ( 'type' == a ) {
type = p;
continue;//Skips attaching type attribute here as it will be subsequently attached.
} else if ( 'txt' == a ) {
continue;
}
btn += ' ' + a + '="' + p + '"';
}
btn += ' type="' + type + '"';
btn += '>';
if ( Object.hasOwn( attr, 'txt' ) ) {
btn += attr.txt;
}
btn += '</button>';
return btn;
},//btnGen
/**
* Creates button used to remove text from controlled textbox.
*
* @param object obj Additional attrbutes for the button.
* @return string Customized button used to clear textbox.
*/
clrTxt : function( obj ) {
var obj1 = mnObj.clrObj, n, c = 'class';
for ( n in obj ) {
obj1[n] = obj[n];
}
//Adds the dashicon classes to existing classes so the "x" can be displayed on the button.
obj1[c] = obj1[c] + pz + 'button dashicons-before dashicons-no-alt';
return this.btnGen( obj1 );
},
prvcy : {
priv : 'privacy',
init : function( status ) {
if ( 'undefined' === typeof status ) status = 1;
var self = this,
priv = self.priv,
clss = self.clss + pz + priv,
opts = [],
obj = { id : class2Id( clss ), class : clss, purp : priv, label : self.label + '" title="' + i18nGen[46] },
htm = '';
self.options.forEach( function ( option ) {
var item = {
value : option.val,
label : option.txt
};
if ( option.val == status ) {
item.selected = !0;
}
opts.push( item );
});
obj.option = opts;
obj.extra = [ html.input( { type : hid, name : self.name + '[visibility]', value : status, 'data-purp': 'submit' } ) ];
return select( obj );
},
//List of privacy options from which users can select.
options : [ { val : 1, txt : i18n.privacy[0] }, { val: 0, txt : i18n.privacy[1] } ]
},//privacy
dsbld : ' disabled="disabled"',
/**
* Changes html attribute by removing the last part of the attribute and appending string that will uniquely identify another element.
*
* @param object obj{
* string attr The attribute to change.
* string sep The character used to convert the attribute to an array.
* string join The character used to rejoin parts of the attribute.
* string end The string that identifies another element.
* }*/
chgAttr : function( obj ) {
return obj.attr.split( obj.sep ).slice( 0, -1 ).join( obj.join ) + obj.join + obj.end;
}
},//icons
mnObj = {
clrObj : { 'data-purp' : 'clear', 'aria-label' : clr, 'title' : clr },
chckd : ' checked="checked"',
popstate : !!_.history.pushState,
fileApiSupported : !!(_.File && _.FileReader && _.FileList && _.Blob),
click : tStart in document.documentElement ? 'click ' + tStart : 'click',
//Prevents false positive click event when user swipes on touchscreen devices
pc : function( e ) {
var type = e.type,
z,
touch,
positionX;
if ( ! /(touchstart)/.test( document.documentElement ) ) {
return $tru;
}
if ( tStart == type ) {
z = $tru;
touch = e.targetTouches;
positionX = touch[ touch.length-1 ].pageX;
e.target.ontouchend = function( _ ){
touch = _.targetTouches;
if ( touch[touch.length-1].pageX != positionX ) {
z = flg;
e.preventDefault();
}
}
return z;
} else if( 'click' == type ){
return $tru;
}
return flg;
}//pc
};//mnObj
/**
* Displays parts of address separated by commas
*
* Removes country from address if it's United States
*
* @param string addr The address to display
* @return string The address.
*/
function displayAddr ( addr ) {
var sep = ', ',
city = addr.city.split( sep );
if ( 3 == city.length && 'United States' == city[2] ) {
city.pop();
}
city = city.join( sep );
return city;
}
/**
* Suggests cities using keywords.
*
* @param string addr The keywords.
* @return array Cities that fully or partially matched the keywords.
*/
function citiesFnd ( addr ) {
var citiesFound = [],
citiesFnd1 = [],
len;
if ( ! ( addr = addr.trim() ) ) return citiesFound;
addr = addr.toLowerCase().split( /\s*(?:,|\/)\s*/, 3 );
len = addr.length;
if ( '' == addr[len-1] ) {
addr.pop();
len = addr.length;
}
if ( len ) {
$.each( describrCities, function() {
var city = this,
cityName = city.name,
cityName_ = cityName.toLowerCase(),
countryCode = city.countryCode;
if ( 0 === cityName_.indexOf( addr[0] ) ) {
citiesFound.push({
name : cityName,
state : findState( { stateCode : city.stateCode, countryCode : countryCode } ).name,
country : findCountry( countryCode ).name,
countryCode : city.countryCode,
twin_city : ( ( function() {
//By default, assume that only one of each city exists.
var isTwinCity = 0;
//Iterates over cities already found and checks if this city already exists.
citiesFound.map( function( _city ) {
var twinCity = _city.twin_city;//twinCity of already saved city.
//Is the city (cityName) being added a twin city of an already saved city (city.name)?
if( cityName == _city.name ) {
if ( ! twinCity ) {
twinCity = 1;
}
isTwinCity = 1;
}
_city.twin_city = twinCity;
return _city;//This return is for citiesFound.map.
});
return isTwinCity;//This return is for twinCity:.
})())
});//Push ends here.
}
});
for ( var i = 0, len1 = citiesFound.length; i < len1; i++ ) {
var city = citiesFound[i],
country = city.country,
state = country2State( city.name, country );
if ( ! state ) {
state = city.state.toLowerCase()
}
country = country.toLowerCase();
state = state.toLowerCase();
if ( 3 == len && 0 !== state.indexOf( addr[1] ) && 0 !== country.indexOf( addr[2] ) ) {
continue;
}
if ( 2 == len && 0 !== state.indexOf( addr[1] ) ) {
continue;
}
citiesFnd1[ citiesFnd1.length ] = city;
}
}