1/*jslint browser: true, continue: true, regexp: true, plusplus: true, sloppy: true, this: true, for: true, multivar: true */ 2/*global $DGD */ 3/*global jQuery */ 4/*global FB */ 5/*global gapi */ 6/*global IN */ 7/*global console */ 8/*global twttr */ 9 10if (typeof $DGD.echo !== 'object') { 11 $DGD.echo = function (str) { 12 if ($DGD.debug) { 13 console.log(str); 14 } 15 }; 16} 17 18$DGD.didScroll = true; 19$DGD.didResize = false; 20$DGD.screenheight = 2000; 21$DGD.screenwidth = 4000; 22$DGD.all_boxes = []; 23$DGD.boxes_wait_for_scroll = []; 24$DGD.boxes_with_relative_position = []; 25$DGD.boxes_wait_for_close = []; 26$DGD.boxes_wait_for_open = []; 27$DGD.tabs_to_open = []; 28$DGD.docheight = 2000; 29$DGD.toScroll = 2000; 30$DGD.overlay = null; 31 32 33function DgdCreateSocialButtons(box) { 34 this.ul = false; 35 this.container = false; 36 37 this.addFbButton = function () { 38 this.ul.append('<li class="fb ' + box.social.facebook + '"><div class="fb-like" data-send="false" data-share="false" data-action="like" data-layout="' + box.social.facebook + '" data-width="200" data-show-faces="false"></div></li>'); 39 if (typeof FB === 'object') { 40 FB.init({status: true, cookie: true, xfbml: true}); 41 } else { 42 jQuery.getScript("//connect.facebook.net/en_US/all.js#xfbml=1", function () { 43 FB.init({status: true, cookie: true, xfbml: true}); 44 }); 45 } 46 }; 47 48 this.addTwitterButton = function () { 49 if (typeof twttr === 'object') { 50 twttr.widgets.load(); 51 } else { 52 jQuery.getScript("//platform.twitter.com/widgets.js"); 53 } 54 55 this.ul.append('<li class="twitter ' + box.social.twitter + '"><a href="https://twitter.com/share" data-url="' + $DGD.permalink + '" data-text="' + $DGD.title + '" class="twitter-share-button" >Tweet</a></li>'); 56 if (box.social.twitter === 'no-count') { 57 this.ul.find('.twitter a').attr('data-count', 'none'); 58 } else if (box.social.twitter === 'vertical') { 59 this.ul.find('.twitter a').attr('data-count', 'vertical'); 60 } 61 }; 62 63 this.addGoogleButton = function () { 64 if (typeof gapi === 'object') { 65 jQuery(".g-plusone").each(function () { 66 gapi.plusone.render(jQuery(this).get(0)); 67 }); 68 } else { 69 jQuery.getScript("https://apis.google.com/js/plusone.js"); 70 } 71 72 this.ul.append('<li class="google ' + box.social.google + '"><div class="g-plusone"></div></li>'); 73 if (box.social.google === 'annotation') { 74 this.ul.find('.google div').attr('data-size', 'medium'); 75 this.ul.find('.google div').attr('data-annotation', 'none'); 76 } else { 77 this.ul.find('.google div').attr('data-size', box.social.google); 78 } 79 }; 80 81 this.addLinkedinButton = function () { 82 // if (typeof IN === 'object') { 83 // IN.parse(); 84 // } else { 85 if (typeof IN === 'undefined') { 86 jQuery.getScript("//platform.linkedin.com/in.js"); 87 } 88 this.ul.append('<li class="linkedin ' + box.social.linkedin + '"><script type="IN/Share"' + (box.social.linkedin !== 'none' ? ' data-counter="' + box.social.linkedin + '"' : '') + '></script></li>'); 89 }; 90 91 this.addStumbleuponButton = function () { 92 jQuery.getScript("//platform.stumbleupon.com/1/widgets.js"); 93 this.ul.append('<li class="stumbleupon s' + box.social.stumbleupon + '"><su:badge layout="' + box.social.stumbleupon + '"></su:badge></li>'); 94 }; 95 96 this.addPinterestButton = function () { 97 jQuery.getScript("//assets.pinterest.com/js/pinit.js"); 98 this.ul.append('<li class="pinterest ' + box.social.pinterest + '"><a href="http://pinterest.com/pin/create/button/?url=' + $DGD.permalink + '&media=' + $DGD.thumbnail + '" class="pin-it-button" count-layout="' + box.social.pinterest + '"><img border="0" src="//assets.pinterest.com/images/PinExt.png" title="Pin It" /></a></li>'); 99 }; 100 101 if (box.div.find('.inscroll').length > 0) { 102 this.container = box.div.find('.inscroll'); 103 } else if (box.div.find('#inscroll').length > 0) { 104 this.container = box.div.find('#inscroll'); 105 } else { 106 this.container = box.div; 107 } 108 109 if (box.social) { 110 if (!jQuery(this.container).find('ul.stb_social').length) { 111 // add ul if needed 112 jQuery(this.container).append('<ul class="stb_social"></ul>'); 113 } 114 this.ul = jQuery(this.container).find('ul.stb_social'); 115 if (this.ul.length > 0) { 116 if (box.social.facebook) { 117 this.addFbButton(); 118 } 119 if (box.social.twitter) { 120 this.addTwitterButton(); 121 } 122 if (box.social.google) { 123 this.addGoogleButton(); 124 } 125 if (box.social.linkedin) { 126 this.addLinkedinButton(); 127 } 128 if (box.social.stumbleupon) { 129 this.addStumbleuponButton(); 130 } 131 if (box.social.pinterest) { 132 this.addPinterestButton(); 133 } 134 } 135 } 136} 137 138$DGD.addClass = function (element, name) { 139 element.className = element.className.replace(/\s+$/gi, '') + ' ' + name; 140}; 141 142$DGD.removeClass = function (element, name) { 143 element.className = element.className.replace(name, ''); 144};
145 146$DGD.loadCss = function (cssObject, parent) { 147 var cssUrl, fileref; 148 if (typeof cssObject === 'string') { 149 cssUrl = cssObject; 150 fileref = document.createElement('link'); 151 fileref.rel = 'stylesheet'; 152 fileref.type = 'text/css'; 153 fileref.href = cssUrl; 154 } else if (typeof cssObject === 'object') { 155 // console.log('CSS Object: '+cssObject); 156 cssUrl = cssObject.href; 157 fileref = cssObject; 158 } 159 if (parent.childNodes.lenght > 0) { 160 parent.insertBefore(fileref, parent.childNodes[0]); 161 } else { 162 parent.appendChild(fileref); 163 } 164}; 165 166$DGD.measureScreen = function () { 167 if (typeof window.innerHeight === 'number') { 168 this.screenheight = parseInt(window.innerHeight, 10); 169 this.screenwidth = parseInt(window.innerWidth, 10); 170 } else if (typeof screen.availHeight === 'number') { 171 this.screenheight = parseInt(screen.availHeight, 10); 172 this.screenwidth = parseInt(screen.availWidth, 10); 173 } else { 174 this.screenheight = parseInt(jQuery(window).height(), 10); 175 this.screenwidth = parseInt(jQuery(window).width(), 10); 176 } 177 this.docheight = parseInt(jQuery(document).height() || document.body.scrollHeight, 10); 178 // With no doctype tag Chrome reports the same value for both calls. 179 this.toScroll = this.docheight - this.screenheight; 180 // console.log(this.screenwidth + 'x' + this.screenheight + ' ' + this.toScroll); 181}; 182 183 184$DGD.isMobile = function (a) { 185 // Thanks goes to http://detectmobilebrowsers.com/about 186 if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4))) { 187 return true; 188 } 189 return false; 190}; 191 192 193$DGD.calcScroll = function () {
194 var scrolled = (document.body.scrollTop || parseInt(jQuery(document).scrollTop(), 10)), 195 rate = Math.round((scrolled + 0.001) * 10 / (this.toScroll + 0.001)) * 10, 196 i, 197 box; 198 for (i = 0; i < this.boxes_wait_for_scroll.length; i++) { 199 box = this.boxes_wait_for_scroll[i]; 200 if ((box.trigger.action === 'scroll' || box.trigger.action === 'element') && rate >= box.trigger.scroll && box.hidden && !box.closed) { 201 if (box.trigger.delaytime > 0) { 202 this.regTimedOpening(box, box.trigger.delaytime); 203 } else { 204 this.showBox(box, false); 205 } 206 } 207 if (!box.keep_open && (box.trigger.action === 'scroll' || box.trigger.action === 'element') && rate < box.trigger.scroll && !box.hidden) { 208 this.hideBox(box); 209 } 210 } 211}; 212 213$DGD.setCookie = function (cname, exdays) { 214 var d = new Date(), expires = '', path = '; path=/'; 215 if (exdays !== 0) { 216 d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000)); 217 expires = "; expires=" + d.toUTCString(); 218 } 219 document.cookie = cname + "=" + exdays + expires + path; 220}; 221 222$DGD.getCookie = function (cname) { 223 // returns integer representing stored cookie value 224 var name = cname + '=', ca = document.cookie.split(';'), i, c; 225 for (i = 0; i < ca.length; i++) { 226 c = ca[i]; 227 while (c.charAt(0) === ' ') { c = c.substring(1); } 228 if (c.indexOf(name) !== -1) { return parseInt(c.substring(name.length, c.length), 10); } 229 } 230 return -2; 231}; 232 233$DGD.checkCookie = function (box) { 234 var cookieval = this.getCookie(box.id); 235 if (cookieval === box.cookieLifetime || cookieval === 9000) { 236 // value from cookie exists and is same than in scrollbox: showing is disabled 237 // value from cookie is 9000: showing is disabled 238 box.closed = true; 239 return false; 240 } 241 // cookie does not exist OR value is changed: showing is enabled 242 return true; 243}; 244 245$DGD.resizeBox = function (box) { 246 // box.height is input from box author 247 // box.height_int is calculated value according to screen or box measurements, if height expressed in relative values (auto or %) 248 if (box.height === 'auto') { 249 // used for TAB-s mainly 250 box.height_int = parseInt(box.div.outerHeight(true), 10); 251 } else { 252 if (box.height === '100%') { 253 box.height_int = this.screenheight - 2 * box.jsCss.margin; 254 } else { 255 box.height_int = parseInt(box.height, 10); 256 if (box.height_int > this.screenheight - 2 * box.jsCss.margin) { 257 box.height_int = this.screenheight - 2 * box.jsCss.margin; 258 } 259 } 260 box.div.css('height', box.height_int); 261 } 262 263 if (box.width === 'auto') { 264 // used for TAB-s mainly 265 box.width_int = parseInt(box.div.outerWidth(true), 10); 266 } else { 267 if (box.width === '100%') { 268 box.width_int = this.screenwidth - 2 * box.jsCss.margin; 269 } else { 270 box.width_int = parseInt(box.width, 10); 271 if (box.width_int > this.screenwidth - 2 * box.jsCss.margin) { 272 box.width_int = this.screenwidth - 2 * box.jsCss.margin; 273 } 274 } 275 box.div.css('width', box.width_int); 276 } 277}; 278 279$DGD.calculateBoxPlacement = function (box) { 280 // calculates box positions before and after animation (e.g. slide out) according to 281 // box.vpos: vertical (y-axis) positioning, either 'top', 'center', or 'bottom') 282 // box.hpos: horisontal (x-axis) positioning, either 'left', 'center', or 'right' 283 // box.transition.from: slide from behind edge, 't' - top edge, 'b' - bottom edge, 'r' - right edge, 'l' - left edge 284 285 // before executing this function box.width_int and box.height_int int values must be calculated with this.resizebox 286 287 switch (box.vpos) { // placement 'to' 288 case 'top': 289 box.vpos_att = 'top'; 290 box.vpos_to = box.jsCss.margin; 291 switch (box.transition.from) { 292 case 't': 293 box.vpos_from = -(box.height_int + box.jsCss.margin); 294 break; 295 case 'b': 296 box.vpos_from = this.screenheight + box.jsCss.margin; 297 break; 298 default: 299 box.vpos_from = box.vpos_to; 300 } 301 break; 302 case 'center': 303 box.vpos_att = 'top'; 304 box.vpos_to = (this.screenheight - box.height_int) / 2; 305 switch (box.transition.from) { 306 case 't': 307 box.vpos_from = -(box.height_int + box.jsCss.margin); 308 break; 309 case 'b': 310 box.vpos_from = this.screenheight + box.jsCss.margin; 311 break; 312 default: 313 box.vpos_from = box.vpos_to; 314 } 315 break; 316 default: // case 'bottom' 317 box.vpos_att = 'bottom'; 318 box.vpos_to = box.jsCss.margin; 319 switch (box.transition.from) { 320 case 't': 321 box.vpos_from = this.screenheight + box.jsCss.margin; 322 break; 323 case 'b': 324 box.vpos_from = -(box.height_int + box.jsCss.margin); 325 break; 326 default: 327 box.vpos_from = box.vpos_to; 328 } 329 break; 330 } 331 332 switch (box.hpos) { // placement 'to' 333 case 'left': 334 box.hpos_att = 'left'; 335 box.hpos_to = box.jsCss.margin; 336 switch (box.transition.from) { 337 case 'r': 338 box.hpos_from = this.screenwidth + box.jsCss.margin; 339 break; 340 case 'l': 341 box.hpos_from = -(box.width_int + 2 * box.jsCss.margin); 342 break; 343 default: 344 box.hpos_from = box.hpos_to; 345 } 346 break; 347 case 'center': 348 box.hpos_att = 'left'; 349 box.hpos_to = (this.screenwidth - box.width_int) / 2; 350 switch (box.transition.from) { 351 case 'r': 352 box.hpos_from = this.screenwidth + box.jsCss.margin; 353 break; 354 case 'l': 355 box.hpos_from = -(box.width_int + 2 * box.jsCss.margin); 356 break; 357 default: 358 box.hpos_from = box.hpos_to; 359 } 360 break; 361 default: // case 'right': 362 box.hpos_att = 'right'; 363 box.hpos_to = box.jsCss.margin; 364 switch (box.transition.from) { 365 case 'r': 366 box.hpos_from = -(box.width_int + 2 * box.jsCss.margin); 367 break; 368 case 'l': 369 box.hpos_from = this.screenwidth + 2 * box.jsCss.margin; 370 break; 371 default: 372 box.hpos_from = box.hpos_to; 373 } 374 break; 375 } 376 377 box.div.css(box.vpos_att, box.vpos_from); 378 box.div.css(box.hpos_att, box.hpos_from); 379 box.anim_from[box.vpos_att] = box.vpos_from; 380 box.anim_from[box.hpos_att] = box.hpos_from; 381 box.anim_to[box.vpos_att] = box.vpos_to; 382 box.anim_to[box.hpos_att] = box.hpos_to; 383};
384 385$DGD.placeBox = function (box) { 386 var image, 387 elementheight, 388 placeCloseButtonImage = function () { 389 // resize close button after image onload (so measurements are known) 390 // assumingly close button is always first children of box div 391 var closebutton = box.div.children().first(); 392 closebutton.removeClass('dgd_stb_box_x'); 393 closebutton.css('background-image', 'url(' + box.closeImageUrl + ')'); 394 closebutton.width(image.width); 395 closebutton.height(image.height); 396 closebutton.css('border', 'none'); 397 closebutton.css('top', '-' + (box.jsCss.margin + parseInt(box.div.css('border-top-width'), 10)) + 'px'); 398 closebutton.css('right', '-' + (box.jsCss.margin + parseInt(box.div.css('border-right-width'), 10)) + 'px'); 399 }; 400 if (!box.div) { 401 box.div = jQuery('#' + box.id); 402 } 403 box.hidden = true; // box is temporarily not visible 404 box.closed = false; // box is closed, do not show again 405 box.anim_from = {}; 406 box.anim_to = {}; 407 box.width_int = null; // value will be set with this.resizeBox 408 box.height_int = null; // value will be set with this.resizeBox 409 410 // set div properties first as they affect position calculations later 411 if (box.jsCss.backgroundColor !== null && box.jsCss.backgroundColor !== '') { 412 box.div.css('background-color', box.jsCss.backgroundColor); 413 } 414 if (box.jsCss.padding !== null) { 415 box.div.css('padding', box.jsCss.padding + 'px'); 416 } 417 box.jsCss.margin = parseInt(box.jsCss.margin, 10); 418 if (box.jsCss.borderWidth !== '0px' && box.jsCss.borderColor !== '') { 419 box.div.css('border', box.jsCss.borderColor + ' solid ' + box.jsCss.borderWidth); 420 } 421 if (box.jsCss.borderRadius !== '0px') { 422 box.div.css('border-radius', box.jsCss.borderRadius); 423 } 424 if (box.jsCss.boxShadow !== '0px') { 425 box.div.css('box-shadow', box.jsCss.boxShadow + ' ' + box.jsCss.boxShadow + ' 25px #888888'); 426 } 427 if (box.jsCss.backgroundImageUrl !== null && box.jsCss.backgroundImageUrl !== '') { 428 box.div.css('background-image', 'url(' + box.jsCss.backgroundImageUrl + ')'); 429 } 430 431 if (box.closeImageUrl !== null && box.closeImageUrl !== '') { 432 // first tag in box.div is always close button, set this image as background 433 image = new Image(); 434 image.src = box.closeImageUrl; 435 image.onload = placeCloseButtonImage; 436 } 437 438 box.socialButtonEngine = new DgdCreateSocialButtons(box); 439 440 if (box.parentid) { 441 box.div.addClass('dgd_stb_tab'); 442 box.div.click($DGD.closeBox); 443 } 444 445 if (box.trigger.action === 'element') { 446 if (jQuery(box.trigger.element).length > 0) { 447 elementheight = jQuery(box.trigger.element).offset().top; 448 // this.toScroll = this.docheight - this.screenheight; 449 box.trigger.scroll = ((elementheight - this.screenheight) + 0.001) / (this.toScroll + 0.001) * 100; 450 } else { 451 // if element is missing, box will be not shown 452 box.trigger.scroll = 111; 453 this.echo('Element ' + box.trigger.element + ' is missing'); 454 } 455 } 456 457 458 switch (box.transition.effect) { 459 case 'fade': 460 box.anim_from.opacity = 0; 461 box.anim_to.opacity = 1; 462 box.div.css('opacity', 0); 463 break; 464 } 465 // box.div.css('display', 'block').stop(true, true); 466}; 467 468$DGD.fixPosition = function () { 469 var i, box; 470 for (i = 0; i < this.all_boxes.length; i++) { 471 box = this.all_boxes[i]; 472 this.resizeBox(box); 473 this.calculateBoxPlacement(box); 474 if (!box.hidden) { 475 // Box already visible, fix position 476 // box.div.animate(box.anim_to, box.transition.speed, 'swing'); 477 478 box.div.css(box.vpos_att, box.vpos_to); 479 box.div.css(box.hpos_att, box.hpos_to); 480 } 481 } 482}; 483 484$DGD.hideOverlay = function (box) { 485 if (typeof box.lightbox === 'object' && box.lightbox.enabled) { 486 $DGD.overlay.hide(); 487 jQuery('#page, .dgd_blurme').removeClass('dgd_blur'); 488 } 489}; 490 491$DGD.hideBox = function (box) { 492 if (box.hidden) { 493 // already hidden nothing to do here 494 return; 495 } 496 // BUG: Do not hide if some input boxes are in focus? 497 box.hidden = true; 498 box.div.animate(box.anim_from, box.transition.speed, 'swing', function () { 499 box.div.css('display', 'none'); 500 });
501 $DGD.hideOverlay(box); 502}; 503 504$DGD.regTimedClose = function (box, seconds) { 505 if (seconds > 0) { 506 box.closingTime = Date.now() + parseInt(seconds, 10) * 1000; 507 $DGD.boxes_wait_for_close[$DGD.boxes_wait_for_close.length] = box; 508 } 509}; 510 511$DGD.regTimedOpening = function (box, seconds) { 512 if (seconds > 0) { 513 box.openingTime = Date.now() + parseInt(seconds, 10); 514 $DGD.boxes_wait_for_open[$DGD.boxes_wait_for_open.length] = box; 515 } 516}; 517 518$DGD.showOverlay = function(box) { 519 if (typeof box.lightbox === 'object' && box.lightbox.enabled) { 520 $DGD.overlay.height(this.docheight); 521 $DGD.overlay.css({'opacity': box.lightbox.opacity, 'background-color': box.lightbox.color}); 522 $DGD.overlay.show(); 523 if (box.lightbox.blur) { 524 jQuery('#page, .dgd_blurme').addClass('dgd_blur'); 525 } 526 } 527}; 528 529$DGD.showBox = function (box, forcedOpen) { 530 if (!box) { box = this; } 531 if (!box.hidden || (box.closed && !forcedOpen)) { 532 // already visible OR forcefully closed, return 533 return; 534 } 535 if (box.tabid) { 536 $DGD.closeBox($DGD.getBoxById(box.tabid)); 537 } 538 539 this.showOverlay(box); 540 541 box.hidden = false; 542 box.div.css('display', 'block').stop(true, true); 543 box.div.animate(box.anim_to, box.transition.speed, 'swing'); 544 if (box.delay_auto_close > 0) { 545 $DGD.regTimedClose(box, box.delay_auto_close); 546 } 547}; 548 549$DGD.getBoxById = function (box_id) { 550 var i; 551 for (i = 0; i < $DGD.scrollboxes.length; i++) { 552 if ($DGD.scrollboxes[i].id === box_id) { return $DGD.scrollboxes[i]; } 553 } 554 return false; 555}; 556 557$DGD.getBoxByElementAction = function (e) { 558 var i, box; 559 for (i = 0; i < $DGD.scrollboxes.length; i++) { 560 box = $DGD.scrollboxes[i]; 561 if (box.trigger.action === e.type && jQuery(box.trigger.element).get(0) === e.currentTarget) { 562 return box; 563 } 564 } 565}; 566 567$DGD.closeBox = function () { 568 // closeBox is initiated from Static context, use $DGD instead of 'this' 569 var box = $DGD.getBoxById(jQuery(this).closest('.dgd_stb_box').attr('id')); 570 if (box) { 571 box.closed = true; 572 $DGD.hideBox(box); 573 $DGD.setCookie(box.id, box.cookieLifetime); 574 if (box.tabid) { 575 // it's a box with tab, show tab 576 $DGD.showBox($DGD.getBoxById(box.tabid), true); 577 } 578 if (box.parentid) { 579 // if tab is closed, then parent will be opened 580 $DGD.showBox($DGD.getBoxById(box.parentid), true); 581 } 582 } 583}; 584 585$DGD.closeAfterSubmit = function (box_id) { 586 var box = $DGD.getBoxById(box_id); 587 if (box && box.hide_submitted) { 588 // 9000 means 'for ever' 589 box.cookieLifetime = 9000; 590 $DGD.setCookie(box.id, box.cookieLifetime); 591 } 592 // register timed close 593 $DGD.regTimedClose(box, box.submit_auto_close); 594}; 595 596$DGD.submitForm = function (e) { 597 // submitForm is initiated from Static context, use $DGD 598 e.preventDefault(); 599 var form = jQuery(this), 600 box_id = form.closest('.dgd_stb_box').attr('id'), 601 message_container = form.next('p'), 602 sendobj = {}; 603 604 console.log(this); 605 606 // Fallback for situation where this <p> does not exist 607 if (message_container.length === 0) { 608 form.parent().append('<p class="stbMsgArea"></p>'); 609 message_container = form.parent().find('p.stbMsgArea'); 610 } 611 612 sendobj.Box = box_id; 613 sendobj.Page = document.location.href; 614 sendobj.action = 'dgd_stb_form_process'; 615 sendobj.stbNonce = $DGD.nonce; 616 sendobj.Screen_size = $DGD.screenwidth + 'px * ' + $DGD.screenheight + 'px'; 617 form.find('input, textarea, select').each(function () { 618 sendobj[jQuery(this).attr('name')] = jQuery(this).val(); 619 }); 620 621 jQuery.ajax({ 622 url: $DGD.ajaxurl, 623 data: sendobj, 624 dataType: 'json', 625 type: 'post', 626 cache: false, 627 beforeSend: function () { 628 message_container.html('<img src="' + $DGD.scripthost + 'img/37-1.gif" border="0">').show(); 629 }, 630 success: function (response) { 631 message_container.html(response.html).show(); 632 if (response.status === '200') { 633 // set cookie for permanent close 634 $DGD.closeAfterSubmit(box_id); 635 } 636 }, 637 error: function (jqXHR, textStatus, errorThrown) { 638 message_container.html(textStatus + ': ' + errorThrown).show(); 639 } 640 });
641}; 642 643$DGD.generateBox = function (box, boxparent) { 644 var boxdiv, form, newelem; 645 if (typeof box.html === 'string' && box.html !== '') { 646 newelem = document.createElement('div'); 647 newelem.className = 'dgd_stb_box ' + box.theme; 648 newelem.id = box.id; 649 newelem.innerHTML = '<a class="dgd_stb_box_close dgd_stb_box_x" href="javascript:void(0);"> </a>' + box.html; 650 boxdiv = boxparent.appendChild(newelem); 651 } else { 652 boxdiv = document.getElementById(box.id); 653 } 654 if (typeof boxdiv === 'object' && boxdiv) { 655 if (typeof box.theme === 'string' && box.theme.length > 0) { 656 this.loadCss(this.scripthost + 'themes/' + box.theme + '/style.css', boxdiv); 657 } 658 if (typeof box.receiver_email === 'string' && box.receiver_email === '1') { 659 form = jQuery(boxdiv).find('form'); 660 if (typeof form === 'object') { form.submit(this.submitForm); } 661 } 662 return boxdiv; 663 } 664 return false; 665}; 666 667$DGD.mouseEventHandler = function (e) { 668 var box = $DGD.getBoxByElementAction(e); 669 if (box) { 670 $DGD.showBox(box, false); 671 } 672}; 673 674$DGD.scrollboxInit = function () { 675 var is_mobile_user = this.isMobile(navigator.userAgent || navigator.vendor || window.opera), 676 boxparent = document.body, // possibility to append boxes to different elements, use <body> as default 677 i, 678 box, 679 d; 680 681 if (this.scrollboxes.length > 0) { 682 $DGD.overlay = jQuery('.dgd_overlay'); 683 this.measureScreen(); 684 685 for (i = 0; i < this.scrollboxes.length; i++) { 686 box = this.scrollboxes[i]; 687 box.cookieLifetime = parseInt(box.cookieLifetime, 10); 688 if ((typeof box.hide_mobile === 'string') && is_mobile_user) { 689 // this.echo(box.id + ' is disabled for mobile user'); 690 continue; 691 } 692 693 this.generateBox(box, boxparent); 694 this.placeBox(box); 695 this.resizeBox(box); 696 this.calculateBoxPlacement(box); 697 698 this.all_boxes.push(box); 699 700 if (!this.checkCookie(box)) { 701 // closed boxes will be not added to wait arrays, those can be opened only from tab (if exists) 702 if (box.tabid) { 703 $DGD.tabs_to_open.push(box.tabid); 704 } 705 continue; 706 } 707 708 // start timers 709 if (box.trigger.action === 'mouseover' || box.trigger.action === 'click') { 710 if (jQuery(box.trigger.element).length > 0) { 711 jQuery(box.trigger.element).on(box.trigger.action, $DGD.mouseEventHandler); 712 } 713 } 714 715 this.boxes_wait_for_scroll.push(box); 716 } 717 718 if (this.boxes_wait_for_scroll.length > 0) { 719 jQuery(window).scroll(function () {$DGD.didScroll = true; }); 720 jQuery(window).resize(function () {$DGD.didResize = true; }); 721 722 setInterval(function () { 723 if ($DGD.didScroll) { 724 $DGD.didScroll = false; 725 $DGD.calcScroll(); 726 } 727 728 // Monitor screen and content changes and correct boxes placement 729 if ($DGD.didResize) { 730 $DGD.didResize = false; 731 $DGD.measureScreen(); 732 $DGD.fixPosition(); 733 } 734 735 if ($DGD.boxes_wait_for_close.length > 0) { 736 d = Date.now(); 737 for (i = 0; i < $DGD.boxes_wait_for_close.length; i++) { 738 box = $DGD.boxes_wait_for_close[i]; 739 if (box.closingTime < d) { 740 // time to wrap it up 741 box.closed = true; 742 $DGD.hideBox(box); 743 // remove box from queue 744 $DGD.boxes_wait_for_close.splice(i, 1); 745 } 746 } 747 } 748 if ($DGD.boxes_wait_for_open.length > 0) { 749 d = Date.now(); 750 for (i = 0; i < $DGD.boxes_wait_for_open.length; i++) { 751 box = $DGD.boxes_wait_for_open[i];
752 if (box.openingTime < d) { 753 $DGD.showBox(box, false); 754 // remove box from queue 755 $DGD.boxes_wait_for_open.splice(i, 1); 756 } 757 } 758 } 759 }, 333); 760 } 761 762 if ($DGD.tabs_to_open.length > 0) { 763 for (i = 0; i < $DGD.tabs_to_open.length; i++) { 764 $DGD.showBox($DGD.getBoxById($DGD.tabs_to_open[i])); 765 } 766 } 767 768 jQuery('.dgd_stb_box_close').click($DGD.closeBox); 769 jQuery('.dgd_stb_box_close_button').click($DGD.closeBox); 770 // fallback for old layout 771 jQuery('#closebox').click($DGD.closeBox); 772 773 // Bind close action to MailChimp "success" response field change 774 jQuery('.dgd_stb_box #mce-success-response').bind('DOMSubtreeModified', function() { 775 $DGD.closeAfterSubmit(jQuery('#mce-success-response').closest('.dgd_stb_box').attr('id')); 776 }); 777 } 778}; 779 780jQuery(document).ready(function () { $DGD.scrollboxInit(); }); 781 782/* 783TIP Example about triggering scrollboxes resizing from page changing event 784 785if (typeof $DGD === 'object') { 786 jQuery('body').bind('DOMNodeInserted DOMNodeRemoved', function() { $DGD.didResize = true; }); 787} 788 789 790 791*/
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.