forked from jakguru/Redmond-Inspired
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunctions.js
More file actions
812 lines (722 loc) · 21.8 KB
/
functions.js
File metadata and controls
812 lines (722 loc) · 21.8 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
var sounds = {
error: new Audio( redmond_terms.errorSound ),
open: new Audio( redmond_terms.openSound ),
login: new Audio( redmond_terms.loginSound ),
};
jQuery(function() {
startSystemClock();
handle_start_menu();
// --- Splash screen (10 seconds) with loading dots ---
var $splash = jQuery('#redmond-splash');
if ( $splash.length ) {
var splashDuration = 10000; // 10 seconds
var $dots = jQuery('#redmond-splash-dots');
var dotCount = 1;
// animate "Loading." -> ".." -> "..." -> "."
var dotsTimer = setInterval(function() {
if ( !$dots.length ) return;
dotCount = (dotCount % 3) + 1; // 1..3
$dots.text('.'.repeat(dotCount));
}, 400);
setTimeout(function() {
clearInterval(dotsTimer);
$splash.fadeOut(600, function() {
jQuery(this).remove();
});
}, splashDuration);
}
// Global link handler: only hijack desktop/start-menu links,
// never links inside already-open dialogs.
jQuery('a')
.off('click.redmondGlobal')
.on('click.redmondGlobal', function( e ) {
var $a = jQuery(this);
// If link is inside a dialog, let dialog logic handle it
if ( $a.closest('.ui-dialog').length ) {
return;
}
// If it's a custom close link, leave it alone
if ( $a.hasClass('redmond-close-window') ) {
return;
}
var id = $a.attr('id');
// Skip special start menu/system links (normal navigation)
if (
typeof id !== 'undefined' &&
(
id === 'home-start-menu-link' ||
id === 'new-post-start-menu-link' ||
id === 'control-panel-start-menu-link' ||
id === 'start-menu-bottom-bar-logout' ||
id === 'start-menu-bottom-bar-register' ||
id === 'start-menu-bottom-bar-login' ||
id === 'system-info-start-menu-link' ||
id === 'my-documents-start-menu-link' ||
id === 'my-tags-start-menu-link' ||
id === 'authors-start-menu-link' ||
id === 'system-search-start-menu-link'
)
) {
return;
}
// Everything else: open as Redmond window
e.preventDefault();
open_this_as_redmond_dialog(this);
});
jQuery(window).on('checkOpenWindows',function() {
checkOpenWindows();
});
jQuery('body').on('onContextMenu',function(e){
e.preventDefault();
return false;
});
if ( redmond_terms.playLoginSounds ) {
sounds.login.play();
}
for ( var process in processes ) {
if ( ! Object.prototype.hasOwnProperty.call(processes, process) ) {
continue;
}
if ( typeof processes[process].dialog === 'function' && processes[process].dialog('isOpen') ) {
processes[process].dialog('moveToTop');
find_window_on_top();
break;
}
}
if ( typeof redmond_adjust_dialog_sizes === 'function' ) {
redmond_adjust_dialog_sizes();
}
});
// Generic close handler for elements with .redmond-close-window
jQuery(document).on('click', '.redmond-close-window', function ( e ) {
e.preventDefault();
e.stopPropagation();
var $dialog = jQuery(this).closest('.ui-dialog');
if ( $dialog.length ) {
var $content = $dialog.find('.ui-dialog-content');
if ( $content.length && typeof $content.dialog === 'function' ) {
$content.dialog('close');
}
else {
$dialog.hide();
}
}
});
// Force the jQuery UI titlebar "X" to actually close the window
jQuery(document).on('click', '.ui-dialog-titlebar-close', function ( e ) {
e.preventDefault();
e.stopPropagation();
// Prefer the theme's own close logic if it exists
if ( typeof redmond_close_this === 'function' ) {
redmond_close_this(this);
return;
}
// Fallback: try to close the jQuery UI dialog directly
var $dialog = jQuery(this).closest('.ui-dialog');
var $content = $dialog.find('.ui-dialog-content');
if ( $content.length && typeof $content.dialog === 'function' ) {
$content.dialog('close');
} else if ( $dialog.length ) {
$dialog.remove();
}
});
// Resize handler: keep dialog content height limited to viewport
// and always scrollable when needed.
jQuery(window)
.off('resize.redmond')
.on('resize.redmond', function () {
var maxHeight = jQuery(window).height() * 0.9;
jQuery('.ui-dialog-content').each(function () {
jQuery(this).css({
'max-height': maxHeight,
'overflow-y': 'auto',
'overflow-x': 'auto',
});
});
if ( typeof redmond_adjust_dialog_sizes === 'function' ) {
redmond_adjust_dialog_sizes();
}
})
.trigger('resize.redmond');
function checkOpenWindows() {
var processList = '';
for ( var process in processes ) {
if ( ! Object.prototype.hasOwnProperty.call(processes, process) ) {
continue;
}
if ( typeof processes[process].dialog !== 'function' || ! processes[process].dialog('isOpen') ) {
continue;
}
if ( parseInt(processes[process].parent().css('top'),10) >= 0 ) {
processes[process].currentTop = parseInt(processes[process].parent().css('top'),10);
}
else {
processes[process].parent().css('top',processes[process].currentTop);
}
processList += '<li onclick="processes[\'' +process+ '\'].dialog(\'moveToTop\')" id="' +process+ '_taskbar">';
processList += '<span class="task-icon"';
processList += ' style="' + processes[process].parent().find('.ui-dialog-title').attr('style') + '"';
processList += '></span>';
processList += processes[process].parent().find('.ui-dialog-title').html().substring(0,20) + '</li>' + "\r\n";
}
jQuery("#open-processes").html( processList );
jQuery("#open-processes>li").on('click',function() {
find_window_on_top();
});
find_window_on_top();
}
function find_window_on_top() {
var top;
var hightestZ = -Infinity;
for ( var process in processes ) {
if ( ! Object.prototype.hasOwnProperty.call(processes, process) ) {
continue;
}
if ( typeof processes[process].dialog !== 'function' || ! processes[process].dialog('isOpen') ) {
continue;
}
if ( processes[process].zIndex() > hightestZ ) {
top = process;
hightestZ = processes[process].zIndex();
}
var currTop = processes[process].parent().offset().top;
if ( currTop < 0 ) {
processes[process].parent().offset({top: 100, left: processes[process].parent().offset().left});
}
}
jQuery("#open-processes>li").removeClass('active');
if ( typeof top === 'undefined' ) {
return;
}
var taskbar = jQuery("#" + top + '_taskbar');
taskbar.addClass('active');
}
function startSystemClock() {
jQuery("#taskbar-clock").html( currentTime() );
setInterval( function() {
jQuery("#taskbar-clock").html( currentTime() );
},1000);
}
function currentTime() {
var d = new Date();
return d.toLocaleTimeString();
}
function handle_start_menu() {
jQuery("#start-button").on('click',function() {
toggle_activated(jQuery(this).parent());
jQuery('#start-menu-wrapper').toggle();
});
jQuery("#start-menu-wrapper a").on('click',function() {
if ( jQuery(this).is(':visible') ) {
jQuery('#start-menu-wrapper').toggle();
toggle_activated( jQuery("#start-button").parent() );
}
});
jQuery("#start-menu-archives-link").on('mouseover',function() {
jQuery("#start-menu-archives-link>div.archives-outer-wrapper").show();
});
jQuery("#start-menu-archives-link").on('mouseout',function() {
jQuery("#start-menu-archives-link>div.archives-outer-wrapper").hide();
});
jQuery("ul.archives-inner-wrapper>li").on('mouseover',function() {
var obj = this;
jQuery(this).find('div.archives-outer-wrapper').show();
var newtop = 0;
jQuery(this).prevAll().each(function() {
if ( jQuery(this).hasClass('seperator') ) {
newtop = newtop + 2;
}
else {
newtop = newtop + 22;
}
});
jQuery(this).find('div.archives-outer-wrapper').each(function() {
jQuery(this).css({
bottom: 'auto',
height: function() {
return parseInt( 22 * jQuery(obj).find('li').length ,10);
},
top: newtop,
});
});
});
jQuery("ul.archives-inner-wrapper>li").on('mouseout',function() {
jQuery(this).find('div.archives-outer-wrapper').hide();
});
jQuery("#my-documents-start-menu-link").on('click',function(e){
e.preventDefault();
open_archive_as_dialog();
});
jQuery("#my-tags-start-menu-link").on('click',function(e){
e.preventDefault();
open_archive_as_dialog('all','tags');
});
jQuery("#system-search-start-menu-link").on('click',function(e){
e.preventDefault();
open_redmond_search_window();
});
jQuery("#authors-start-menu-link").on('click',function(e){
e.preventDefault();
open_redmond_authors_window();
});
}
function toggle_activated( obj ) {
if ( jQuery(obj).hasClass('activated') ) {
jQuery(obj).removeClass('activated');
}
else {
jQuery(obj).addClass('activated');
}
}
function open_this_as_redmond_dialog( obj ) {
var type = ( typeof( jQuery(obj).attr('data-post-id') ) !== 'undefined' ) ? 'inline' : 'iframe';
if ( type == 'inline' ) {
open_post_as_dialog( parseInt( jQuery(obj).attr('data-post-id') , 10 ) );
}
else {
var html = '<iframe src="' + jQuery(obj).attr('href') + '"></iframe>';
var process = new Date().getTime();
redmond_window( process , jQuery(obj).attr('title') , html , false , true , true , redmond_terms.externalPageIcon );
processes[process].css({
'overflow-y': 'auto',
'overflow-x': 'auto',
});
}
}
function open_category_as_redmond_dialog( obj ) {
var o = jQuery(obj);
open_archive_as_dialog( o.attr('data-category-id') , o.attr('data-type') );
}
function open_post_as_dialog( postId ) {
jQuery.ajax({
url: redmond_terms.ajaxurl,
data: {
action: 'getpost',
post: postId,
nonce: redmond_terms.nonce,
},
async: true,
beforeSend: function() {},
cache: false,
crossDomain: false,
dataType: 'json',
error: function( jqXHR ) {
redmondHandleAjaxError( jqXHR );
},
method: 'POST',
success: function( returned ) {
var data = redmondParseAjaxResponse( returned );
if ( false === data ) {
redmondHandleAjaxError();
return;
}
redmond_window( data.task_name , data.post_title , data.post_content , data.fileMenu , true, true , data.post_icon );
processes[data.task_name].find('article').css({
padding: 10,
});
redmondEnsureDialogScroll( processes[data.task_name] );
sounds.open.play();
}
});
}
function open_archive_as_dialog( archive , taxonomy , targetId ) {
if ( typeof( taxonomy ) == 'undefined' ) {
taxonomy = 'category';
}
if ( typeof( archive ) == 'undefined' ) {
archive = 'all';
}
jQuery.ajax({
url: redmond_terms.ajaxurl,
data: {
action: 'getarchive',
taxonomy: taxonomy,
archive: archive,
nonce: redmond_terms.nonce,
},
async: true,
beforeSend: function() {},
cache: false,
crossDomain: false,
dataType: 'json',
error: function( jqXHR ) {
redmondHandleAjaxError( jqXHR );
},
method: 'POST',
success: function( returned ) {
var data = redmondParseAjaxResponse( returned );
if ( false === data ) {
redmondHandleAjaxError();
return;
}
if ( typeof( targetId ) !== 'undefined' && jQuery("#" + targetId ).length > 0 ) {
jQuery("#"+targetId).dialog('close');
}
redmond_window( data.taskname , data.title , data.html , data.menu , true, true , data.icon );
if ( processes[data.taskname] ) {
redmondEnsureDialogScroll( processes[data.taskname] );
}
jQuery("#" + data.taskname).find('a').on('click',function(e) {
if ( typeof( jQuery(this).attr('id') ) === 'undefined' && typeof( jQuery(this).attr('data-type') ) !== 'undefined' ) {
e.preventDefault();
switch ( jQuery(this).attr('data-type') ) {
case 'regular':
open_this_as_redmond_dialog(this);
break;
default:
open_category_as_redmond_dialog(this);
break;
}
}
});
sounds.open.play();
}
});
}
function open_redmond_authors_window( author, targetId ) {
if ( typeof( author ) == 'undefined' ) {
author = 'all';
}
jQuery.ajax({
url: redmond_terms.ajaxurl,
data: {
action: 'getauthor',
author: author,
nonce: redmond_terms.nonce,
},
async: true,
beforeSend: function() {},
cache: false,
crossDomain: false,
dataType: 'json',
error: function( jqXHR ) {
redmondHandleAjaxError( jqXHR );
},
method: 'POST',
success: function( returned ) {
var data = redmondParseAjaxResponse( returned );
if ( false === data ) {
redmondHandleAjaxError();
return;
}
if ( typeof( targetId ) !== 'undefined' && jQuery("#" + targetId ).length > 0 ) {
jQuery("#"+targetId).dialog('close');
}
redmond_window( data.taskname , data.title , data.html , data.menu , true, true , data.icon );
if ( processes[data.taskname] ) {
redmondEnsureDialogScroll( processes[data.taskname] );
}
jQuery("#" + data.taskname).find('a').on('click',function(e) {
if ( typeof( jQuery(this).attr('id') ) === 'undefined' && typeof( jQuery(this).attr('data-type') ) !== 'undefined' ) {
e.preventDefault();
switch ( jQuery(this).attr('data-type') ) {
case 'regular':
open_this_as_redmond_dialog(this);
break;
default:
open_redmond_authors_window( jQuery(this).attr('data-author-id') );
break;
}
}
});
sounds.open.play();
}
});
}
function open_redmond_search_window( search ) {
var windowTitle;
if ( typeof(search) == 'undefined' || search.length == 0 ) {
windowTitle = redmond_terms.search;
}
else {
windowTitle = redmond_terms.search_for + search;
}
jQuery.ajax({
url: redmond_terms.ajaxurl,
data: {
action: 'getsearch',
search:search,
nonce: redmond_terms.nonce,
},
async: true,
beforeSend: function() {},
cache: false,
crossDomain: false,
dataType: 'json',
error: function( jqXHR ) {
redmondHandleAjaxError( jqXHR );
},
method: 'POST',
success: function( returned ) {
var data = redmondParseAjaxResponse( returned );
if ( false === data ) {
redmondHandleAjaxError();
return;
}
redmond_window( 'searchwindow' , windowTitle , data.html , redmond_terms.default_file_menu , false , true , redmond_terms.searchIcon );
if ( processes.searchwindow ) {
redmondEnsureDialogScroll( processes.searchwindow );
}
jQuery("#searchwindow").find('button').on('click',function(e) {
e.preventDefault();
open_redmond_search_window( jQuery('#searchwindow').find('input').val() );
});
jQuery("#searchwindow").find('input').on('keyup',function(e){
if ( e.keyCode == 13 ) {
open_redmond_search_window( jQuery('#searchwindow').find('input').val() );
}
});
jQuery("#searchwindow").find('a').on('click',function(e) {
if ( typeof( jQuery(this).attr('id') ) === 'undefined' && typeof( jQuery(this).attr('data-type') ) !== 'undefined' ) {
e.preventDefault();
switch ( jQuery(this).attr('data-type') ) {
case 'regular':
open_this_as_redmond_dialog(this);
break;
default:
open_category_as_redmond_dialog(this);
break;
}
}
});
sounds.open.play();
}
});
}
function redmondHandleAjaxError( jqXHR ) {
var message = redmond_terms.ajaxerror;
if ( jqXHR && jqXHR.responseJSON && jqXHR.responseJSON.data ) {
if ( typeof jqXHR.responseJSON.data === 'string' && jqXHR.responseJSON.data.length > 0 ) {
message = jqXHR.responseJSON.data;
} else if ( jqXHR.responseJSON.data.message ) {
message = jqXHR.responseJSON.data.message;
}
}
do_redmond_error_window( message );
console.log( 'AJAX Error', jqXHR );
}
function redmondParseAjaxResponse( returned ) {
if ( ! returned || typeof returned.success === 'undefined' ) {
return false;
}
if ( true !== returned.success || typeof returned.data === 'undefined' ) {
return false;
}
return returned.data;
}
function redmondOpenAjaxDialog( processId, data, fallbackTitle ) {
var dialogTitle = ( data && data.title ) ? data.title : fallbackTitle;
var dialogHtml = ( data && data.html ) ? data.html : '';
var dialogMenu = ( data && data.menu ) ? data.menu : null;
var dialogIcon = ( data && data.icon ) ? data.icon : redmond_terms.windowIcon;
var canResize = ( data && typeof data.resizable === 'boolean' ) ? data.resizable : false;
var draggable = ( data && typeof data.draggable === 'boolean' ) ? data.draggable : true;
var limitHeight = ( data && typeof data.limitHeight === 'boolean' ) ? data.limitHeight : true;
redmond_window( processId, dialogTitle, dialogHtml, dialogMenu, canResize, draggable, dialogIcon, limitHeight );
if ( ! processes[processId] || ! processes[processId].length ) {
return null;
}
return processes[processId];
}
// Make dialog content scrollable + limit height
function redmondEnsureDialogScroll( dialogContent ) {
if ( ! dialogContent || ! dialogContent.length ) {
return;
}
var maxHeight = jQuery(window).height() * 0.9;
// Try to target the real .ui-dialog-content
var content = dialogContent.hasClass('ui-dialog-content')
? dialogContent
: dialogContent.closest('.ui-dialog').find('.ui-dialog-content').first();
if ( ! content.length ) {
content = dialogContent;
}
content.css({
'overflow-y': 'auto',
'overflow-x': 'auto',
'max-height': maxHeight,
});
if ( typeof redmond_adjust_dialog_sizes === 'function' ) {
redmond_adjust_dialog_sizes();
}
}
function redmondCopyToClipboard( text ) {
if ( navigator.clipboard && typeof navigator.clipboard.writeText === 'function' ) {
return navigator.clipboard.writeText( text );
}
return new Promise(function( resolve, reject ) {
var $buffer = jQuery('<textarea class="redmond-copy-buffer" aria-hidden="true"></textarea>');
$buffer.val( text ).css({
position: 'fixed',
top: '-1000px',
left: '-1000px',
opacity: 0,
width: '1px',
height: '1px',
});
jQuery('body').append( $buffer );
var node = $buffer.get(0);
try {
node.focus();
node.select();
if ( typeof node.setSelectionRange === 'function' ) {
node.setSelectionRange( 0, node.value.length );
}
var successful = document.execCommand( 'copy' );
$buffer.remove();
if ( successful ) {
resolve();
}
else {
reject();
}
}
catch ( err ) {
$buffer.remove();
reject( err );
}
});
}
function redmondShareFeedback( dialogContent, message, isError ) {
if ( ! dialogContent || ! dialogContent.length || ! message ) {
return;
}
var feedback = dialogContent.find('.redmond-share-feedback');
if ( ! feedback.length ) {
return;
}
feedback.stop( true, true );
feedback.text( message );
feedback.removeClass( 'is-error is-success is-visible' );
feedback.addClass( isError ? 'is-error' : 'is-success' );
feedback.addClass( 'is-visible' );
var previousTimer = feedback.data( 'redmondFeedbackTimer' );
if ( previousTimer ) {
clearTimeout( previousTimer );
}
var timer = setTimeout( function() {
feedback.removeClass( 'is-visible is-error is-success' );
feedback.text( '' );
}, 2400 );
feedback.data( 'redmondFeedbackTimer', timer );
}
function do_redmond_error_window( message ) {
var contents = '';
contents += '<p>' + message +'</p>' + "\r\n";
// Button that uses our JS close handler instead of inline onclick
contents += '<span class="button-outer dialog-close-button">' +
'<button class="system-button redmond-close-window" type="button">' +
redmond_terms.closetext +
'</button></span>' + "\r\n";
redmond_window('error', redmond_terms.errTitle, contents, null, false, true, redmond_terms.errorIcon);
processes.error.css({
// no overflow-y: hidden here, we want scrollable content
background: '#1f2937',
'background-color': '#1f2937',
padding: 10,
'max-width': 700,
});
processes.error.find('div.file-bar').css({
display:'none',
});
redmondEnsureDialogScroll( processes.error );
sounds.error.play();
}
function redmond_comment_field( postid ) {
jQuery.ajax({
url: redmond_terms.ajaxurl,
method: 'POST',
dataType: 'json',
data: {
action: 'redmond_get_comment_form',
nonce: redmond_terms.nonce,
postId: postid,
},
success: function( returned ) {
var data = redmondParseAjaxResponse( returned );
if ( false === data ) {
redmondHandleAjaxError();
return;
}
var processId = 'comment_for_' + postid;
var dialogContent = redmondOpenAjaxDialog( processId, data, 'Comment' );
if ( ! dialogContent ) {
return;
}
var wrapper = dialogContent.closest('.ui-dialog');
if ( wrapper.length ) {
wrapper.addClass('redmond-comment-window');
}
redmondEnsureDialogScroll( dialogContent );
var commentField = dialogContent.find('#comment');
if ( commentField.length ) {
commentField.trigger('focus');
}
sounds.open.play();
},
error: function( jqXHR ) {
redmondHandleAjaxError( jqXHR );
}
});
}
function redmond_share_post( postid ) {
jQuery.ajax({
url: redmond_terms.ajaxurl,
method: 'POST',
dataType: 'json',
data: {
action: 'redmond_get_share_data',
nonce: redmond_terms.nonce,
postId: postid,
},
success: function( returned ) {
var data = redmondParseAjaxResponse( returned );
if ( false === data ) {
redmondHandleAjaxError();
return;
}
var processId = 'share_post_' + postid;
var dialogContent = redmondOpenAjaxDialog( processId, data, 'Share' );
if ( ! dialogContent ) {
return;
}
var wrapper = dialogContent.closest('.ui-dialog');
if ( wrapper.length ) {
wrapper.addClass('redmond-share-window');
}
redmondEnsureDialogScroll( dialogContent );
dialogContent
.off('click.redmondShareCopy')
.on('click.redmondShareCopy', '.redmond-copy-link', function( event ) {
event.preventDefault();
var button = jQuery( this );
var targetId = button.data( 'copyTarget' );
if ( ! targetId ) {
return;
}
var target = dialogContent.find( '#' + targetId );
if ( ! target.length ) {
return;
}
redmondCopyToClipboard( target.val() )
.then( function() {
redmondShareFeedback( dialogContent, button.data( 'successMessage' ), false );
} )
.catch( function() {
if ( target.length && target[0] && typeof target[0].select === 'function' ) {
target.trigger('focus');
target[0].select();
if ( typeof target[0].setSelectionRange === 'function' ) {
target[0].setSelectionRange( 0, target.val().length );
}
}
redmondShareFeedback( dialogContent, button.data( 'errorMessage' ), true );
} );
});
sounds.open.play();
},
error: function( jqXHR ) {
redmondHandleAjaxError( jqXHR );
}
});
}