1jQuery(document).ready(function($) { 2 3 var daln_archived_ticker_data_xml = ''; 4 var daln_ticker_cycles = 0; 5 6 /* 7 * Append the ticker in the DOM if the daln_apply_ticker flag is defined 8 */ 9 if ( typeof daln_apply_ticker != 'undefined' && daln_apply_ticker ){ 10 11 //append the ticker before the ending body tag 12 daln_append_html(); 13 14 //refresh the news only if the news ticker is in "open" status 15 if (( $("#daln-container").css("display") == "block") ){ 16 17 //refresh the news 18 daln_refresh_news(); 19 20 } 21 22 /* 23 * If the clock is based on the user time and the clock_autoupdate option enabled set the interval used to 24 * update the clock 25 */ 26 if(daln_clock_source == 2 && daln_clock_autoupdate == 1) { 27 window.setInterval(daln_set_clock_based_on_user_time, (daln_clock_autoupdate_time * 1000) ); 28 } 29 30 } 31 32 /* 33 * This function is used to refresh all the data displayed in the ticker and to animate the sliding news from the 34 * initial to the final destination. It's called in the following situations: 35 * 36 * - When the document is ready 37 * - When a cycle of sliding news has finished its animation 38 * - When the news ticker is opened with the open button 39 */ 40 function daln_refresh_news(){ 41 42 if(typeof daln_ticker_transient != 'undefined' && daln_ticker_transient !== null){ 43 44 //Convert the XML string to a JavaScript XML Document 45 daln_archived_ticker_data_xml = $.parseXML(daln_ticker_transient); 46 47 //Set the transient to null so it won't be used multiple times 48 daln_ticker_transient = null; 49 50 } 51 52 if( $.isXMLDoc( daln_archived_ticker_data_xml) === false || daln_ticker_cycles >= daln_cached_cycles ){ 53 54 //retrieve the news with ajax and refresh the news --------------------------------------------------------- 55 56 daln_ticker_cycles = 0; 57 58 //set ajax in synchronous mode 59 jQuery.ajaxSetup({async:false}); 60 61 //prepare input for the ajax request 62 var data = { 63 "action": "get_ticker_data", 64 "security": daln_nonce, 65 "ticker_id": daln_ticker_id 66 }; 67 68 //ajax 69 $.post(daln_ajax_url, data, function(ticker_data_xml) { 70 71 daln_archived_ticker_data_xml = ticker_data_xml; 72 73 daln_update_the_clock(ticker_data_xml); 74 75 daln_refresh_featured_news(ticker_data_xml); 76 77 daln_refresh_sliding_news(ticker_data_xml); 78 79 daln_slide_the_news(); 80 81 }); 82 83 //set ajax in asynchronous mode 84 jQuery.ajaxSetup({async:true}); 85 86 }else{ 87 88 //use the current ticker xml data to refresh the news ------------------------------------------------------ 89 90 daln_ticker_cycles++; 91 92 daln_update_the_clock(daln_archived_ticker_data_xml); 93 94 daln_refresh_featured_news(daln_archived_ticker_data_xml); 95 96 daln_refresh_sliding_news(daln_archived_ticker_data_xml); 97 98 daln_slide_the_news(); 99 100 } 101 102 } 103 104 /* 105 * Update the clock 106 */ 107 function daln_update_the_clock(ticker_data_xml){ 108 109 if(daln_clock_source == 2){
110 111 //update the clock based on the user time ------------------------------------------------------------------ 112 daln_set_clock_based_on_user_time(); 113 114 }else{ 115 116 //update the clock based on the server time ---------------------------------------------------------------- 117 var currentTime = $(ticker_data_xml).find('time').text(); 118 119 var timestamp = moment.unix(currentTime).utc(); 120 $("#daln-clock").text(timestamp.format(daln_clock_format)); 121 122 } 123 124 } 125 126 /* 127 * Remove the featured news title and excerpt from the DOM and uses the ticker data in XML format data to append the 128 * news featured news title and excerpt 129 */ 130 function daln_refresh_featured_news(ticker_data_xml){ 131 132 //parse the xml string 133 $(ticker_data_xml).find("featurednews news").each(function(){ 134 135 var news_title = $(this).find("newstitle").text(); 136 var news_excerpt = $(this).find("newsexcerpt").text(); 137 var url = $(this).find("url").text(); 138 139 //Delete the featured title 140 $('#daln-featured-title').html(""); 141 142 //Delete the featured excerpt 143 $('#daln-featured-excerpt').html(""); 144 145 if( url.length > 0 && daln_enable_links ){ 146 147 //Append the new featured title 148 $('#daln-featured-title').html( '<a target="' + daln_target_attribute + '" href="' + url + '">' + daln_htmlEscape( news_title ) + '</a>' ); 149 150 //Append the new featured excerpt 151 $('#daln-featured-excerpt').html( daln_htmlEscape( news_excerpt ) ); 152 153 }else{ 154 155 //Append the new featured title 156 $('#daln-featured-title').html( daln_htmlEscape( news_title ) ); 157 158 //Append the new featured excerpt 159 $('#daln-featured-excerpt').html( daln_htmlEscape( news_excerpt ) ); 160 161 } 162 163 }); 164 165 } 166 167 /* 168 * Deletes all the sliding news from the DOM and uses the ticker data in XML format to append the news sliding news 169 */ 170 function daln_refresh_sliding_news(ticker_data_xml){ 171 172 //Delete the previous sliding news 173 $('#daln-slider-floating-content').empty(); 174 175 //parse the xml string 176 $(ticker_data_xml).find("slidingnews news").each(function(){ 177 178 var news_title = $(this).find("newstitle").text(); 179 var url = $(this).find("url").text(); 180 var text_color = $(this).find("text_color").text(); 181 var text_color_hover = $(this).find("text_color_hover").text(); 182 var background_color = $(this).find("background_color").text(); 183 var background_color_opacity = $(this).find("background_color_opacity").text(); 184 var image_before = $(this).find("image_before").text(); 185 var image_after = $(this).find("image_after").text(); 186 187 //generate the style for the text color 188 if( text_color.trim().length > 0 ){ 189 var style_text_color = 'style="color: ' + text_color + ';"'; 190 }else{ 191 var style_text_color = ''; 192 } 193 194 //generate the style for the background color 195 if( background_color.trim().length > 0 ) { 196 var color_a = rgb_hex_to_dec(background_color); 197 var style_background_color = 'style="background: rgba(' + color_a['r'] + ',' + color_a['g'] + ',' + color_a['b'] + ',' + parseFloat(background_color_opacity) + ');"'; 198 }else{ 199 var style_background_color = ''; 200 } 201 202 //generate the image_before html 203 if(image_before.trim().length > 0){ 204 var image_before_html = '<img class="daln-image-before" src="' + image_before + '">'; 205 }else{ 206 var image_before_html = ''; 207 } 208 209 //generate the image_after html 210 if(image_after.trim().length > 0){ 211 var image_after_html = '<img class="daln-image-after" src="' + image_after + '">'; 212 }else{ 213 var image_after_html = ''; 214 } 215 216 //check if is set the RTL layout option 217 if( daln_rtl_layout == 0 ){ 218 219 //LTR layout ----------------------------------------------------------------------- 220 if( url.length > 0 && daln_enable_links ){ 221 $('#daln-slider-floating-content').append( '<div ' + style_background_color + ' class="daln-slider-single-news">' + image_before_html + '<a data-text-color="' + text_color + '" onmouseout=\'jQuery(this).css("color", jQuery(this).attr("data-text-color"))\' onmouseover=\'jQuery(this).css("color", "' + text_color_hover + '" )\' ' + style_text_color + ' target="' + daln_target_attribute + '" href="' + url + '">' + daln_htmlEscape( news_title ) + '</a>' + image_after_html + '</div>' ); 222 }else{ 223 $('#daln-slider-floating-content').append( '<div ' + style_background_color + ' class="daln-slider-single-news">' + image_before_html + '<span ' + style_text_color + ' >' + daln_htmlEscape( news_title ) + '</span>' + image_after_html + '</div>' ); 224 } 225 226 }else{ 227 228 //RTL layout ----------------------------------------------------------------------- 229 if( url.length > 0 && daln_enable_links ){ 230 $('#daln-slider-floating-content').prepend( '<div ' + style_background_color + ' class="daln-slider-single-news">' + image_before_html + '<a data-text-color="' + text_color + '" onmouseout=\'jQuery(this).css("color", jQuery(this).attr("data-text-color"))\' onmouseover=\'jQuery(this).css("color", "' + text_color_hover + '" )\' ' + style_text_color + ' target="' + daln_target_attribute + '" href="' + url + '">' + daln_htmlEscape( news_title ) + '</a>' + image_after_html + '</div>' ); 231 }else{ 232 $('#daln-slider-floating-content').prepend( '<div ' + style_background_color + ' class="daln-slider-single-news">' + image_before_html + '<span ' + style_text_color + ' >' + daln_htmlEscape( news_title ) + '</span>' + image_after_html + '</div>' ); 233 } 234 235 } 236 }); 237 238 } 239 240 /* 241 * Slides the news with jQuery animate from the initial to the final position. When the animation is complete calls 242 * daln_refresh_news() which restarts the process from the start. 243 */ 244 function daln_slide_the_news(){ 245 246 //if the news slider is already animated then return 247 if( ( $('#daln-slider-floating-content:animated').length ) == 1 ){ return; }; 248 249 //get browser with 250 var window_width = $(window).width(); 251 252 //floating news width 253 var floating_news_width =parseInt( $( "#daln-slider-floating-content" ).css("width") ); 254 255 //check if is set the RTL layout option 256 if( daln_rtl_layout == 0 ){ 257 258 //LTR layout ----------------------------------------------------------------------- 259 260 //position outside the screen to the left 261 var outside_left = floating_news_width + window_width; 262 263 //set floating content left position outside the screen 264 $( "#daln-slider-floating-content" ).css("left", window_width ); 265 266 //start floating the news 267 $( "#daln-slider-floating-content" ).delay(daln_sliding_delay).animate({ 268 left: "-=" + outside_left, 269 easing: "linear" 270 }, ( outside_left * daln_sliding_speed ), "linear", function() { 271 272 //animation complete 273 daln_refresh_news(); 274 275 }); 276 277 }else{ 278 279 //RTL layout ----------------------------------------------------------------------- 280 281 //position outside the screen to the left 282 var outside_left = floating_news_width + window_width; 283 284 //set floating content left position outside the screen 285 $( "#daln-slider-floating-content" ).css("left", - floating_news_width ); 286 287 //start floating the news 288 $( "#daln-slider-floating-content" ).delay(daln_sliding_delay).animate({ 289 left: "+=" + outside_left, 290 easing: "linear" 291 }, ( outside_left * daln_sliding_speed ), "linear", function() { 292 293 //animation complete 294 daln_refresh_news(); 295 296 }); 297 298 } 299 300 } 301 302 /* 303 * On the click event of the "#daln-close" element closes the news ticker and sends an ajax request used to save the 304 * "closed" status in the "live_news_status" cookie 305 */ 306 $("#daln-close").click(function() { 307 308 //Stop the animation 309 $("#daln-slider-floating-content").stop(); 310 311 //Delete the previous sliding news 312 $('#daln-slider-floating-content').empty(); 313 314 //Hide the news container 315 $("#daln-container").hide(); 316 317 //Show the open button 318 $("#daln-open").show(); 319 320 //prepare input for the ajax request 321 var data = { 322 "action": "set_status_cookie", 323 "security": daln_nonce, 324 "status": "closed" 325 }; 326 327 //ajax 328 $.post(daln_ajax_url, data, function(ajax_response) { 329 330 if( ajax_response == "success" ){ 331 //nothing 332 } 333 334 }); 335 336 //set the status hidden field to closed 337 $("#daln-status").attr("value","closed"); 338 339 }); 340 341 /* 342 * On the click event of the "#daln-open" element opens the news ticker and sends an ajax request used to save the 343 * "open" status in the "live_news_status" cookie 344 */ 345 $("#daln-open").click(function() { 346 347 //Show the news container 348 $("#daln-container").show(); 349 350 //Show the open button 351 $("#daln-open").hide(); 352 353 daln_refresh_news(); 354 355 //prepare input for the ajax request 356 var data = { 357 "action": "set_status_cookie", 358 "security": daln_nonce, 359 "status": "open" 360 }; 361 362 //ajax 363 $.post(daln_ajax_url, data, function(ajax_response) { 364 365 if( ajax_response == "success" ){ 366 //nothing 367 } 368 369 }); 370 371 //set the status hidden field to open
372 $("#daln-status").attr("value","open"); 373 374 }); 375 376 /* 377 * Converts certain characters to their HTML entities 378 */ 379 function daln_htmlEscape(str) { 380 return String(str) 381 .replace(/&/g, '&') 382 .replace(/"/g, '"') 383 .replace(/'/g, ''') 384 .replace(/</g, '<') 385 .replace(/>/g, '>'); 386 } 387 388 /* 389 * Appends the ticker HTML just before the ending body element 390 */ 391 function daln_append_html(){ 392 393 html_output = '<div id="daln-container">' + 394 395 '<!-- featured news -->' + 396 '<div id="daln-featured-container">' + 397 '<div id="daln-featured-title-container">' + 398 '<div id="daln-featured-title"></div>' + 399 '</div>' + 400 '<div id="daln-featured-excerpt-container">' + 401 '<div id="daln-featured-excerpt"></div>' + 402 '</div>' + 403 '</div>' + 404 405 '<!-- slider -->' + 406 '<div id="daln-slider">' + 407 '<!-- floating content -->' + 408 '<div id="daln-slider-floating-content"></div>' + 409 '</div>' + 410 411 '<!-- clock -->' + 412 '<div id="daln-clock"></div>' + 413 414 '<!-- close button -->' + 415 '<div id="daln-close"></div>' + 416 417 '</div>' + 418 419 '<!-- open button -->' + 420 '<div id="daln-open"></div>'; 421 422 $('body').append(html_output); 423 424 } 425 426 /* 427 * Uses a "Date" object to retrieve the user time and adds the clock offset of this news ticker 428 */ 429 function daln_set_clock_based_on_user_time(){ 430 431 //Get the current unix timestamp and add the offset 432 var timestamp = moment().unix() + daln_clock_offset; 433 434 //Convert the unix timestamp to the provided format 435 var time = moment.unix(timestamp).format(daln_clock_format); 436 437 //Update the DOM 438 $("#daln-clock").text(time); 439 440 } 441 442 /* 443 * Given an hexadecimal rgb color an array with the 3 components converted in decimal is returned 444 * 445 * @param string The hexadecimal rgb color 446 * @return array An array with the 3 component of the color converted in decimal 447 */ 448 function rgb_hex_to_dec(hex){ 449 450 //remove the # character 451 var hex = hex.replace('#', ''); 452 453 //find the component of the color 454 if ( hex.length == 3 ) { 455 var r = parseInt(hex.substring(0, 1), 16); 456 var g = parseInt(hex.substring(1, 2), 16); 457 var b = parseInt(hex.substring(2, 3), 16); 458 } else { 459 var r = parseInt(hex.substring(0, 2), 16); 460 var g = parseInt(hex.substring(2, 4), 16); 461 var b = parseInt(hex.substring(4, 6), 16); 462 } 463 464 //generate the array with the component of the color 465 var color_a = new Array(); 466 color_a['r'] = r; 467 color_a['g'] = g; 468 color_a['b'] = b; 469 470 return color_a; 471 472 } 473 474});
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.