1(function ($, window, undefined) { 2 'use strict'; 3 4 var hideItemClass = 'edn__contentBlock_hide', 5 activeItemClass = 'edn__contentBlock_active', 6 itemsHiddenClass = 'edn__contentBlock_itemsHidden', 7 pageReadyClass = 'edn__contentBlock_pageReady', 8 loadingClass = 'edn__contentBlock_loading', 9 noContentClass = 'edn__contentBlock_noContent', 10 contentErrorClass = 'edn__contentBlock_contentError', 11 disablePreviousPageClass = 'edn__contentBlock_disablePreviousPage', 12 disableNextPageClass = 'edn__contentBlock_disableNextPage', 13 triggeredPreviousPageClass = 'edn__contentBlock_triggeredPreviousPage', 14 triggeredNextPageClass = 'edn__contentBlock_triggeredNextPage', 15 16 masonryInit = function () { 17 var self = this; 18 19 if (self.options.masonry) 20 self.$contentWrapper 21 .isotope({ 22 sortBy: 'original-order', 23 masonry: { 24 isFitWidth: true 25 } 26 }) 27 .find('img').imagesLoaded() 28 .progress(function () { 29 self.$contentWrapper.isotope('layout'); 30 }); 31 }, 32 33 postShow = function () { 34 var self = this; 35 36 if (self.verticalLayout) 37 self.resize(); 38 }, 39 40 showPage = function (contentKey, page) { 41 var self = this, 42 $activeItem = $('>', self.$visibleItemList).eq(self.activeItemIndex); 43 44 if ($activeItem.length > 0 && $activeItem.data('meta').contentKey != contentKey) 45 return; 46 47 var itemCache = self.itemCache[contentKey], 48 pageCache = itemCache.pages[page + '']; 49 50 if (itemCache.activePage != page) 51 return; 52 53 self.$moduleWrapper 54 .removeClass(pageReadyClass) 55 .removeClass(loadingClass) 56 .removeClass(noContentClass) 57 .removeClass(contentErrorClass) 58 .removeClass(disablePreviousPageClass) 59 .removeClass(disableNextPageClass); 60 61 clearTimeout(self.pageReadyTimeout); 62 63 self.pageReadyTimeout = setTimeout(function () { 64 self.$moduleWrapper.addClass(pageReadyClass); 65 }, 100); 66 67 if (itemCache.totalItemCount == 0) { 68 self.$moduleWrapper.addClass(noContentClass); 69 postShow.call(self); 70 return; 71 } 72 73 if (itemCache.totalItemCount == -1 || (!pageCache.loaded && pageCache.requestError)) { 74 self.$moduleWrapper.addClass(contentErrorClass); 75 postShow.call(self); 76 return; 77 } 78 79 if (pageCache.loaded) { 80 if (page == 1) 81 self.$moduleWrapper.addClass(disablePreviousPageClass); 82 83 if (Math.ceil(itemCache.totalItemCount / self.options.itemsPerPage) <= page) 84 self.$moduleWrapper.addClass(disableNextPageClass); 85 86 if (self.$contentWrapper.hasClass('edn_WrapperFirst')) 87 self.$contentWrapper.html(pageCache.content); 88 else 89 self.$contentWrapper.replaceWith(pageCache.content); 90 91 self.$contentWrapper = $('.edn__articleListWrapper', self.$moduleWrapper); 92 masonryInit.call(self); 93 94 postShow.call(self); 95 } 96 }, 97 98 requestPage = function (contentKey, page) { 99 var self = this, 100 itemCache = self.itemCache[contentKey], 101 pageCache; 102 103 if (!itemCache) { 104 itemCache = { 105 pages: {}, 106 totalItemCount: -1, 107 activePage: -1 108 }; 109 110 self.itemCache[contentKey] = itemCache; 111 } 112 113 if (page < 1) 114 page = 1; 115 116 if (itemCache.totalItemCount != -1) { 117 var numOfPages = Math.ceil(itemCache.totalItemCount / self.options.itemsPerPage); 118 119 if (page > numOfPages) 120 page = numOfPages; 121 } 122 123 itemCache.activePage = page; 124 125 if (itemCache.totalItemCount == 0) { 126 showPage.call(self, contentKey, page); 127 return; 128 } 129 130 var pageKey = page + '' 131 132 pageCache = itemCache.pages[pageKey]; 133 134 if (pageCache) { 135 if (pageCache.loaded) { 136 showPage.call(self, contentKey, page); 137 return; 138 } 139 140 if (pageCache.requesting) { 141 self.$moduleWrapper.addClass(loadingClass); 142 return; 143 } 144 } else { 145 itemCache.pages[pageKey] = pageCache = { 146 content: '', 147 loaded: false, 148 requesting: true, 149 requestError: false 150 }; 151 } 152 153 if (itemCache.totalItemCount == -1) { 154 self.$moduleWrapper.addClass(disablePreviousPageClass + ' ' + disableNextPageClass); 155 } 156 157 self.$moduleWrapper.addClass(loadingClass); 158 pageCache.requesting = true; 159 160 var requestSuccessful = false, 161 requestTotalItemCount = itemCache.totalItemCount == -1; 162 163 var postData = { 164 portalId: self.options.portalId, 165 moduleId: self.options.moduleId, 166 tabId: self.options.tabId, 167 articleId: self.options.articleId, 168 contentKey: contentKey, 169 contentPage: page, 170 getPaginationMeta: requestTotalItemCount, 171 localeCode: self.options.localeCode 172 } 173 174 if (self.options.localeCode) 175 $.extend(postData, { localeCode: self.options.localeCode }); 176 177 $.ajax({
178 type: 'GET', 179 url: self.options.websiteClientRoot + 'DesktopModules/EasyDNNnews/ListContentHtml.ashx', 180 cache: false, 181 dataType: 'json', 182 timeout: 15000, 183 data: postData 184 }) 185 .done(function (response, status) { 186 requestSuccessful = true; 187 188 if (status == 'nocontent' || !$.isPlainObject(response)) { 189 itemCache.totalItemCount = 0; 190 pageCache.loaded = true; 191 return; 192 } 193 194 if (requestTotalItemCount) { 195 if (!response.contentCount) { 196 requestSuccessful = false; 197 return; 198 } 199 200 itemCache.totalItemCount = response.contentCount; 201 } 202 203 pageCache.content = response.contentHtml; 204 pageCache.loaded = true; 205 }) 206 .always(function () { 207 pageCache.requesting = false; 208 pageCache.requestError = !requestSuccessful; 209 210 showPage.call(self, contentKey, page); 211 }); 212 }; 213 214 function ContentBlock(elem, options) { 215 var self = this; 216 217 self.options = options; 218 self.itemCache = {}; 219 220 self.$moduleWrapper = $(elem); 221 self.$contentWrapper = $('.edn__articleListWrapper', self.$moduleWrapper); 222 self.$header = $('.edn__contentBlock_header', self.$moduleWrapper); 223 self.$headerTitle = $('.edn__contentBlock_title', self.$header); 224 self.$visibleItemList = $('.edn__contentBlock_visibleItemList', self.$moduleWrapper); 225 self.$hiddenItemWrapper = $('.edn__contentBlock_hiddenItemWrapper', self.$moduleWrapper); 226 self.$hiddenItemList = $('.edn__contentBlock_hiddenItemList', self.$hiddenItemWrapper); 227 228 self.itemCount = $('>', self.$visibleItemList).length; 229 self.activeItemIndex = $('> .' + activeItemClass, self.$visibleItemList).index(); 230 231 self.verticalLayout = self.$visibleItemList.hasClass('edn__contentBlock_vertical'); 232 233 if (self.verticalLayout) 234 self.$heightReference = $('.edn__contentBlock_heightReference', self.$moduleWrapper); 235 236 var contentSwitchEvents = 'click fakeClick'; 237 238 if (self.$moduleWrapper.hasClass('edn__contentBlock_hoverSwitch')) 239 contentSwitchEvents += ' mouseenter'; 240 241 self.$moduleWrapper 242 .on('click', '.edn__contentBlock_hiddenItemWrapper .edn__contentBlock_hiddenItemList >', function () { 243 var $this = $(this); 244 245 $this 246 .addClass(activeItemClass) 247 .siblings() 248 .removeClass(activeItemClass); 249 250 $('> .' + hideItemClass, self.$visibleItemList) 251 .eq($this.index()) 252 .trigger('fakeClick'); 253 }) 254 .on(contentSwitchEvents, '.edn__contentBlock_visibleItemList >', function () { 255 var $item = $(this); 256 257 $item 258 .addClass(activeItemClass) 259 .siblings() 260 .removeClass(activeItemClass); 261 262 self.activeItemIndex = $item.index(); 263 264 self.$moduleWrapper.removeClass(triggeredNextPageClass + ' ' + triggeredPreviousPageClass); 265 266 requestPage.call(self, $item.data('meta').contentKey, 1); 267 }) 268 .on('click', '.edn__contentBlock_previousPage, .edn__contentBlock_nextPage', function () { 269 var $this = $(this), 270 nextPage = false; 271 272 if ($this.hasClass('edn__contentBlock_previousPage') && self.$moduleWrapper.hasClass(disablePreviousPageClass)) 273 return; 274 275 if ($this.hasClass('edn__contentBlock_nextPage')) { 276 if (self.$moduleWrapper.hasClass(disableNextPageClass)) 277 return; 278 279 nextPage = true; 280 281 self.$moduleWrapper 282 .addClass(triggeredNextPageClass) 283 .removeClass(triggeredPreviousPageClass); 284 } else { 285 self.$moduleWrapper 286 .addClass(triggeredPreviousPageClass) 287 .removeClass(triggeredNextPageClass); 288 } 289 290 var activeItemContentKey = '-1', 291 $items = $('>', self.$visibleItemList); 292 293 if ($items.length) 294 activeItemContentKey = $items.eq(self.activeItemIndex).data('meta').contentKey; 295
296 var itemCache = self.itemCache[activeItemContentKey], 297 page = 1; 298 299 if (itemCache) { 300 if (itemCache.totalItemCount <= 0) 301 return; 302 303 page = itemCache.activePage; 304 } 305 306 if (nextPage) 307 page++; 308 else 309 page--; 310 311 requestPage.call(self, activeItemContentKey, page); 312 }) 313 .on('click', '.edn_contentBlock_trigger', function () { 314 $('.edn__contentBlock_hiddenItemWrapper').toggleClass('edn__showItems'); 315 }) 316 .on('click', '.edn__contentBlock_hiddenItemList li', function () { 317 $('.edn__contentBlock_hiddenItemWrapper').removeClass('edn__showItems').addClass('edn__itemListClicked'); 318 setTimeout(function () { 319 $('.edn__contentBlock_hiddenItemWrapper').removeClass('edn__itemListClicked'); 320 }, 300); 321 322 }).mouseleave(function () { 323 $('.edn__contentBlock_hiddenItemWrapper').removeClass('edn__showItems'); 324 setTimeout(function () { 325 $('.edn__contentBlock_hiddenItemWrapper').removeClass('edn__itemListClicked'); 326 }, 300); 327 }); 328 329 self.itemCache['-1'] = { 330 pages: { 331 '1': { 332 content: self.$contentWrapper[0].outerHTML, 333 loaded: true, 334 requesting: false, 335 requestError: false 336 } 337 }, 338 totalItemCount: options.initialContentItemCount, 339 activePage: 1 340 }; 341 342 self.resize(); 343 344 masonryInit.call(self); 345 346 self.$moduleWrapper.addClass('edn__contentBlock_ready'); 347 348 $(window).on('resize', function () { 349 self.resize(); 350 }); 351 } 352 353 ContentBlock.prototype = { 354 resize: function (skipTimeout) { 355 var self = this, 356 hideItems = false; 357 358 $('>', self.$visibleItemList).removeClass(hideItemClass); 359 360 if (self.verticalLayout) { 361 if (self.$heightReference.length == 0) 362 return; 363 364 var availableHeight = self.$heightReference.outerHeight(true); 365 366 if (self.$visibleItemList.outerHeight(true) > availableHeight) { 367 hideItems = true; 368 369 var i = self.itemCount - 1; 370 371 self.$hiddenItemList.empty(); 372 373 while (i >= 0 && self.$visibleItemList.outerHeight(true) > availableHeight) { 374 var $item = $('>', self.$visibleItemList).eq(i); 375 376 $item.addClass(hideItemClass); 377 self.$hiddenItemList.prepend($item.clone(true)); 378 379 i--; 380 } 381 } 382 383 clearTimeout(self.reResizeTimeout); 384 385 if (!skipTimeout) { 386 self.reResizeTimeout = setTimeout(function () { 387 self.resize(true); 388 }, 1000); 389 } 390 } else { 391 var availableWidth = self.$header.innerWidth() - (self.$headerTitle.length == 0 ? 0 : self.$headerTitle.outerWidth(true)) - 20; 392 availableWidth = Math.round(availableWidth) - 3; 393 if (self.$visibleItemList.outerWidth(false) > availableWidth) { 394 hideItems = true; 395 396 var i = self.itemCount - 1; 397 398 self.$hiddenItemList.empty(); 399 400 while (i >= 0 && self.$visibleItemList.outerWidth(false) > availableWidth) { 401 var $item = $('>', self.$visibleItemList).eq(i); 402 403 $item.addClass(hideItemClass); 404 self.$hiddenItemList.prepend($item.clone(true)); 405 406 i--; 407 } 408 } 409 } 410 411 if (hideItems) { 412 self.$visibleItemList.addClass(itemsHiddenClass); 413 self.$hiddenItemWrapper.addClass(itemsHiddenClass); 414 } else { 415 self.$visibleItemList.removeClass(itemsHiddenClass); 416 self.$hiddenItemWrapper.removeClass(itemsHiddenClass); 417 } 418 } 419 }; 420 421 var instanceKey = 'edNewsContentBlock', 422 defaultOptions = { 423 websiteClientRoot: '/', 424 portalId: 0, 425 moduleId: 0, 426 tabId: 0, 427 itemsPerPage: 5, 428 initialContentItemCount: 0, 429 masonry: false 430 }; 431 432 $.fn.edNewsContentBlock = function (options) { 433 options = $.extend({}, defaultOptions, options); 434 435 return this.each(function () { 436 var $self = $(this); 437 438 if ($self.data(instanceKey)) 439 return; 440 441 $self.data(instanceKey, new ContentBlock(this, options)); 442 }); 443 }; 444 445})(eds3_5_jq, window);
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.