-
Notifications
You must be signed in to change notification settings - Fork 123
/
Copy pathindex.js
3176 lines (2748 loc) · 101 KB
/
index.js
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
$(document).ready(function() {
// helper functions
var settings_buttons = '<div class="module_settings"><span>Settings</span></div><div class="module_remove"><span>Remove</span></div>';
// where all polls will reside
var timeOuts = new Array([]);
function construct_inactive_module(name, title) {
return '<div id="' + name + '_inactive" class="inactive_module" data-module="' + name + '">' + settings_buttons + '<h2>' + title + '</h2></div></div>';
}
function confirmation_dialog(customsettings) {
var settings = {
question: 'Are you sure?',
confirm: function() {},
cancel: function() {}
};
if (customsettings !== undefined) {
$.extend(settings, customsettings);
}
var dialog = '<div id="confirmation_dialog" class="dialog"><h3>' + settings.question + '</h3><div class="choices"><div class="confirm">Yes</div><div class="cancel">No</div></div></div>';
$('body').append(dialog);
$('#confirmation_dialog').showPopup({
dispose: true,
on_confirm: settings.confirm,
on_close: settings.cancel
});
}
function validate_form(form) {
var valid = true;
var required = $(form).find('.required');
required.each(function() {
var formrow = $(this).closest('.formrow');
if ($(this).val() === '') {
valid = false;
formrow.addClass('invalid');
} else {
formrow.removeClass('invalid');
}
});
return valid;
}
function popup_message(message) {
var popup = $('<div id="popup_message" class="dialog"><div class="close">x</div><p>' + message + '</p><div class="choices"><div class="cancel">OK</div></div></div>');
$('body').append(popup);
popup.showPopup({ dispose: true });
}
// get/poll module
function get_module(module, customsettings) {
var settings = {
poll: 0,
placeholder: $('.placeholder[data-module=' + module + ']'),
params: []
};
if (customsettings !== undefined) {
$.extend(settings, customsettings);
}
var url = WEBROOT + '/xhr/' + module;
for (var i=0; i < settings.params.length; i++) {
url += '/' + settings.params[i];
}
var module_ele = $('#' + module);
if (!module_ele.hasClass('edit_settings')) {
$.get(url, function(data) {
// if module is already on page
if (module_ele.length > 0) {
// if module has been returned by the XHR view
if ($(data).attr('id') === module) {
module_ele.replaceWith(data);
// else placeholder has been returned by the XHR view
} else {
module_ele.fadeOut(200, function() {
$(this).replaceWith(data);
});
}
// placeholder is on page
} else {
var new_module = $(data).hide();
settings.placeholder.replaceWith(new_module);
$('.module[data-module=' + module + ']').fadeIn(200);
}
});
}
// poll
if (settings.poll !== 0) {
var timer = module+'_timer';
if(timer){
clearTimeout(timeOuts[timer]);
timeOuts[timer] = setTimeout(function() {
get_module(module, {
poll: settings.poll,
params: [settings.params]
});
}, settings.poll * 1000);
}
}
}
// initialise modules on page load
function init_modules() {
$('.placeholder:not(.initialised)').each(function() {
$(this).addClass('initialised');
var delay = $(this).data('delay');
if (delay === undefined) {
get_module($(this).data('module'), {
poll: $(this).data('poll')
});
} else {
var module = $(this).data('module');
var poll = $(this).data('poll');
setTimeout(function() {
get_module(module, {
poll: poll
});
}, delay * 1000);
}
});
}
init_modules();
// currently playing
var currently_playing_id = null;
function get_currently_playing(visibility) {
$.get(WEBROOT + '/xhr/currently_playing', function(data) {
var module;
if (data.playing === false) {
// hide currently playing
$('#currently_playing').slideUp(200, function() {
$(this).remove();
});
// hide synopsis module if visible
$('#synopsis').fadeOut(200, function() {
$(this).replaceWith(construct_inactive_module('synopsis', 'Synopsis'));
});
currently_playing_id = null;
} else {
var currently_playing_module = $('#currently_playing');
if (currently_playing_module.length > 0) {
currently_playing_module.replaceWith(data);
} else {
module = $(data).hide();
$('body').append(module);
$('#currently_playing').slideDown(200);
}
if(visibility) {
$('#currently_playing').attr('class', visibility);
}
// use fanart of currently playing item as background if enabled in settings
if ($('body').data('fanart_backgrounds') === 'True') {
var fanart_url = $('#currently_playing').data('fanart');
if (fanart_url !== undefined) {
var img = new Image();
img.onload = function() {
var fanart = $('#fanart');
fanart.css('background-image', 'url(' + fanart_url + ')');
if (!fanart.is(':visible')) {
fanart.fadeIn(500);
}
};
img.src = fanart_url;
}
}
// synopsis
// if synopsis module is enabled
var synopsis_module = $('#synopsis, #synopsis_inactive');
if (synopsis_module.length > 0) {
// if currently playing item has a synopsis
var synopsis = $('#currently_playing .synopsis');
if (synopsis.length > 0) {
module = $('<div id="synopsis" class="module generic" data-module="synopsis">' + settings_buttons + '<h2></h2><div class="inner"><p></p></div></div>');
module.find('h2').replaceWith(synopsis.find('h2'));
module.find('p').replaceWith(synopsis.find('p'));
// if already visible
if (synopsis_module.hasClass('module')) {
synopsis_module.replaceWith(module);
// else if not visible
} else {
module.hide();
synopsis_module.replaceWith(module);
module.fadeIn(200);
}
// if no synopsis
} else {
// if visible
if (synopsis_module.hasClass('module')) {
synopsis_module.fadeOut(200, function() {
$(this).replaceWith(construct_inactive_module('synopsis', 'Synopsis'));
});
}
}
} // if synopsis module is enabled
// trakt
if ($('#trakt, #trakt_inactive').length > 0 && currently_playing_id !== $(data).data('id')) {
get_module('trakt', {
placeholder: $('#trakt_inactive')
});
}
currently_playing_id = $(data).data('id');
}
});
if (visibility) {
timeOuts['currently_playing'] = setTimeout(function() {
get_currently_playing(visibility);
}, 5000);
} else {
timeOuts['currently_playing'] = setTimeout(function() {
get_currently_playing();
}, 5000);
}
}
// Currently playing playlist
$(document).on('click', '#currently_playing .playlist', function() {
$.get(WEBROOT + '/xhr/currently_playing/playlist', function(data){
var popup = $(data);
$('body').append(popup);
popup.showPopup({dispose: true});
});
});
$(document).on('click', '#playlist_dialog .btn', function(e) {
e.stopPropagation();
});
$(document).on('click', '#playlist_dialog .control', function() {
$.get(WEBROOT + $(this).data('command'));
$.get(WEBROOT + '/xhr/currently_playing/playlist', function(data){
$('#playlist_dialog .close').click();
var popup = $(data);
$('body').append(popup);
popup.showPopup({dispose: true});
});
});
$(document).on('click', '#playlist_dialog .play', function() {
var playlistid = $(this).data('playlistid');
var position = $(this).data('position');
add_loading_gif(this);
$.get(WEBROOT + '/xhr/playlist/' + playlistid + '/play/' + position);
$.get(WEBROOT + '/xhr/currently_playing/playlist', function(data){
$('#playlist_dialog .close').click();
var popup = $(data);
$('body').append(popup);
popup.showPopup({dispose: true});
});
});
// Seek Function
$(document).on('click', '#currently_playing .progress', function(e){
var x = e.pageX - $(this).offset().left;
var percent = Math.round((x / $(this).width())*100);
var minimized = false;
if($('#currently_playing').hasClass('minimize')){
minimized = true;
}
$.get(WEBROOT + '/xhr/controls/seek_'+percent);
$.get(WEBROOT + '/xhr/currently_playing', function(data){
$('#currently_playing').replaceWith(data);
if(minimized){
$('#currently_playing').attr('class', 'minimize');
} else {
$('#currently_playing').attr('class', 'maximize');
}
});
});
$(document).on('mouseenter', '#currently_playing .progress', function(e){
var x = e.pageX - $(this).offset().left;
var percent = Math.round((x / $(this).width())*100);
var time = parseInt($(this).children('.total').data('seconds'), 10)*(percent/100);
time = (new Date()).clearTime().addSeconds(time).toString('H:mm:ss');
$(this).append('<div id="tooltip">' + percent + '</div>');
$(this).children('div#tooltip').css('margin-left', (percent-5)+'%');
});
$(document).on('mousemove', '#currently_playing .progress', function(e){
var x = e.pageX - $(this).offset().left;
var percent = Math.round((x / $(this).width())*100);
if(percent < 0 || percent > 100){return;}
var time = parseInt($(this).children('.total').data('seconds'), 10)*(percent/100);
time = (new Date()).clearTime().addSeconds(time).toString('H:mm:ss');
$(this).children('div#tooltip').html(time);
$(this).children('#tooltip').css('margin-left', (percent-5)+'%');
});
$(document).on('mouseleave', '#currently_playing .progress', function(e){
$(this).children('div#tooltip').remove();
});
// Volume Function
$(document).on('click', '#currently_playing .controls .volume', function(e){
var y = e.pageY - $(this).offset().top;
var percent = Math.round((y / $(this).height())*100);
if(percent < 0){percent = 0;}
if(percent > 100){percent = 100;}
$.get(WEBROOT + '/xhr/controls/volume_'+(100-percent));
$.get(WEBROOT + '/xhr/currently_playing', function(data){
$('#currently_playing').replaceWith(data);
});
});
$(document).on('mouseenter', '#currently_playing .controls .volume', function(e){
var y = e.pageY - $(this).offset().top;
var percent = Math.round((y / $(this).height())*100);
if(percent < 0){percent = 0;}
if(percent > 100){percent = 100;}
$(this).append('<div id="tooltip">' + (100-percent) + '%</div>');
$(this).children('div#tooltip').css('margin-top', (10*(percent-50))+'%');
});
$(document).on('mousemove', '#currently_playing .controls .volume', function(e){
var y = e.pageY - $(this).offset().top;
var percent = Math.round((y / $(this).height())*100);
if(percent < 0){percent = 0;}
if(percent > 100){percent = 100;}
$(this).children('div#tooltip').html((100-percent)+'%');
$(this).children('#tooltip').css('margin-top', (10*(percent-50))+'%');
});
$(document).on('mouseleave', '#currently_playing .volume', function(e){
$(this).children('div#tooltip').remove();
});
if ($('body').data('show_currently_playing') === 'True') {
get_currently_playing();
}
// currently_playing controls
$(document).on('click', '#currently_playing .controls > div', function() {
var command = $(this).data('command');
var minimized = false;
if($('#currently_playing').hasClass('minimize')){
minimized = true;
}
$.get(WEBROOT + '/xhr/controls/' + command);
$.get(WEBROOT + '/xhr/currently_playing', function(data) {
if (data.playing === false) {
$('#currently_playing').slideUp(200, function() {
$(this).remove();
});
} else {
$('#currently_playing').replaceWith(data);
}
if(minimized) {
$('#currently_playing').attr('class', 'minimize');
} else {
$('#currently_playing').attr('class', 'maximize');
}
});
});
$(document).on('click', '#currently_playing .controls .option > div', function() {
var command = $(this).attr('class');
$.get(WEBROOT + '/xhr/controls/' + command);
$.get(WEBROOT + '/xhr/currently_playing', function(data) {
$('#currently_playing').replaceWith(data);
});
});
// invoke XBMC library
$(document).on('click', '.invoke_library', function() {
invoke_library(WEBROOT + '/xhr/library' + $(this).data('path'));
});
function invoke_library(url) {
$.get(url, function(data) {
var library = $('#library');
if (library.length > 0) {
library.replaceWith(data);
} else {
$('#col1').append(data);
}
});
}
// currently playing close
$(document).on('click', '#currently_playing .visibility .close', function() {
$('#currently_playing').slideUp(200, function() {
$(this).remove();
clearTimeout(timeOuts['currently_playing']);
});
});
// currently playing minimize
$(document).on('click', '#currently_playing .visibility .minimize', function() {
if ($('#currently_playing').hasClass('minimize')) {
$('#currently_playing').attr('class', 'maximize');
} else {
$('#currently_playing').attr('class', 'minimize');
}
clearTimeout(timeOuts['currently_playing']);
if($('#currently_playing').hasClass('minimize')){
get_currently_playing('minimize');
} else {
get_currently_playing('maximize');
}
});
// Filter function
$(document).on('change keydown keyup search', '#library .filter', function(e){
var filter = $(this).val().toLowerCase();
$('#library .media').filter(function(index) {
return $(this).attr('filter').toLowerCase().indexOf(filter) < 0;
}).css('display', 'none');
$('#library .media').filter(function(index) {
return $(this).attr('filter').toLowerCase().indexOf(filter) >= 0;
}).css('display', '');
if(e.which == 13){
$('#library .media:visible:first').click();
}
});
$(document).on('click', '#library .filter', function(){
var filter = $(this).val();
if(filter === 'Filter'){
$(this).css('color', '#67C0F8').attr('value', '');
}
});
// update video library control
$(document).on('click', '#library #video-update', function() {
$.get(WEBROOT + '/xhr/controls/update_video');
});
// clean video library control
$(document).on('click', '#library #video-clean', function() {
$.get(WEBROOT + '/xhr/controls/clean_video');
});
// update music library control
$(document).on('click', '#library #audio-update', function() {
$.get(WEBROOT + '/xhr/controls/update_audio');
});
// clean music library control
$(document).on('click', '#library #audio-clean', function() {
$.get(WEBROOT + '/xhr/controls/clean_audio');
});
// xbmc poweron
$(document).on('click', '#library #poweron', function() {
$.get(WEBROOT + '/xhr/controls/poweron');
});
// xbmc poweroff
$(document).on('click', '#library #poweroff', function() {
$.get(WEBROOT + '/xhr/controls/poweroff');
});
// xbmc reboot
$(document).on('click', '#library #reboot', function() {
$.get(WEBROOT + '/xhr/controls/reboot');
});
// xbmc suspend
$(document).on('click', '#library #suspend', function() {
$.get(WEBROOT + '/xhr/controls/suspend');
});
// post trakt shout
$(document).on('click', '#add_shout .submit', function() {
var add_shout = $('#add_shout');
var spoiler = $('.spoiler_check');
var textarea = add_shout.find('textarea');
var submit_wrapper = add_shout.find('.submit_wrapper');
if (textarea.val().length === 0) {
var error_message = submit_wrapper.find('p');
if (error_message.length === 0) {
submit_wrapper.append('<p>');
error_message = submit_wrapper.find('p');
}
error_message.text('You need to enter a shout.');
return false;
}
var type = add_shout.data('type');
var dict = {
type: type,
itemid: add_shout.data('itemid'),
shout: textarea.val()
};
if (spoiler.is(':checked')) {
dict['spoiler'] = 'true';
}
else {
dict['spoiler'] = 'false';
}
if (type === 'episode') {
dict['season'] = add_shout.data('season');
dict['episode'] = add_shout.data('episode');
}
submit_wrapper.addClass('xhrloading');
$.post(WEBROOT + '/xhr/trakt/add_shout', dict, function(data) {
submit_wrapper.removeClass('xhrloading');
submit_wrapper.find('p').remove();
textarea.val('');
if (data.status === 'error') {
submit_wrapper.append('<p>There was a problem submitting your shout.</p>');
return false;
}
if ($(data).attr('id') === 'trakt') {
$('#trakt').replaceWith(data);
}
});
});
// view more recently added episodes
$(document).on('click', '#recently_added .view_older', function() {
get_module('recently_added', {
params: [$('#recently_added').data('episode_offset') + $('#recently_added .episodes > li').length]
});
return false;
});
$(document).on('click', '#recently_added .view_newer', function() {
var offset = $('#recently_added').data('episode_offset') - $('#recently_added .episodes > li').length;
if(offset<0){offset=0;}
get_module('recently_added', {
params: [offset]
});
return false;
});
// view more recently added movies
$(document).on('click', '#recently_added_movies .view_older', function() {
get_module('recently_added_movies', {
params: [$('#recently_added_movies').data('movie_offset') + $('#recently_added_movies .movies > li').length]
});
return false;
});
$(document).on('click', '#recently_added_movies .view_newer', function() {
var offset = $('#recently_added_movies').data('movie_offset') - $('#recently_added_movies .movies > li').length;
if(offset<0){offset=0;}
get_module('recently_added_movies', {
params: [offset]
});
return false;
});
// view more recently added albums
$(document).on('click', '#recently_added_albums .view_older', function() {
get_module('recently_added_albums', {
params: [$('#recently_added_albums').data('album_offset') + $('#recently_added_albums .albums > li').length]
});
return false;
});
$(document).on('click', '#recently_added_albums .view_newer', function() {
var offset = $('#recently_added_albums').data('album_offset') - $('#recently_added_albums .albums > li').length;
if(offset<0){offset=0;}
get_module('recently_added_albums', {
params: [offset]
});
return false;
});
// play recently added episodes when clicking on them
$(document).on('click', '#recently_added .play_episode', function() {
$.get(WEBROOT + '/xhr/play/video/episode/' + $(this).data('episodeid'));
});
// play recently added movies when clicking on them
$(document).on('click', '#recently_added_movies .play_movie', function() {
$.get(WEBROOT + '/xhr/play/video/movie/' + $(this).data('movieid'));
});
// play recently added albums when clicking on them
$(document).on('click', '#recently_added_albums .play_album', function() {
$.get(WEBROOT + '/xhr/play/audio/album/' + $(this).data('albumid'));
});
/*** XBMC LIBRARY ***/
// show xhrloading
function show_library_loading() {
$('#library .back').hide();
$('#library .xhrloading').show();
}
// hide xhrloading
function hide_library_loading() {
$('#library .xhrloading').hide();
$('#library .back').show();
}
// browse library
$(document).on('click', '#library .get', function() {
var url = $(this).data('url');
url = WEBROOT + '/xhr/library' + url;
show_library_loading();
$.get(url, function(data) {
$('#library').replaceWith(data);
var x = window.scrollX, y = window.scrollY;
$('#library #filter input').focus();
window.scrollTo(x, y);
});
});
// play button
$(document).on('click', '#library .play', function() {
show_library_loading();
$.get(WEBROOT + $(this).closest('.media').data('xhr_play'), function() {
hide_library_loading();
});
});
// queue button
$(document).on('click', '#library .queue', function() {
show_library_loading();
$.get(WEBROOT + $(this).closest('.media').data('xhr_queue'), function() {
hide_library_loading();
});
});
// play file button
$(document).on('click', '#library .play_file', function() {
var file = $(this).closest('.media').data('path');
show_library_loading();
$.post(WEBROOT + $(this).closest('.media').data('xhr_play'),{file: encodeURI(file)}, function(data){
hide_library_loading();
});
});
// queue file button
$(document).on('click', '#library .queue_file', function() {
var file = $(this).closest('.media').data('path');
show_library_loading();
$.post(WEBROOT + $(this).closest('.media').data('xhr_queue'),{file: encodeURI(file)}, function(data){
hide_library_loading();
});
});
// info button
$(document).on('click', '#library .info', function() {
show_library_loading();
$.get(WEBROOT + $(this).closest('.media').data('xhr_info'), function(data) {
$('#library').replaceWith(data);
});
});
// download button
$(document).on('click', '#library .download', function() {
$.get(WEBROOT + $(this).closest('.media').data('xhr_download'), function(data) {
var link = document.createElement('a');
link.href = data;
var fileName = data.substring(data.lastIndexOf('%2f') + 3, data.length);
fileName = decodeURI(fileName);
link.download = fileName;
var e = document.createEvent('MouseEvents');
e.initEvent('click', true, true);
link.dispatchEvent(e);
});
});
//Check for resume position when clicking video
$(document).on('click', '#library .resume_check', function() {
var xhr_play = $(this).closest('.media').data('xhr_play');
show_library_loading();
$.get(WEBROOT + $(this).closest('.media').data('xhr_resume_check'), function(data) {
hide_library_loading();
if (data.resume) {
var popup = $(data.template);
$('body').append(popup);
popup.showPopup({ dispose: true });
}
else {
$.get(WEBROOT+xhr_play);
}
});
});
// Play/Resume from dialog
$(document).on('click', '#resume_dialog .action', function() {
$.get(WEBROOT + $(this).data('url'), function() {
$('#resume_dialog .close').click();
});
});
// Play trailer
$(document).on('click', '#library .trailer', function() {
show_library_loading();
$.get(WEBROOT + $(this).closest('.media').data('xhr_trailer'), function() {
hide_library_loading();
});
});
// Resume
$(document).on('click', '#library .resume', function() {
show_library_loading();
$.get(WEBROOT + $(this).closest('.media').data('xhr_resume'), function() {
hide_library_loading();
});
});
// PVR scan
$(document).on('click', '#library #pvr-scan', function() {
show_library_loading();
$.get(WEBROOT + '/xhr/controls/pvr-scan', function(data){
hide_library_loading();
});
});
// control buttons
$(document).on('click', '#library .list_buttons .button, #library .banner_button, #library .poster_button', function(e) {
e.stopPropagation();
});
$(document).on('mouseenter', '#library ul.list_view li', function() {
$('.watched', this).hide();
$('.list_buttons .button', this).show();
});
$(document).on('mouseleave', '#library ul.list_view li', function() {
$('.list_buttons .button', this).hide();
$('.watched', this).show();
});
$(document).on('mouseenter', '#library .poster_view #poster', function() {
$('.poster_buttons', this).show();
});
$(document).on('mouseleave', '#library .poster_view #poster', function() {
$('.poster_buttons', this).hide();
});
// Save media settings
$(document).on('click', '#library #settings .choices .save', function() {
var settings = $('#library #settings').find('form').serializeArray();
var media = $('#library #content').data('media');
var url = $('#library #content').data('url');
url = WEBROOT + '/xhr/library' + url;
button = $(this);
show_library_loading();
$.post(
WEBROOT + '/xhr/library/save/'+media+'/',
{settings: JSON.stringify(settings)},
function(data) {
if (data.success) {
$.get(url, function(data) {
$('#library').replaceWith(data);
toggle_settings_mode();
});
}
else {
popup_message('Failed to save '+media+' settings');
hide_library_loading();
}
}
);
});
/*** SICKBEARD ***/
// Loading wheel on menu click
$(document).on('click', '#sickbeard .menu li', function() {
$(this).children().css('background', 'url('+WEBROOT+'/static/images/xhrloading.gif) no-repeat center').html(' ');
});
// Search Episode Functionality on Magnifying Glass png
$(document).on('click', '#sickbeard .coming_ep div.options img.search', function(){
$(this).attr('src', WEBROOT + '/static/images/xhrloading.gif');
var ep = $(this).attr('episode');
var season = $(this).attr('season');
var id = $(this).attr('id');
$.get(WEBROOT + '/xhr/sickbeard/search_ep/'+id+'/'+season+'/'+ep)
.success(function(data){
if(data.result === 'success'){
$('#sickbeard #'+id+'_'+season+'_'+ep+' div.options img.search').attr('src', WEBROOT + '/static/images/yes.png');
} else {
$('#sickbeard #'+id+'_'+season+'_'+ep+' div.options img.search').attr('src', WEBROOT + '/static/images/no.png');
}
})
.error(function(){
popup_message('Could not reach SickBeard.');
});
});
// Air time on hover
$(document).on('hover', '#sickbeard .coming_ep', function(){
var id = ($(this).attr('id'));
});
// Load show info from banner display
$(document).on('click', '#sickbeard .coming_ep .options img.banner', function(){
var tvdb = $(this).attr('id');
$.get(WEBROOT + '/xhr/sickbeard/get_show_info/'+tvdb, function(data){
$('#sickbeard').replaceWith(data);
});
});
// Plot display function
$(document).on('mouseenter', '#sickbeard .coming_ep .details .plot-title', function(){
$(this).toggle();
var id = $(this).closest('div.coming_ep').attr('id');
$('#sickbeard #'+id+' .details .plot').toggle();
});
// Plot hide function
$(document).on('mouseleave', '#sickbeard .coming_ep', function(){
var id = $(this).attr('id');
$('#sickbeard #'+id+' .details .plot-title').show();
$('#sickbeard #'+id+' .details .plot').hide();
});
// Toggle missed episodes
$(document).on('click', '#sickbeard #missed', function(){
$('#sickbeard .missed').toggle();
});
// All Shows menu
$(document).on('click', '#sickbeard .menu .all', function(){
$.get(WEBROOT + '/xhr/sickbeard/get_all', function(data){
$('#sickbeard').replaceWith(data);
});
});
// Coming episodes Menu
$(document).on('click', '#sickbeard .menu .upcoming', function(){
$.get(WEBROOT + '/xhr/sickbeard', function(data){
$('#sickbeard').replaceWith(data);
});
});
// History menu
$(document).on('click', '#sickbeard .menu .history', function(){
$.get(WEBROOT + '/xhr/sickbeard/history/30', function(data){
$('#sickbeard').html($(data).html());
$('#sickbeard .menu').prepend('<li class="snatched" title="View snatched"><span>Snatched</span></li>');
});
});
$(document).on('click', '#sickbeard .menu li.snatched', function(){
$('#sickbeard .history .Snatched').toggle();
$(this).toggleClass('active');
$(this).children().css('background', 'url('+WEBROOT+'/static/images/snatched.png) no-repeat center').html('Snatched');
});
// Show Menu
$(document).on( 'click', '#sickbeard .menu-icon', function(){
$('#sickbeard .menu').fadeToggle(200);
});
// Show info
$(document).on('click', '#sickbeard #sickbeard-list ul', function(){
var id = $(this).attr('id');
$.get(WEBROOT + '/xhr/sickbeard/get_show_info/'+id, function(data){
$('#sickbeard').replaceWith(data);
});
});
// Episode list back button functionality
$(document).on('click', '#sb_content > #show .sb-back', function(){
$.get(WEBROOT + '/xhr/sickbeard/get_all', function(data){
$('#sickbeard').replaceWith(data);
});
});
// Season info
$(document).on('click', '#sb_content > #show ul.seasons li', function(){
$.get(WEBROOT + '/xhr/sickbeard/get_season/'+$(this).attr('tvdbid')+'/'+$(this).attr('season'), function(data){
$('#sickbeard').replaceWith(data);
$('#sickbeard .episode-list .tablesorter').tablesorter({sortList: [[0,0]]});
});
});
// Going into episode info
$(document).on('click', '#sickbeard .episode-list #season tbody tr', function(){
$.get(WEBROOT + '/xhr/sickbeard/get_ep_info/'+$(this).attr('link'), function(data){
$('#sickbeard').replaceWith(data);
});
});
// Episode info back button functionality
$(document).on('click', '#sickbeard .episode-info div.back', function(){
$.get(WEBROOT + '/xhr/sickbeard/get_season/'+$(this).attr('tvdbid')+'/'+$(this).attr('season'), function(data){
$('#sickbeard').replaceWith(data);
$('#sickbeard .episode-list .tablesorter').tablesorter({sortList: [[0,0]]});
});
});
// Back Button Episode List
$(document).on('click', '#sickbeard .episode-list >.back', function(){
$.get(WEBROOT + '/xhr/sickbeard/get_show_info/'+$(this).attr('tvdbid'), function(data){
$('#sickbeard').replaceWith(data);
});
});
// Show Banner manager display
$(document).on('click', '#sickbeard #show .banner .options' , function(){
if($(this).hasClass('open')){ // closing
$('#sickbeard #show .banner').transition({ y: '0px' });
} else { // opening
$('#sickbeard #show .banner').transition({ y: '-40px' });
}
$(this).toggleClass('open');
});
// Delete show function
$(document).on('click', '#sickbeard #show .manage .delete' , function(){
var id = $('#sickbeard #show .manage').attr('tvdbid');
$.get(WEBROOT + '/xhr/sickbeard/delete_show/'+id)
.success(function(data){
popup_message(data);
})
.error(function(){
popup_message('Could not reach Sickbeard.');
});
});
// Refresh show function
$(document).on('click', '#sickbeard #show .manage .refresh' , function(){
var id = $('#sickbeard #show .manage').attr('tvdbid');
$.get(WEBROOT + '/xhr/sickbeard/refresh_show/'+id)
.success(function(data){
popup_message(data);
})
.error(function(){