1(function ($) { 2 "use strict"; 3 4 var dummyTip = null; 5 var _config = null; 6 7 function getConfig() { 8 if (_config !== null) { 9 return _config; 10 } else if ($('#youtuber-cfg').length) { 11 _config = JSON.parse($('#youtuber-cfg').html()); 12 if (!_config || !_config['ajax_url']) { 13 console.log('No YouTubeR config'); 14 } 15 return _config; 16 } else { 17 console.log('No YouTubeR config'); 18 } 19 } 20 21 function getConfigValue(_name){ 22 var params = getConfig(); 23 return params[_name]; 24 } 25 26 function getLangString(key) { 27 var params = getConfig(); 28 return params.lang[key]; 29 } 30 31 function reBindScripts() { 32 if ($('a.mxyt-lightbox').length) { 33 $('a.mxyt-lightbox').fancybox(JSON.parse(getConfigValue('fancybox_params'))); 34 } 35 36 $('.mxyt-tip').each(function (index, element) { 37 var $this = $(this); 38 var mainContainer = $this.closest('.mxYouTubeR'); 39 var _class = ''; 40 if (mainContainer.attr('class')) { 41 var matches = mainContainer.attr('class').match(/(mxYouTubeR_theme_[a-z0-9\-_]+)/); 42 if (matches && matches.length > 0) { 43 _class = matches[0]; 44 } 45 } 46 $this.off('mouseenter'); 47 $this.on('mouseenter', function () { 48 if (!dummyTip.hasClass(_class)) { 49 dummyTip.addClass(_class); 50 } 51 dummyTip.children('span').html($this.attr('title')); 52 var pos = $this.offset(); 53 dummyTip.css('left', pos.left + $this.innerWidth() / 2 - dummyTip.width() / 2); 54 dummyTip.css('top', pos.top); 55 56 dummyTip.addClass('active'); 57 dummyTip.stop().css('opacity', 0).animate({ 58 'opacity': 0.9, 59 'margin-top': -25 60 }, 200, 'swing', function () { 61 //console.info(tip,this); 62 }); 63 }); 64 $this.off('mouseleave'); 65 $this.on('mouseleave', function () { 66 dummyTip.removeClass(_class); 67 dummyTip.removeClass('active'); 68 dummyTip.css('margin-top', -15); 69 }); 70 }); 71 72 $('.mxyt-text-description.mxyt-less').each(function (index, element) { 73 var $this = $(this); 74 if ($this.next().is('.mxyt-text-description-btn')) { 75 return; 76 } 77 var moreBtn = $('<div class="mxyt-text-description-btn">' + getLangString('more') + '</div>'); 78 var fullHeight = $this.children().height(); 79 if ($this.height() < fullHeight) { 80 $this.addClass('hasMore'); 81 moreBtn.insertAfter($this); 82 moreBtn.off('click'); 83 moreBtn.on('click', function () { 84 var btn = $(this); 85 if ($this.hasClass('mxyt-less')) { 86 $this.removeClass('mxyt-less'); 87 btn.html(getLangString('less')); 88 } else { 89 $this.addClass('mxyt-less'); 90 btn.html(getLangString('more')); 91 } 92 }); 93 } else { 94 $this.removeClass('hasMore'); 95 $this.addClass('noMore'); 96 } 97 }); 98 99 $('.mxyt-playlist-select span').off('click'); 100 $('.mxyt-playlist-select span').on('click', function () { 101 var $this = $(this); 102 playlistLoader.loadPlaylist($this.closest('.mxyt-channel-videos'), $this.attr('data-mxyt-cfg')); 103 return false; 104 }); 105 106 $('.mxyt-load-more').each(function (index, element) { 107 var $this = $(this); 108 if ($this.attr('data-checked')) { 109 return; 110 } 111 $this.attr('data-checked', 'true'); 112 if ($this.hasClass('mxyt-infinite-scroll')) { 113 $(window).on('scroll resize', function () { 114 playlistLoader.checkLoadMore($this); 115 }); 116 playlistLoader.checkLoadMore($this); 117 } else { 118 $this.off('click'); 119 $this.on('click', function () { 120 playlistLoader.loadMore($this); 121 return false; 122 }); 123 } 124 }); 125 $('.ch-item').on('mouseenter', function () { 126 $(this).addClass('mx-active'); 127 }); 128 $('.ch-item').on('mouseleave', function () { 129 $(this).removeClass('mx-active'); 130 }); 131 $('.mxYouTubeR').trigger('mxYouTubeRLayout'); 132 } 133 134 var playlistLoader = { 135 loading: false, 136 haveMore: false, 137 button: null, 138 loadingBar: null, 139 params: {}, 140 target: null, 141 142 bind: function (jqBtn) { 143 this.button = jqBtn; 144 this.haveMore = jqBtn.attr('data-mxyt-havemore')=='1'; 145 this.params = jqBtn.attr('data-mxyt-cfg'); 146 this.target = jqBtn.closest('.mxYouTubeR').find('.mxyt-playlist'); 147 }, 148 checkLoadMore: function(jqBtn){ 149 if (jqBtn.hasClass('mxyt-infinite-scroll')) { 150 var top = $(window).scrollTop() + $(window).height(); 151 if (top > jqBtn.offset().top) { 152 this.loadMore(jqBtn); 153 } 154 } 155 },
156 loadMore: function (jqBtn) { 157 if (this.loading) { 158 return false; 159 } 160 this.bind(jqBtn); 161 if (!this.haveMore) { 162 return false; 163 } 164 this.loading = true; 165 this.loadingBar = $('<i class="mxyt-icon mxyt-icon-spinner"></i>'); 166 this.button.hide(); 167 this.button.parent().append(this.loadingBar); 168 169 var loader = this; 170 $.ajax({ 171 url: getConfigValue('ajax_url'), 172 type: 'post', 173 dataType: "json", 174 data: { 175 action: 'youtuber', 176 params: loader.params, 177 }, 178 success: function (result) { 179 if (result && result.success) { 180 loader.loaded(result); 181 } 182 else if(result && result.error){ 183 alert(result.error); 184 } 185 else { 186 alert('mxYouTubeR ajax error.'); 187 } 188 }, 189 error: function () { 190 alert('mxYouTubeR ajax error.'); 191 } 192 }); 193 }, 194 loadPlaylist: function (_container, _params) { 195 if (this.loading) { 196 return false; 197 } 198 this.loading = true; 199 var loadingBar = $('<p align="center"><i class="mxyt-icon mxyt-icon-spinner"></i></p>'); 200 _container.html(loadingBar); 201 202 var loader = this; 203 $.ajax({
204 url: getConfigValue('ajax_url'), 205 type: 'post', 206 dataType: "json", 207 data: { 208 action: 'youtuber', 209 params: _params 210 }, 211 success: function (result) { 212 if (result.success) { 213 loader.loading = false; 214 loadingBar.remove(); 215 var items = $($(result.html).find('.mxyt-channel-videos').html()); 216 _container.append(items); 217 reBindScripts(); 218 items.css('opacity', 0); 219 items.stop().animate({ 220 'opacity': 1 221 }, 300); 222 } else { 223 alert('mxYouTubeR ajax error.'); 224 } 225 }, 226 error: function () { 227 alert('mxYouTubeR ajax error.'); 228 } 229 }); 230 }, 231 loaded: function (result) { 232 this.haveMore = result.haveMore; 233 this.loading = false; 234 this.loadingBar.remove(); 235 this.button.attr('data-mxyt-havemore', (this.haveMore?'1':'0')); 236 if (this.haveMore) { 237 this.button.show(); 238 } 239 var html = $(result.html); 240 var items = html.find('.mxyt-row, .mxyt-brow'); 241 this.params = this.params.replace(/\&start=\d+/,'&start='+html.find('.mxyt-load-more').attr('data-mxyt-start')); 242 this.button.attr('data-mxyt-cfg', this.params); 243 this.target.append(items); 244 reBindScripts(); 245 items.css('opacity', 0); 246 items.stop().animate({ 247 'opacity': 1 248 }, 300); 249 250 this.checkLoadMore(this.button); 251 } 252 }; 253 254 window.mxYouTuberInit = function () { 255 if (!dummyTip) { 256 dummyTip = $('<div id="mxyt-tooltip" class="mxyt-tooltip"><span></span><div></div></div>'); 257 $('body').append(dummyTip); 258 } 259 $('.mxYouTubeR').on('mxYouTubeRInit mxYouTubeRLayout',function(e){ 260 console.info(e); 261 }); 262 $('.mxYouTubeR').trigger('mxYouTubeRInit'); 263 reBindScripts(); 264 } 265 266 $(document).ready(function (e) { 267 $(".youtuber-widget").each(function(){ 268 var node = $(this); 269 node.html('<div class="mxyt-widget-loading"><i class="mxyt-icon mxyt-icon-spinner"></i></div>'); 270 $.ajax({
271 url: getConfigValue('ajax_url'), 272 type: 'get', 273 dataType: "html", 274 data: { 275 action: 'youtuber-widget', 276 id: node.attr("data-id"), 277 }, 278 success: function (result) { 279 node.html(result); 280 window.mxYouTuberInit(); 281 }, 282 error: function (jqXHR, textStatus, errorThrown) { 283 node.html('YouTubeR ajax error: '+errorThrown+'.'); 284 } 285 }); 286 }); 287 }); 288 289})(jQuery); 290
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.