PluginProbe
FV Player 8 / trunk
FV Player 8 vtrunk
trunk 8.0.18 8.0.19 8.0.20 8.0.21 8.0.25 8.0.27 8.1 8.1.3
fv-player / js / bunny_stream-browser.js

bunny_stream-browser.js in FV Player 8 trunk, at js/bunny_stream-browser.js

156 lines 5.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 jQuery( function($) {
2 var firstLoad = true;
3
4 function fv_player_bunny_stream_browser_load_assets(dropdown_val, link) {
5
6 var
7 $this = jQuery(this),
8 $media_frame_content = jQuery('.media-frame-content:visible'),
9 $overlay_div = jQuery('#fv-player-shortcode-editor-preview-spinner').clone().css({
10 'height' : '100%'
11 }),
12 page = 1,
13 ajax_data = {
14 action: "load_bunny_stream_jobs",
15 nonce: fv_player_bunny_stream_settings.nonce,
16 page: page
17 },
18 appending = false,
19 allLoaded = false;
20
21 if( link ) {
22 ajax_data['path'] = link;
23 }
24
25 if( window.fv_flowplayer_browser_get_function ) {
26 fv_flowplayer_browser_get_function[ 'fv_player_bunny_stream_browser_media_tab' ] = fv_player_bunny_stream_browser_load_assets;
27 }
28
29 $this.addClass('active').siblings().removeClass('active');
30
31 function loadMoreFunction(force) {
32 if ((!appending && !allLoaded) || force === true) {
33 appending = true;
34 // reset allLoaded if we're forcing a load after API error
35 if (force === true) {
36 allLoaded = false;
37 }
38 page++;
39 getBunnyStreamData();
40 }
41 return false;
42 }
43
44 function getBunnyStreamData() {
45 // check if we have search data to include
46 var searchVal = $('#media-search-input').val();
47
48 // show overlay if we're not appending, otherwise append the overlay and then remove it
49 $media_frame_content.html($overlay_div);
50
51 if (searchVal) {
52 ajax_data['search'] = searchVal;
53 } else {
54 delete(ajax_data['search']);
55 }
56
57 ajax_data['page'] = page;
58
59 ajax_data['appending'] = (appending ? 1 : 0);
60 ajax_data['firstLoad'] = (firstLoad ? 1 : 0);
61
62 jQuery.post(ajaxurl, ajax_data, function(ret) {
63 // don't overwrite the page if we've shown the browser for the first time already
64 // ... instead, we'll be either clearing and rewriting the UL or appending data to it
65 var renderOptions = {
66 searchMsg: "Search in current collection..."
67 };
68
69 // add errors, if any
70 if (ret.err) {
71 renderOptions['errorMsg'] = ret.err;
72 }
73
74 $media_frame_content.html( renderBrowserPlaceholderHTML(renderOptions) );
75
76 if (!appending && !allLoaded) {
77 // clear the UL if we're not appending
78 jQuery('#__assets_browser').find('li').remove();
79 }
80
81 // if our result didn't return any items, there's been an error
82 // and we don't need to bother with any display logic below
83 if (!ret.items.items) {
84 return;
85 }
86
87 var
88 $ul = jQuery('#__assets_browser'),
89 havePendingItems = false;
90
91 firstLoad = false;
92
93 // if we didn't get any items back and we're auto-loading data for infinite scroll,
94 // set allLoaded to true, so we don't try to load any more data
95 if (!ret.items.items.length && appending) {
96 jQuery('#overlay-loader-li').remove();
97
98 // if we got an error, re-add the Load More button
99 if (ret.err) {
100 fv_flowplayer_browser_add_load_more_button($ul, function() { loadMoreFunction(true); });
101 }
102
103 appending = false;
104 allLoaded = true;
105 return;
106 }
107
108 // remove temporary loading LI if we're not displaying the full browser for the first time
109 if (!firstLoad) {
110 jQuery('#overlay-loader-li').remove();
111 }
112
113 var args = {
114 breadcrumbs: 1,
115 action: 'add_bunny_stream_new_folder',
116 noFileName: true,
117 append: appending,
118 extraAttachmentClass: 'fullsize',
119 ajaxSearchCallback: function() {
120 allLoaded = false;
121 appending = false;
122 page = 1;
123 getBunnyStreamData();
124 },
125 loadMoreButtonAction: (ret.is_last_page ? false : loadMoreFunction)
126 }
127
128 // show add new collection button only in Home/ folder
129 if( typeof ajax_data['path'] == 'undefined' || ( ajax_data['path'] && ajax_data['path'] == 'Home/' ) ) {
130 args.add_new_folder = 1;
131 args.add_new_folder_text = 'Add new collection';
132 args.nonce_add_new_folder = fv_player_bunny_stream_upload_settings.nonce_add_new_folder;
133 }
134
135 fv_flowplayer_browser_browse(ret.items, args);
136
137 appending = false;
138 } );
139 }
140
141 getBunnyStreamData();
142 return false;
143 }
144
145 $( document ).on( "mediaBrowserOpen", function(event) {
146 var tabId = 'fv_player_bunny_stream_browser_media_tab';
147
148 // make sure we'll add .m3u8 files with the same name as our encoded file into the list of elements to lookup splash images in
149 if( window.fv_flowplayer_browser_splash_file_lookup_rules ) {
150 fv_flowplayer_browser_splash_file_lookup_rules[ tabId ] = { 'include' : ['\.(m3u8)$'] };
151 }
152 fv_flowplayer_media_browser_add_tab( tabId, 'Bunny Stream', fv_player_bunny_stream_browser_load_assets, null, function() {
153 firstLoad = true;
154 }).addClass('upload_supported');
155 });
156 });