-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsaved_resource(5)
1182 lines (993 loc) · 41.3 KB
/
saved_resource(5)
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
/*!
AutoResize v1.18.4 - 2014-01-11
Automatically adjust textarea height based on user input.
(c) 2014 Jack Moore - http://www.jacklmoore.com/autosize
Originally altered by mdawaffe.
Current version altered by pento.
license: http://www.opensource.org/licenses/mit-license.php
*/
(function ($) {
var
defaults = {
className: 'autosizejs',
append: '',
callback: false,
resizeDelay: 10,
placeholder: true,
animate: true,
animateDuration: 150,
animateCallback: function(){},
extraSpace: 20
},
// border:0 is unnecessary, but avoids a bug in Firefox on OSX
copy = '<textarea tabindex="-1" style="position:absolute; top:-999px; left:0; right:auto; bottom:auto; border:0; padding: 0; -moz-box-sizing:content-box; -webkit-box-sizing:content-box; box-sizing:content-box; word-wrap:break-word; height:0 !important; min-height:0 !important; overflow:hidden; transition:none; -webkit-transition:none; -moz-transition:none;"/>',
// line-height is conditionally included because IE7/IE8/old Opera do not return the correct value.
typographyStyles = [
'fontFamily',
'fontSize',
'fontWeight',
'fontStyle',
'letterSpacing',
'textTransform',
'textDecoration',
'wordSpacing',
'textIndent'
],
// to keep track which textarea is being mirrored when adjust() is called.
mirrored,
// the mirror element, which is used to calculate what size the mirrored element should be.
mirror = $(copy).data('autosize', true)[0];
// test that line-height can be accurately copied.
mirror.style.lineHeight = '99px';
if ($(mirror).css('lineHeight') === '99px') {
typographyStyles.push('lineHeight');
}
mirror.style.lineHeight = '';
$.fn.autoResize = function (options) {
if (!this.length) {
return this;
}
options = $.extend({}, defaults, options || {});
if (mirror.parentNode !== this.parentNode) {
$(mirror).insertBefore(this);
}
return this.each(function () {
var
ta = this,
$ta = $(ta),
maxHeight,
minHeight,
boxOffset = 0,
callback = $.isFunction(options.callback),
originalStyles = {
height: ta.style.height,
overflow: ta.style.overflow,
overflowY: ta.style.overflowY,
wordWrap: ta.style.wordWrap,
resize: ta.style.resize
},
timeout,
width = $ta.width();
if ($ta.data('autosize')) {
// exit if autosize has already been applied, or if the textarea is the mirror element.
return;
}
$ta.data('autosize', true);
if ($ta.css('box-sizing') === 'border-box' || $ta.css('-moz-box-sizing') === 'border-box' || $ta.css('-webkit-box-sizing') === 'border-box'){
boxOffset = $ta.outerHeight() - $ta.height();
}
// IE8 and lower return 'auto', which parses to NaN, if no min-height is set.
minHeight = Math.max(parseInt($ta.css('minHeight'), 10) - boxOffset || 0, $ta.height());
$ta.css({
overflow: 'hidden',
overflowY: 'hidden',
wordWrap: 'break-word', // horizontal overflow is hidden, so break-word is necessary for handling words longer than the textarea width
resize: ($ta.css('resize') === 'none' || $ta.css('resize') === 'vertical') ? 'none' : 'horizontal'
});
// The mirror width must exactly match the textarea width, so using getBoundingClientRect because it doesn't round the sub-pixel value.
// window.getComputedStyle, getBoundingClientRect returning a width are unsupported, but also unneeded in IE8 and lower.
function setWidth() {
var width;
var style = window.getComputedStyle ? window.getComputedStyle(ta, null) : false;
if (style) {
width = ta.getBoundingClientRect().width;
if (width === 0) {
width = parseInt(style.width,10);
}
$.each(['paddingLeft', 'paddingRight', 'borderLeftWidth', 'borderRightWidth'], function(i,val){
width -= parseInt(style[val],10);
});
} else {
width = Math.max($ta.width(), 0);
}
mirror.style.width = width + 'px';
}
function initMirror() {
var styles = {};
mirrored = ta;
mirror.className = options.className + " " + ta.className;
maxHeight = parseInt($ta.css('maxHeight'), 10);
// mirror is a duplicate textarea located off-screen that
// is automatically updated to contain the same text as the
// original textarea. mirror always has a height of 0.
// This gives a cross-browser supported way getting the actual
// height of the text, through the scrollTop property.
$.each(typographyStyles, function(i,val){
styles[val] = $ta.css(val);
});
$(mirror).css(styles);
setWidth();
// Chrome-specific fix:
// When the textarea y-overflow is hidden, Chrome doesn't reflow the text to account for the space
// made available by removing the scrollbar. This workaround triggers the reflow for Chrome.
if (window.chrome) {
var width = ta.style.width;
ta.style.width = '0px';
var ignore = ta.offsetWidth;
ta.style.width = width;
}
}
// Using mainly bare JS in this function because it is going
// to fire very often while typing, and needs to very efficient.
function adjust() {
var height, original;
if (mirrored !== ta) {
initMirror();
} else {
setWidth();
}
if (!ta.value && options.placeholder) {
// If the textarea is empty, copy the placeholder text into
// the mirror control and use that for sizing so that we
// don't end up with placeholder getting trimmed.
mirror.value = ($ta.attr("placeholder") || '') + options.append;
} else {
mirror.value = ta.value + options.append;
}
mirror.style.overflowY = ta.style.overflowY;
original = parseInt(ta.style.height,10);
// Setting scrollTop to zero is needed in IE8 and lower for the next step to be accurately applied
mirror.scrollTop = 0;
mirror.scrollTop = 9e4;
// Using scrollTop rather than scrollHeight because scrollHeight is non-standard and includes padding.
height = mirror.scrollTop + options.extraSpace;
if (maxHeight && height > maxHeight) {
ta.style.overflowY = 'scroll';
height = maxHeight;
} else {
ta.style.overflowY = 'hidden';
if (height < minHeight) {
height = minHeight;
}
}
height += boxOffset;
height = Math.floor( height );
if (original !== height) {
if ( options.animate && $ta.css( 'display' ) === 'block' ) {
$ta.stop().animate( {height: height}, options.animateDuration, options.animateCallback );
} else {
ta.style.height = height + 'px';
options.animateCallback.call( this );
}
if (callback) {
options.callback.call(ta,ta);
}
}
}
function resize () {
clearTimeout(timeout);
timeout = setTimeout(function(){
var newWidth = $ta.width();
if (newWidth !== width) {
width = newWidth;
adjust();
}
}, parseInt(options.resizeDelay,10));
}
if ('onpropertychange' in ta) {
if ('oninput' in ta) {
// Detects IE9. IE9 does not fire onpropertychange or oninput for deletions,
// so binding to onkeyup to catch most of those occasions. There is no way that I
// know of to detect something like 'cut' in IE9.
$ta.on('input.autosize keyup.autosize', adjust);
} else {
// IE7 / IE8
$ta.on('propertychange.autosize', function(){
if(event.propertyName === 'value'){
adjust();
}
});
}
} else {
// Modern Browsers
$ta.on('input.autosize', adjust);
}
// Set options.resizeDelay to false if using fixed-width textarea elements.
// Uses a timeout and width check to reduce the amount of times adjust needs to be called after window resize.
if (options.resizeDelay !== false) {
$(window).on('resize.autosize', resize);
}
// Event for manual triggering if needed.
// Should only be needed when the value of the textarea is changed through JavaScript rather than user input.
$ta.on('autosize.resize', adjust);
// Event for manual triggering that also forces the styles to update as well.
// Should only be needed if one of typography styles of the textarea change, and the textarea is already the target of the adjust method.
$ta.on('autosize.resizeIncludeStyle', function() {
mirrored = null;
adjust();
});
$ta.on('autosize.destroy', function(){
mirrored = null;
clearTimeout(timeout);
$(window).off('resize', resize);
$ta
.off('autosize')
.off('.autosize')
.css(originalStyles)
.removeData('autosize');
});
// Call adjust in case the textarea already contains text.
adjust();
});
};
}(window.jQuery || window.$)); // jQuery or jQuery-like library, such as Zepto
;
var HighlanderComments = jQuery.extend( HighlanderComments, {
autosaveInterval: false,
commentList: null,
initialHeight: 70,
cookies: { facebook: 'wpc_fbc', twitter: 'wpc_tc', wordpress: 'wpc_wpc', googleplus: 'wpc_gpc' },
popups: { facebook: ',height=400,width=600', twitter: ',height=515,width=600', wordpress: ',height=500,width=500' },
temp_cookie_data: '',
currentParent: false,
currentParentId: false,
currentParentMargins: {},
resizeCallback: function() {},
init : function() {
jQuery( '#respond' ).addClass( 'js' );
HighlanderComments.commentList = jQuery( '#thecomments, .thecomments, #commentlist, #comment-list, #comments-list, .commentlist, .comment-list, .comments-list, .com-list, #comments' ).last();
jQuery( '#comment-form-nascar a' ).click( HighlanderComments.clickService );
jQuery( '#postas-wordpress' ).click( HighlanderComments.clickExternalTab );
jQuery( '#postas-facebook, #labelto-facebook' ).click( HighlanderComments.clickExternalTab );
jQuery( '#postas-twitter, #labelto-twitter' ).click( HighlanderComments.clickExternalTab );
pm.bind( 'googlePlusButtonClick', HighlanderComments.onGooglePlusButtonClick, 'https://public-api.wordpress.com' );
pm.bind( 'googlePlusSignIn', HighlanderComments.onGooglePlusSignIn, 'https://public-api.wordpress.com' );
jQuery( '#labelto-wordpress' ).click( HighlanderComments.checkPostToWordPress );
jQuery( '#comment-form-post-to-edit a' ).click( HighlanderComments.editShareText );
jQuery( window ).resize( HighlanderComments.toggleShareLabels );
HighlanderComments.toggleShareLabels();
HighlanderComments.restoreComment();
// HighlanderComments.autosaveInterval = setInterval( HighlanderComments.autosaveComment, 10000 );
jQuery.each( jQuery( '.comment-form-field input, textarea#comment' ), function() {
if ( jQuery(this).val() !== '' ) {
HighlanderComments.hideLabels( jQuery(this) );
}
} );
jQuery( 'div.comment-form-fields input' ).change( function() { HighlanderComments.toggleLabel( jQuery(this) ); } ).focus( function() { HighlanderComments.hideLabels( jQuery(this) ); } ).blur( function() { HighlanderComments.showLabels( jQuery(this) ); } );
jQuery( 'div.comment-form-fields label' ).click( function() { HighlanderComments.hideLabels( jQuery(this).parent().children( '.comment-form-input input' ) ); } );
// Identity auto-fill from Gravatar Profiles
jQuery( '#email' ).blur( function() {
HighlanderComments.updateAvatarWithGravatar( '#email' );
if ( !jQuery( '#author' ).val() ) {
Gravatar.autofill( jQuery( this ).val(), {
'displayName':'author',
'url':'url' // Their first available link, or profile URL if none
} );
var afd = Gravatar.autofill_data;
Gravatar.autofill_data = function( hash ) {
afd.call( Gravatar, hash );
jQuery( 'input#url' ).change();
jQuery( 'input#author' ).change().click();
};
}
} );
// Comment area auto-sizing and tab handling
jQuery( 'textarea#comment' )
.autoResize({
animate: false,
animateCallback: HighlanderComments.resizeCallback
})
.css( 'resize', 'none' )
.trigger('change.dynSiz')
.focus( function() { HighlanderComments.hideLabels( jQuery(this) ); } )
.blur( function() { HighlanderComments.showLabels( jQuery(this) ); } )
.keydown( function( e ) {
if ( 'undefined' != typeof e.keyCode && 9 == e.keyCode ) { // TAB key
e.preventDefault();
if ( 'guest' == jQuery( '#hc_post_as' ).val() ) {
if ( 1 == HighlanderComments.comment_registration ) {
jQuery( '#postas-wordpress' ).focus();
} else {
jQuery( '#email' ).focus();
}
} else {
jQuery( '#comment-submit' ).focus();
}
}
} )
.keyup( function( e ) { HighlanderComments.fillShareText( jQuery(this) ); } )
.one( 'focus', function() {
var googlePlusSignIn = jQuery( '#googleplus-sign-in' );
if ( googlePlusSignIn.length < 1 ) {
return;
}
pm( {
target: googlePlusSignIn[0].contentWindow,
type: 'googlePlusLoadJS',
data: 0,
url: 'https://public-api.wordpress.com'
} );
});
// Client-side form validation
jQuery( '#commentform' ).submit( function() {
var verified = true, email, author;
// Comment text required
if ( '' === jQuery( 'textarea#comment' ).val() ) {
jQuery( 'label[for="comment"]' ).fadeOut( 'fast', function() {
jQuery(this).text( HighlanderComments.enterACommentError ).fadeIn( 'fast').addClass('error');
} );
jQuery( '#comment-form-comment' ).addClass('error');
jQuery( 'textarea#comment' ).focus( function() { jQuery(this).parent( '#comment-form-comment' ).removeClass('error'); } );
verified = false;
}
// Only exists if email/name are required
if ( 'guest' == jQuery( '#hc_post_as' ).val() && ( jQuery( '#comment-form-guest label span[class="required"]' ).size() || jQuery( '#comment-form-guest label[class="error"]' ).size() ) ) {
email = jQuery( '#email' ).val();
if ( '' === email || !email.match( /^.*@.*\..*$/ ) ) {
jQuery( 'label[for="email"]' ).fadeOut( 'fast', function() {
var error;
if ( '' == email ) {
error = HighlanderComments.enterEmailError;
} else {
error = '<span class="nopublish">' + HighlanderComments.invalidEmailError + '</span>';
}
jQuery(this).html( error ).css( 'opacity', 1 ).fadeIn( 'fast' ).addClass( 'error' );
});
jQuery( 'div.comment-form-email .comment-form-input' ).addClass('error');
jQuery( 'input#email' ).focus( function() { jQuery(this).parent().removeClass( 'error' ); } );
verified = false;
}
author = jQuery( '#author' ).val();
if ( '' === author ) {
jQuery( 'label[for="author"]' ).fadeOut( 'fast', function() {
jQuery(this).text( HighlanderComments.enterAuthorError ).fadeIn('fast').addClass( 'error' );
} );
jQuery( 'div.comment-form-author .comment-form-input' ).addClass('error');
jQuery( 'input#author' ).focus( function() { jQuery(this).parent().removeClass( 'error' ); } );
verified = false;
}
}
// Don't allow "guest" comments if auth is required
if ( '1' == HighlanderComments.comment_registration && 'guest' == jQuery( '#hc_post_as' ).val() ) {
jQuery( '#comment-form-nascar > p' ).addClass( 'error' ).fadeOut( 'fast', function() {
jQuery( this ).fadeIn( 'fast' );
} );
verified = false;
}
// Set a cookie to remember which was the last used tab
HighlanderComments.writeCookie( 'hc_post_as', jQuery( '#hc_post_as' ).val(), 7, '.wordpress.com' );
if ( !verified ) {
return false;
}
HighlanderComments.clickSubmit();
return true;
} );
// Set up the identity block based on WP options, logged in state, etc
if ( '1' == HighlanderComments.comment_registration ) {
// Must be logged in to comment (guest commenting not allowed)
jQuery('#comment-form-guest').hide();
if ( !HighlanderComments.isJetpack && !HighlanderComments.userIsLoggedIn ) {
// Force to guest posting if they're not logged in, which should actually not allow itself
HighlanderComments.clickGuestTab();
jQuery( '#comment-form-wordpress' ).removeClass( 'selected' );
jQuery( '#hc_post_as' ).val( 'guest' );
}
} else {
// Guest commenting is allowed
if ( HighlanderComments.userIsLoggedIn && jQuery( '#comment-form-wordpress.selected' ).length ) {
// User is logged in and we're looking at the WP UI already, get rid of guest commenting
jQuery( '#comment-form-guest' ).slideUp( 'fast' );
}
}
if ( jQuery( '.comment-form-service.selected' ).not( '#comment-form-guest.selected' ).length ) {
// Something other than Guest is selected, hide the auth strip
jQuery( '#comment-form-nascar' ).hide();
}
if ( 'undefined' !== typeof addComment ) {
HighlanderComments._moveForm = addComment.moveForm;
addComment.moveForm = HighlanderComments.moveForm;
}
// Hover Tooltips
jQuery( '#comment-form-guest .comment-form-avatar' ).hover( function() {
pos = jQuery( this ).offset();
if ( 'rtl' === HighlanderComments.text_direction ) {
style = 'top:' + ( pos.top - 10 ) + 'px;left:' + ( pos.left - 130 ) + 'px;';
} else {
style = 'top:' + ( pos.top - 10 ) + 'px;left:' + ( pos.left + 35 ) + 'px;';
}
jQuery( 'body' ).append( '<div id="hltt-grav" class="highlander-tooltip" style="' + style + '">' + HighlanderComments.gravatarFromEmail + '</div>' );
}, function() {
jQuery( '#hltt-grav' ).fadeOut( 'fast', function() {
jQuery( this ).remove();
jQuery( '.highlander-tooltip' ).remove();
} );
} );
jQuery( '#comment-form-nascar ul' ).hover( function() {
pos = jQuery( this ).offset();
if ( 'rtl' === HighlanderComments.text_direction ) {
style = 'top:' + ( pos.top - 12 ) + 'px;left:' + ( pos.left + 125 ) + 'px;';
} else {
style = 'top:' + ( pos.top - 12 ) + 'px;left:' + ( pos.left - 125 ) + 'px;';
}
jQuery( 'body' ).append( '<div id="hltt-auth" class="highlander-tooltip" style="' + style + '">' + HighlanderComments.logInToExternalAccount + '</div>' );
}, function() {
jQuery( '#hltt-auth' ).fadeOut( 'fast', function() {
jQuery( this ).remove();
jQuery( '.highlander-tooltip' ).remove();
} );
} );
},
_moveForm: null,
moveForm: function( commId, parentId, respondId, postId ) {
if ( null === HighlanderComments._moveForm ) {
return;
}
var t = this,
r = false,
respond = jQuery( '#' + respondId ).css( { marginLeft: 0, marginRight: 0 } ),
w, wTop, commElement, rHeight, cTop, rTop;
if ( HighlanderComments.currentParent ) {
if ( parentId === HighlanderComments.currentParentId ) {
return false;
}
w = jQuery(window);
wTop = w.scrollTop();
commElement = jQuery( '#' + commId );
cTop = commElement.offset().top;
rTop = respond.offset().top;
if ( rTop <= cTop ) {
rHeight = respond.outerHeight( true );
respond.before( jQuery( '<div id="highlander-placeholder" />' ).css( { margin: 0, padding: 0, border: 0, height: rHeight, visibility: 'hidden', position: respond.css( 'position' ) } ) );
}
r = HighlanderComments._moveForm.call( t, commId, parentId, respondId, postId );
if ( false !== r ) {
return r;
}
HighlanderComments.currentParent.stop( true, true ).css( HighlanderComments.currentParentMargins );
jQuery( '#highlander-placeholder' ).remove();
if ( rTop <= cTop ) {
jQuery( window ).scrollTop( wTop - rHeight );
}
HighlanderComments.moveFormNow.call( t, commId, parentId, respondId );
} else {
r = HighlanderComments._moveForm.call( t, commId, parentId, respondId, postId );
if ( false === r ) {
HighlanderComments.moveFormNow.call( t, commId, parentId, respondId );
}
}
return r;
},
moveFormNow: function( commId, parentId, respondId ) {
HighlanderComments.currentParent = jQuery( '#comment-' + parentId ).parents( '.highlander-comment' ).andSelf().filter( '.highlander-comment' ).last();
if ( !HighlanderComments.currentParent.size() ) {
HighlanderComments.currentParent = jQuery( '#comment-' + parentId ).parents( '.comment' ).andSelf().filter( '.comment' ).last();
}
HighlanderComments.currentParentId = parentId;
var respond = jQuery( '#' + respondId );
if ( !HighlanderComments.currentParent.find( respond ).size() ) {
var betterParent = HighlanderComments.currentParent.parents( '.children:first' );
if ( !betterParent.size() ) {
betterParent = HighlanderComments.currentParent.parents( '.highlander-comment:first' );
if ( !betterParent.size() ) {
betterParent = HighlanderComments.currentParent.parents( '.comment:first' );
}
}
if ( betterParent.size() ) {
HighlanderComments.currentParent = betterParent;
}
}
HighlanderComments.currentParentMargins = {
backgroundColor: HighlanderComments.currentParent.css( 'backgroundColor' ),
marginLeft: HighlanderComments.currentParent.css( 'marginLeft' ),
marginRight: HighlanderComments.currentParent.css( 'marginRight' )
};
var oldOff, newOff, offOrder, autoWidth = false;
if ( 'rtl' === HighlanderComments.text_direction ) {
offOrder = [ 'Left', 'Right' ];
} else {
offOrder = [ 'Right', 'Left' ];
}
jQuery.each( offOrder, function( i, v ) {
if ( '0px' === HighlanderComments.currentParentMargins['margin' + v] ) {
oldOff = HighlanderComments.currentParent.offset().left;
if ( 'Right' === v ) {
oldOff += HighlanderComments.currentParent.outerWidth();
}
HighlanderComments.currentParent.css( 'margin' + v, 0 );
newOff = HighlanderComments.currentParent.offset().left;
if ( 'Right' === v ) {
newOff += HighlanderComments.currentParent.outerWidth();
}
if ( oldOff !== newOff ) {
newOff = 'Right' === v ? newOff - oldOff : oldOff - newOff;
HighlanderComments.currentParent.css( 'margin' + v, newOff );
HighlanderComments.currentParentMargins['margin' + v] = newOff;
autoWidth = true;
}
}
} );
if ( autoWidth ) {
HighlanderComments.currentParent.css( 'width', 'auto' );
HighlanderComments.currentParentMargins.width = 'auto';
}
var rgbaTransparent = /rgba.*,\s*0\s*\)/, cp, bg, bgi;
if ( 'transparent' === HighlanderComments.currentParentMargins.backgroundColor || HighlanderComments.currentParentMargins.backgroundColor.match( rgbaTransparent ) ) {
cp = HighlanderComments.currentParent.get( 0 );
bg = 'transparent';
bgi = HighlanderComments.currentParent.css( 'backgroundImage' );
while ( 'none' === bgi && cp.parentNode && cp.parentNode != document && ( 'transparent' === bg || bg.match( rgbaTransparent ) ) ) {
cp = cp.parentNode;
bg = jQuery( cp );
bgi = bg.css( 'backgroundImage' );
bg = bg.css( 'backgroundColor' );
}
HighlanderComments.currentParent.css( 'backgroundColor', bg );
}
var cancel = document.getElementById( 'cancel-comment-reply-link' ),
listOffsetSource = HighlanderComments.commentList,
listOffset,
parentOffset = HighlanderComments.currentParent.offset(),
currentParentMargins = HighlanderComments.currentParentMargins,
redoMargins = false,
grandWidth;
cp = HighlanderComments.currentParent;
while ( !cp.is( HighlanderComments.commentList ) && !cp.is( document ) ) {
if ( 'hidden' === cp.css( 'overflow' ) || 'hidden' === cp.css( 'overflow-x' ) ) {
listOffsetSource = cp;
break;
}
cp = cp.parent();
}
listOffset = listOffsetSource.offset();
HighlanderComments._unmoveForm = cancel.onclick;
cancel.onclick = function() { return HighlanderComments.unmoveForm.call( this ); };
if ( -1 < currentParentMargins.marginLeft.toString().indexOf( '%' ) ) {
grandWidth = HighlanderComments.currentParent.parent().width();
currentParentMargins.marginLeft = parseFloat( currentParentMargins.marginLeft ) / 100 * grandWidth;
redoMargins = true;
}
if ( -1 < currentParentMargins.marginRight.toString().indexOf( '%' ) ) {
grandWidth = HighlanderComments.currentParent.parent().width();
currentParentMargins.marginRight = parseFloat( currentParentMargins.marginRight ) / 100 * grandWidth;
redoMargins = true;
}
if ( redoMargins ) {
HighlanderComments.currentParent.css( currentParentMargins );
}
listOffset.right = listOffset.left + listOffsetSource.outerWidth();
parentOffset.left -= parseInt( HighlanderComments.currentParent.css( 'margin-left' ), 10 );
parentOffset.right = parentOffset.left + HighlanderComments.currentParent.outerWidth( true );
respond.hide();
HighlanderComments.currentParent.animate( {
marginLeft: '-=' + ( parentOffset.left - listOffset.left ).toString(),
marginRight: '-=' + ( listOffset.right - parentOffset.right ).toString()
}, 350, function() {
respond.slideDown( 350, function() {
jQuery( '#' + commId + ' .comment-reply-link:first' ).focus();
jQuery( '#comment' ).focus();
HighlanderComments.resizeCallback();
} );
respond.children('form').after('<div class="clear" id="threaded-clear"></div>');
} );
},
_unmoveForm: null,
unmoveForm: function() {
var r = HighlanderComments._unmoveForm.call( this );
if ( false !== r ) {
return r;
}
HighlanderComments.currentParent.stop( true, true ).animate( HighlanderComments.currentParentMargins, 350, function() {
HighlanderComments.currentParent.css( HighlanderComments.currentParentMargins );
HighlanderComments.currentParent = HighlanderComments.currentParentId = false;
} );
jQuery( '#respond' ).stop( true, true ).show();
jQuery( '#respond div#threaded-clear' ).remove();
HighlanderComments.resizeCallback();
return r;
},
HTMLToText : function( string ) {
return jQuery( '<span />' ).text( string ).html();
},
autosaveComment : function() {
var oneDay = new Date();
oneDay.setTime( oneDay.getTime() + 86400000 );
document.cookie = 'comment-' + HighlanderComments.postID + '=' + encodeURIComponent( jQuery( '#comment' ).val() ) + '; expires=' + oneDay.toGMTString() + '; path=/';
},
unsaveComment : function() {
var oneDay = new Date();
oneDay.setTime( oneDay.getTime() - 86400000 );
document.cookie = 'comment-' + HighlanderComments.postID + '= ; expires=' + oneDay.toGMTString() + '; path=/';
},
restoreComment : function() {
var parts = document.cookie.split( ';' ), part;
jQuery.each( parts, function(i) {
part = parts[i].split( '=' );
if ( 'comment-' + HighlanderComments.postID === jQuery.trim( part[0] ) ) {
if ( 'undefined' !== typeof part[1] && 'undefined' !== part[1] && '' !== decodeURIComponent( part[1] ) ) {
jQuery( '#comment' ).val( decodeURIComponent( part[1] ) );
}
return;
}
} );
},
switchAccount : function() {
jQuery( '.comment-form-service' ).removeClass( 'selected' ).hide();
jQuery( '#hc_post_as' ).val( 'guest' );
jQuery( '#comment-form-nascar > p' ).removeClass( 'error' );
if ( '1' == HighlanderComments.comment_registration ) {
jQuery( '#comment-form-nascar' ).show();
jQuery( '#comment-form-guest' ).hide(); // Guest commenting not allowed
HighlanderComments.resizeCallback();
} else {
jQuery( '#comment-form-nascar' ).show();
jQuery( '#comment-form-guest' ).slideDown( 'fast', HighlanderComments.resizeCallback );
HighlanderComments.clickGuestTab();
}
},
setConnectingToText : function( serviceFriendlyName ) {
jQuery( '#comment-form-load-service p' ).text( HighlanderComments.connectingToText.replace( '%s', serviceFriendlyName ) );
},
updateLoadServiceVisibility : function( tab ) {
jQuery( '.comment-form-service' )
.css( 'visibility', 'hidden' )
.show()
.removeClass( 'selected' )
.filter( tab )
.css( 'visibility', 'visible' )
.fadeIn( 'fast' )
.end()
.not( tab )
.hide()
.css( 'visibility', 'visible' );
},
clickService : function(e) {
e.preventDefault();
// HighlanderComments.autosaveComment();
var tab = this.href.replace( /^.*#/, '#' ).split( ':' );
if ( '#comment-form-load-service' === tab[0] && tab[1] ) {
HighlanderComments.setConnectingToText( tab[1] );
} else {
jQuery( '#hc_post_as' ).val( tab[0].split( '-' ).pop() );
}
HighlanderComments.updateLoadServiceVisibility( '#comment-form-load-service' );
jQuery( '#comment-form-nascar li.selected' ).removeClass( 'selected' );
jQuery( this ).parent().addClass( 'selected' );
HighlanderComments.resizeCallback();
},
clickGuestTab : function(e) {
if ( '1' == HighlanderComments.comment_registration ) {
jQuery( '#comment-form-guest' ).hide();
}
if ( jQuery( '#email' ).length && -1 < jQuery( '#email' ).val().indexOf( '@twitter.example.com' ) ) {
jQuery( '#email' ).val( '' ).blur();
}
HighlanderComments.updateAvatarWithGravatar( '#email' );
// Reenable subscription options
jQuery( '#comment-form-subscribe' ).css( 'opacity', '1' ).find( 'input' ).removeAttr( 'disabled' );
HighlanderComments.resizeCallback();
},
checkPostToWordPress: function(e) {
HighlanderComments.clickExternalTab( 'wordpress' );
jQuery( '#wordpress-login-first' ).show();
},
updateAvatarWithGravatar: function(e) {
var grav_base = ( 'https:' === location.protocol ? 'https://secure' : 'http://www' ) + '.gravatar.com/avatar/';
// When Avatars are disabled, Gravatar can be undefined, so we check against that first
// and fall back to an unknown gravatar if it isn't
var gravSource = grav_base + 'ad516503a11cd5ca435acc9bb6523536?s=25&forcedefault=1';
if ( 'undefined' !== typeof Gravatar && jQuery( e ).length ) {
gravSource = grav_base + Gravatar.md5( jQuery.trim( jQuery( e ).val().toLowerCase() ) ) + '?s=25';
}
if ( 'gravatar_default' !== HighlanderComments.gravDefault ) {
gravSource += '&d=' + encodeURIComponent( HighlanderComments.gravDefault );
}
jQuery( '#comment-form-guest .comment-form-avatar img' ).attr( 'src', gravSource );
},
getServiceData : function( service ) {
var data = HighlanderComments.readCookie( HighlanderComments.cookies[service] );
if ( null === data || 'undefined' === typeof data.access_token || !data.access_token ) {
return false;
}
return data;
},
ext_win : false,
ext_win_check : false,
pollExternalWindow : function( service, from_tab ) {
if ( !HighlanderComments.ext_win || HighlanderComments.ext_win.closed ) {
// If the cookie is available, then we must have auth'd successfully
if ( HighlanderComments.getServiceData( service ) ) {
HighlanderComments.doExternalLoggedIn( service );
return;
}
HighlanderComments.doExternalCanceled( service, from_tab );
HighlanderComments.ext_win = false;
clearInterval( HighlanderComments.ext_win_check );
}
},
cancelExternalWindow : function() {
if ( HighlanderComments.ext_win ) {
HighlanderComments.ext_win.close();
}
HighlanderComments.doExternalCanceled( jQuery( '#hc_post_as' ).val(), true );
},
clickExternalTab : function( e ) {
if ( 'undefined' == typeof e ) {
return;
}
jQuery( '#comment-form-guest' ).slideUp( 'fast', function() {
jQuery( '#comment-form-nascar' ).hide();
HighlanderComments.resizeCallback();
clearInterval( HighlanderComments.ext_win_check );
jQuery( '.highlander-tooltip' ).remove();
var from_tab = 1;
if ( 'string' == typeof e ) {
var service = e;
} else {
var service = e.currentTarget.id.split( '-' )[1];
if ( e.currentTarget.nodeName != 'A' ) {
from_tab = 0;
}
}
if (
// Found commenting cookies
null != HighlanderComments.readCookie( HighlanderComments.cookies[service] )
&&
(
// WordPress tab, and we're logged in
'wordpress' == service && HighlanderComments.userIsLoggedIn
||
// Not WordPress tab
'wordpress' != service
)
) {
if ( from_tab ) {
HighlanderComments.doExternalLoggedIn( service );
}
} else if ( 'googleplus' == service ) {
// Nothing to do - we're already logged in at this point
} else {
HighlanderComments.ext_win = window.open( HighlanderComments.connectURL + '&service=' + service, 'highconn', 'status=0,toolbar=0,location=1,menubar=0,directories=0,resizable=1,scrollbars=0' + HighlanderComments.popups[service] );
HighlanderComments.ext_win_check = setInterval( "HighlanderComments.pollExternalWindow( '" + service + "', " + from_tab + " )", 100 );
}
} );
},
doExternalLoggedIn : function( service ) {
clearInterval( HighlanderComments.ext_win_check );
var data = HighlanderComments.getServiceData( service );
if ( 'object' !== typeof data ) {
return;
}
if ( 'wordpress' == service ) {
// Allow subscription options
jQuery( '#comment-form-subscribe' ).css( 'opacity', '1' ).find( 'input' ).removeAttr( 'disabled' );
// Set up Gravatar and flag as logged in. Load a page to trigger cookies etc
jQuery( '#comment-form-' + service + ' .comment-form-avatar img' ).attr( 'src', data.avatar );
HighlanderComments.userIsLoggedIn = true;
if ( !HighlanderComments.isJetpack ) {
jQuery( 'body' ).append( '<iframe class="highlander-auth-init" height="1" width="1" style="display:none;" src="' + HighlanderComments.homeURL + 'highlander.login/" />' );
}
} else {
if ( 'twitter' == service ) {
// Disable subscription options for Twitter since we don't have an email
jQuery( '#comment-form-subscribe' ).css( 'opacity', '0.5' ).find( 'input' ).attr( 'disabled', 'disabled' ).removeAttr( 'checked' );
}
// Run all external avatars through ImgPress to resize them
jQuery( '#comment-form-' + service + ' .comment-form-avatar img' )
.attr( 'src', function() {
var split, host, path, query, url;
try {
if ( data.avatar.match( /^(https?:)?\/\/i[012]\.wp\.com\// ) ) {
return data.avatar.replace( /^https?:/, location.protocol );
}
if ( data.avatar.match( /^(https?:)?\/\/(.*?\.)gravatar\.com\// ) ) {
return data.avatar.replace( /^https?:/, location.protocol );
}
split = data.avatar.split( '#' ); // Ignore fragment
split = split[0].split( '?' );
query = split[1];
split = split[0].split( '//' ); // Ignore scheme
split = split[1].split( '/' );
host = split[0];
path = split.slice( 1 ).join( '/' );
url = location.protocol + '//i0.wp.com/' + host + '/' + path + '?';
if ( 'graph.facebook.com' === host && query.length ) {
url += 'q=' + encodeURIComponent( query ) + '&';
}
return url + 'resize=25%2C25';
} catch ( error ) {
return data.avatar;
}
} );
}
jQuery( '#email' ).val( data.email ).change();
jQuery( '#author' ).val( data.name ).change();
jQuery( '#url' ).val( data.link ).change().click();
jQuery( '#' + service + '-avatar' ).val( data.avatar );
jQuery( '#' + service + '-user_id' ).val( data.uid );
jQuery( '#' + service + '-access_token' ).val( data.access_token );
jQuery( '#hc_post_as' ).val( service );
// The child of the li.selected can be a <A> (WP, FB, Twitter) or an <IFRAME> (Google+)
var selectedLink = jQuery( '#comment-form-nascar li.selected a' );
if ( selectedLink.length && service == selectedLink.attr( 'id' ).replace( 'postas-', '' ) ) {
jQuery( '#comment-form-load-service' ).hide();
jQuery( '#comment-form-' + service ).show();
jQuery( '#comment-form-' + service + ' .comment-form-posting-as strong' ).text( data.name + ':' );
HighlanderComments.resizeCallback();
}
var selectedIFrame = jQuery( '#comment-form-nascar li.selected iframe' );
if ( selectedIFrame.length && service == "googleplus" ) {
jQuery( '#comment-form-load-service' ).hide();
jQuery( '#comment-form-' + service ).show();
jQuery( '#comment-form-' + service + ' .comment-form-posting-as strong' ).text( data.name + ':' );
HighlanderComments.resizeCallback();
}
},
doExternalCanceled : function( service, from_tab ) {
if ( from_tab ) {
var gravSource = ( 'https:' === location.protocol ? 'https://secure' : 'http://www' ) + '.gravatar.com/avatar/ad516503a11cd5ca435acc9bb6523536?s=25';
if ( 'gravatar_default' !== HighlanderComments.gravDefault ) {
gravSource += '&d=' + encodeURIComponent( HighlanderComments.gravDefault );
}
jQuery( '#comment-form-' + service + ' .comment-form-avatar img' ).attr( 'src', gravSource );
jQuery( '.comment-meta-' + service ).val( '' );