1// global object 2BlogEngine = { 3 $: function (id) { 4 return document.getElementById(id); 5 } 6 , 7 setFlag: function (iso) { 8 if (iso.length > 0) 9 BlogEngine.comments.flagImage.src = BlogEngineRes.webRoot + "Content/images/blog/flags/" + iso + ".png"; 10 else 11 BlogEngine.comments.flagImage.src = BlogEngineRes.webRoot + "Content/images/blog/pixel.gif"; 12 } 13 , 14 15 // Shows the preview of the comment 16 showCommentPreview: function () { 17 var oPreview = this.$('preview'); 18 var oCompose = this.$('compose'); 19 20 if (oPreview) oPreview.className = 'selected'; 21 if (oCompose) oCompose.className = ''; 22 this.$('commentCompose').style.display = 'none'; 23 this.$('commentPreview').style.display = 'block'; 24 this.$('commentPreview').innerHTML = '<img src="' + BlogEngineRes.webRoot + 'Content/images/blog/ajax-loader.gif" width="24" height="24" alt="Loading" />'; 25 var argument = this.$('commentPreview').innerHTML; 26 this.addComment(true); 27 return false; 28 } 29 , 30 composeComment: function () { 31 var oPreview = this.$('preview'); 32 var oCompose = this.$('compose'); 33 34 if (oPreview) oPreview.className = ''; 35 if (oCompose) oCompose.className = 'selected'; 36 if (this.$('commentPreview')) { 37 this.$('commentPreview').style.display = 'none'; 38 } 39 if (this.$('commentCompose')) { 40 this.$('commentCompose').style.display = 'block'; 41 } 42 return false; 43 } 44 , 45 endShowPreview: function (arg, context) { 46 if (BlogEngine.$('commentPreview')) { 47 BlogEngine.$('commentPreview').innerHTML = arg; 48 } 49 } 50 , 51 toggleCommentSavingIndicators: function (bSaving) { 52 BlogEngine.$("btnSaveAjax").disabled = bSaving; 53 BlogEngine.$("ajaxLoader").style.display = bSaving ? "inline" : "none"; 54 BlogEngine.$("status").className = ""; 55 BlogEngine.$("status").innerHTML = ""; 56 if (!bSaving) { 57 if (BlogEngine.$('commentPreview')) { 58 BlogEngine.$('commentPreview').innerHTML = ""; 59 } 60 BlogEngine.composeComment(); 61 } 62 } 63 , 64 onCommentError: function (error, context) { 65 BlogEngine.toggleCommentSavingIndicators(false); 66 error = error || "Unknown error occurred."; 67 var iDelimiterPos = error.indexOf("|"); 68 if (iDelimiterPos > 0) { 69 error = error.substr(0, iDelimiterPos); 70 // Remove numbers from end of error message. 71 while (error.length > 0 && error.substr(error.length - 1, 1).match(/\d/)) { 72 error = error.substr(0, error.length - 1); 73 } 74 } 75 76 if (document.getElementById('recaptcha_response_field')) { 77 Recaptcha.reload(); 78 } 79 if (document.getElementById("spnSimpleCaptchaIncorrect")) document.getElementById("spnSimpleCaptchaIncorrect").style.display = "none"; 80 81 alert("Sorry, the following error occurred while processing your comment:\n\n" + error); 82 } 83 , 84 addComment: function (preview) { 85 var isPreview = preview == true; 86 if (!isPreview) { 87 BlogEngine.toggleCommentSavingIndicators(true); 88 this.$("status").innerHTML = BlogEngineRes.i18n.savingTheComment; 89 } 90 var author = BlogEngine.comments.nameBox.value; 91 var email = BlogEngine.comments.emailBox.value; 92 var content = BlogEngine.comments.contentBox.value; 93 var captcha = BlogEngine.comments.captchaField.value; 94 95 var website = BlogEngine.comments.websiteBox ? BlogEngine.comments.websiteBox.value : ""; 96 var country = BlogEngine.comments.countryDropDown ? BlogEngine.comments.countryDropDown.value : ""; 97 var notify = BlogEngine.$("cbNotify") ? BlogEngine.$("cbNotify").checked : false; 98 var replyToId = BlogEngine.comments.replyToId ? BlogEngine.comments.replyToId.value : ""; 99 100 var recaptchaResponseField = document.getElementById('recaptcha_response_field'); 101 var recaptchaResponse = recaptchaResponseField ? recaptchaResponseField.value : ""; 102 103 var recaptchaChallengeField = document.getElementById('recaptcha_challenge_field'); 104 var recaptchaChallenge = recaptchaChallengeField ? recaptchaChallengeField.value : ""; 105 106 var simpleCaptchaChallengeField = document.getElementById('simpleCaptchaValue'); 107 var simpleCaptchaChallenge = simpleCaptchaChallengeField ? simpleCaptchaChallengeField.value : ""; 108 109 var avatarInput = BlogEngine.$("avatarImgSrc"); 110 var avatar = (avatarInput && avatarInput.value) ? avatarInput.value : ""; 111 112 var callback = isPreview ? BlogEngine.endShowPreview : BlogEngine.appendComment;
113 var argument = author + "-|-" + email + "-|-" + website + "-|-" + country + "-|-" + content + "-|-" + notify + "-|-" + isPreview + "-|-" + captcha + "-|-" + replyToId + "-|-" + avatar + "-|-" + recaptchaResponse + "-|-" + recaptchaChallenge + "-|-" + simpleCaptchaChallenge; 114 115 WebForm_DoCallback(BlogEngine.comments.controlId, argument, callback, 'comment', BlogEngine.onCommentError, false); 116 117 if (!isPreview && typeof (OnComment) != "undefined") 118 OnComment(author, email, website, country, content); 119 } 120 , 121 cancelReply: function () { 122 this.replyToComment(''); 123 } 124 , 125 replyToComment: function (id) { 126 127 // set hidden value 128 BlogEngine.comments.replyToId.value = id; 129 130 // move comment form into position 131 var commentForm = BlogEngine.$('comment-form'); 132 if (!id || id == '' || id == null || id == '00000000-0000-0000-0000-000000000000') { 133 // move to after comment list 134 var base = BlogEngine.$("commentlist"); 135 base.appendChild(commentForm); 136 // hide cancel button 137 BlogEngine.$('cancelReply').style.display = 'none'; 138 } else { 139 // show cancel 140 BlogEngine.$('cancelReply').style.display = ''; 141 142 // move to nested position 143 var parentComment = BlogEngine.$('id_' + id); 144 var replies = BlogEngine.$('replies_' + id); 145 146 // add if necessary 147 if (replies == null) { 148 replies = document.createElement('div'); 149 replies.className = 'comment-replies'; 150 replies.id = 'replies_' + id; 151 parentComment.appendChild(replies); 152 } 153 replies.style.display = ''; 154 replies.appendChild(commentForm); 155 } 156 157 BlogEngine.comments.nameBox.focus(); 158 } 159 , 160 appendComment: function (args, context) { 161 if (context == "comment") { 162 163 if (document.getElementById('recaptcha_response_field')) { 164 Recaptcha.reload(); 165 } 166 if (document.getElementById("spnSimpleCaptchaIncorrect")) document.getElementById("spnSimpleCaptchaIncorrect").style.display = "none"; 167 168 if (args == "RecaptchaIncorrect" || args == "SimpleCaptchaIncorrect") { 169 if (document.getElementById("spnCaptchaIncorrect")) document.getElementById("spnCaptchaIncorrect").style.display = ""; 170 if (document.getElementById("spnSimpleCaptchaIncorrect")) document.getElementById("spnSimpleCaptchaIncorrect").style.display = ""; 171 BlogEngine.toggleCommentSavingIndicators(false); 172 } 173 else { 174 175 176 if (document.getElementById("spnCaptchaIncorrect")) document.getElementById("spnCaptchaIncorrect").style.display = "none"; 177 if (document.getElementById("spnSimpleCaptchaIncorrect")) document.getElementById("spnSimpleCaptchaIncorrect").style.display = "none"; 178 179 var commentList = BlogEngine.$("commentlist"); 180 if (commentList.innerHTML.length < 10) 181 commentList.innerHTML = "<h1 id='comment'>" + BlogEngineRes.i18n.comments + "</h1>" 182 183 // add comment html to the right place 184 var id = BlogEngine.comments.replyToId ? BlogEngine.comments.replyToId.value : ''; 185 186 if (id != '') { 187 var replies = BlogEngine.$('replies_' + id); 188 replies.innerHTML += args; 189 } else { 190 commentList.innerHTML += args; 191 commentList.style.display = 'block'; 192 } 193 194 // reset form values 195 BlogEngine.comments.contentBox.value = ""; 196 BlogEngine.comments.contentBox = BlogEngine.$(BlogEngine.comments.contentBox.id); 197 BlogEngine.toggleCommentSavingIndicators(false); 198 BlogEngine.$("status").className = "success"; 199 200 if (!BlogEngine.comments.moderation) 201 BlogEngine.$("status").innerHTML = BlogEngineRes.i18n.commentWasSaved; 202 else 203 BlogEngine.$("status").innerHTML = BlogEngineRes.i18n.commentWaitingModeration; 204 205 // move form back to bottom 206 var commentForm = BlogEngine.$('comment-form');
207 commentList.appendChild(commentForm); 208 // reset reply to 209 if (BlogEngine.comments.replyToId) BlogEngine.comments.replyToId.value = ''; 210 if (BlogEngine.$('cancelReply')) BlogEngine.$('cancelReply').style.display = 'none'; 211 212 } 213 } 214 215 BlogEngine.$("btnSaveAjax").disabled = false; 216 } 217 , 218 validateAndSubmitCommentForm: function () { 219 220 if (BlogEngine.comments.nameBox.value.length < 1) { 221 BlogEngine.$("status").innerHTML = "Required"; 222 BlogEngine.$("status").className = "warning"; 223 BlogEngine.$("txtName").focus(); 224 return false; 225 } 226 if (BlogEngine.comments.emailBox.value.length < 1) { 227 BlogEngine.$("status").innerHTML = "Required"; 228 BlogEngine.$("txtEmail").focus(); 229 return false; 230 } 231 if (BlogEngine.comments.contentBox.value.length < 1) { 232 BlogEngine.$("status").innerHTML = "Required"; 233 BlogEngine.$("txtContent").focus(); 234 return false; 235 } 236 237 //var bBuiltInValidationPasses = Page_ClientValidate('AddComment'); 238 //var bNameIsValid = BlogEngine.comments.nameBox.value.length > 0; 239 240 //document.getElementById('spnNameRequired').style.display = bNameIsValid ? 'none' : ''; 241 //var bAuthorNameIsValid = true; 242 //if (BlogEngine.comments.checkName) { 243 // var author = BlogEngine.comments.postAuthor; 244 // var visitor = BlogEngine.comments.nameBox.value; 245 // bAuthorNameIsValid = !this.equal(author, visitor); 246 //} 247 248 //document.getElementById('spnChooseOtherName').style.display = bAuthorNameIsValid ? 'none' : ''; 249 //if (bBuiltInValidationPasses && bNameIsValid && bAuthorNameIsValid) { 250 // BlogEngine.addComment(); 251 // return true; 252 //} 253 254 BlogEngine.addComment(); 255 return true; 256 } 257 258 , 259 260 addBbCode: function (v) { 261 try { 262 var contentBox = BlogEngine.comments.contentBox; 263 if (contentBox.selectionStart) // firefox 264 { 265 var pretxt = contentBox.value.substring(0, contentBox.selectionStart); 266 var therest = contentBox.value.substr(contentBox.selectionEnd); 267 var sel = contentBox.value.substring(contentBox.selectionStart, contentBox.selectionEnd); 268 contentBox.value = pretxt + "[" + v + "]" + sel + "[/" + v + "]" + therest; 269 contentBox.focus(); 270 } 271 else if (document.selection && document.selection.createRange) // IE 272 { 273 var str = document.selection.createRange().text; 274 contentBox.focus(); 275 var sel = document.selection.createRange(); 276 sel.text = "[" + v + "]" + str + "[/" + v + "]"; 277 } 278 } 279 catch (ex) { } 280 281 return; 282 } 283 , 284 // Searches the blog based on the entered text and 285 // searches comments as well if chosen. 286 search: function (root, searchfield) { 287 if (!searchfield) { 288 searchfield = 'searchfield'; 289 } 290 var input = this.$(searchfield); 291 var check = this.$("searchcomments"); 292 293 var searchPageExtension = typeof BlogEngineRes.fileExtension === "undefined" ? ".aspx" : BlogEngineRes.fileExtension; 294 var search = "search" + searchPageExtension + "?q=" + encodeURIComponent(input.value); 295 if (check != null && check.checked) 296 search += "&comment=true"; 297 298 top.location.href = root + search; 299 300 return false; 301 } 302 , 303 // Clears the search fields on focus. 304 searchClear: function (defaultText, searchfield) { 305 if (!searchfield) { 306 searchfield = 'searchfield'; 307 } 308 var input = this.$(searchfield); 309 if (input.value == defaultText) 310 input.value = ""; 311 else if (input.value == "") 312 input.value = defaultText; 313 } 314 , 315 rate: function (blogId, id, rating) { 316 this.createCallback("rating.axd?id=" + id + "&rating=" + rating, BlogEngine.ratingCallback, blogId); 317 } 318 , 319 ratingCallback: function (response) { 320 var rating = response.substring(0, 1); 321 var status = response.substring(1); 322 323 if (status == "OK") { 324 if (typeof OnRating != "undefined") 325 OnRating(rating); 326 327 alert(BlogEngineRes.i18n.ratingHasBeenRegistered); 328 } 329 else if (status == "HASRATED") { 330 alert(BlogEngineRes.i18n.hasRated); 331 } 332 else { 333 alert("An error occured while registering your rating. Please try again"); 334 } 335 } 336 , 337 /// <summary> 338 /// Creates a client callback back to the requesting page 339 /// and calls the callback method with the response as parameter. 340 /// </summary> 341 createCallback: function (url, callback, blogId) { 342 var http = BlogEngine.getHttpObject(); 343 http.open("GET", url, true); 344 345 if (blogId && http.setRequestHeader) { 346 http.setRequestHeader('x-blog-instance', blogId.toString()); 347 } 348 349 http.onreadystatechange = function () { 350 if (http.readyState == 4) { 351 if (http.responseText.length > 0 && callback != null) 352 callback(http.responseText); 353 } 354 }; 355 356 http.send(null); 357 } 358 , 359 /// <summary> 360 /// Creates a XmlHttpRequest object. 361 /// </summary> 362 getHttpObject: function () { 363 if (typeof XMLHttpRequest != 'undefined') 364 return new XMLHttpRequest(); 365 366 try { 367 return new ActiveXObject("Msxml2.XMLHTTP"); 368 } 369 catch (e) { 370 try { 371 return new ActiveXObject("Microsoft.XMLHTTP"); 372 } 373 catch (e) { } 374 } 375 376 return false; 377 } 378 , 379 // Updates the calendar from client-callback 380 updateCalendar: function (args, context) { 381 var cal = BlogEngine.$('calendarContainer'); 382 cal.innerHTML = args; 383 BlogEngine.Calendar.months[context] = args; 384 } 385 , 386 toggleMonth: function (year) { 387 var monthList = BlogEngine.$("monthList"); 388 var years = monthList.getElementsByTagName("ul"); 389 for (i = 0; i < years.length; i++) { 390 if (years[i].id == year) { 391 var state = years[i].className == "open" ? "" : "open"; 392 years[i].className = state; 393 break; 394 } 395 } 396 } 397 , 398 // Adds a trim method to all strings. 399 equal: function (first, second) { 400 var f = first.toLowerCase().replace(new RegExp(' ', 'gi'), ''); 401 var s = second.toLowerCase().replace(new RegExp(' ', 'gi'), ''); 402 return f == s; 403 } 404 , 405 /*----------------------------------------------------------------------------- 406 XFN HIGHLIGHTER 407 -----------------------------------------------------------------------------*/ 408 xfnRelationships: ['friend', 'acquaintance', 'contact', 'met' 409 , 'co-worker', 'colleague', 'co-resident' 410 , 'neighbor', 'child', 'parent', 'sibling' 411 , 'spouse', 'kin', 'muse', 'crush', 'date' 412 , 'sweetheart', 'me'] 413 , 414 // Applies the XFN tags of a link to the title tag 415 hightLightXfn: function () { 416 var content = BlogEngine.$('content'); 417 if (content == null) 418 return; 419 420 var links = content.getElementsByTagName('a'); 421 for (i = 0; i < links.length; i++) { 422 var link = links[i]; 423 var rel = link.getAttribute('rel'); 424 if (rel && rel != "nofollow") { 425 for (j = 0; j < BlogEngine.xfnRelationships.length; j++) { 426 if (rel.indexOf(BlogEngine.xfnRelationships[j]) > -1) { 427 link.title = 'XFN relationship: ' + rel; 428 break; 429 } 430 } 431 } 432 } 433 } 434 , 435 436 showRating: function (container, id, raters, rating, blogId) { 437 var div = document.createElement('div'); 438 div.className = 'rating'; 439 440 var p = document.createElement('p'); 441 div.appendChild(p); 442 if (raters == 0) { 443 p.innerHTML = BlogEngineRes.i18n.beTheFirstToRate; 444 } 445 else { 446 p.innerHTML = BlogEngineRes.i18n.currentlyRated.replace('{0}', new Number(rating).toFixed(1)).replace('{1}', raters); 447 } 448 449 var ul = document.createElement('ul'); 450 ul.className = 'star-rating small-star'; 451 div.appendChild(ul); 452 453 var li = document.createElement('li'); 454 li.className = 'current-rating'; 455 li.style.width = Math.round(rating * 20) + '%'; 456 li.innerHTML = 'Currently ' + rating + '/5 Stars.'; 457 ul.appendChild(li); 458 459 for (var i = 1; i <= 5; i++) { 460 var l = document.createElement('li'); 461 var a = document.createElement('a'); 462 a.innerHTML = i; 463 a.href = 'rate/' + i; 464 a.className = this.englishNumber(i); 465 a.title = BlogEngineRes.i18n.rateThisXStars.replace('{0}', i.toString()).replace('{1}', i == 1 ? '' : 's'); 466 a.rel = "nofollow"; 467 a.onclick = function () { 468 BlogEngine.rate(blogId, id, this.innerHTML); 469 return false; 470 }; 471 472 l.appendChild(a); 473 ul.appendChild(l); 474 } 475 476 container.innerHTML = ''; 477 container.appendChild(div); 478 container.style.visibility = 'visible'; 479 } 480 , 481 482 applyRatings: function () { 483 var divs = document.getElementsByTagName('div'); 484 for (var i = 0; i < divs.length; i++) { 485 if (divs[i].className == 'ratingcontainer') { 486 var args = divs[i].innerHTML.split('|'); 487 BlogEngine.showRating(divs[i], args[0], args[1], args[2], args[3]); 488 } 489 } 490 }, 491 492 englishNumber: function (number) { 493 if (number == 1) 494 return 'one-star'; 495 496 if (number == 2) 497 return 'two-stars'; 498 499 if (number == 3) 500 return 'three-stars'; 501 502 if (number == 4) 503 return 'four-stars'; 504 505 return 'five-stars'; 506 } 507 , 508 // Adds event to window.onload without overwriting currently assigned onload functions. 509 // Function found at Simon Willison's weblog - http://simon.incutio.com/ 510 addLoadEvent: function (func) { 511 var oldonload = window.onload; 512 if (typeof window.onload != 'function') { 513 window.onload = func; 514 } 515 else { 516 window.onload = function () { 517 oldonload(); 518 func(); 519 } 520 } 521 } 522 , 523 filterByAPML: function () { 524 var width = document.documentElement.clientWidth + document.documentElement.scrollLeft; 525 var height = document.documentElement.clientHeight + document.documentElement.scrollTop; 526 document.body.style.position = 'static'; 527 528 var layer = document.createElement('div'); 529 layer.style.zIndex = 2; 530 layer.id = 'layer'; 531 layer.style.position = 'absolute'; 532 layer.style.top = '0px'; 533 layer.style.left = '0px'; 534 layer.style.height = document.documentElement.scrollHeight + 'px'; 535 layer.style.width = width + 'px'; 536 layer.style.backgroundColor = 'black'; 537 layer.style.opacity = '.6'; 538 layer.style.filter += ("progid:DXImageTransform.Microsoft.Alpha(opacity=60)"); 539 document.body.appendChild(layer); 540 541 var div = document.createElement('div'); 542 div.style.zIndex = 3; 543 div.id = 'apmlfilter'; 544 div.style.position = (navigator.userAgent.indexOf('MSIE 6') > -1) ? 'absolute' : 'fixed'; 545 div.style.top = '200px'; 546 div.style.left = (width / 2) - (400 / 2) + 'px'; 547 div.style.height = '50px'; 548 div.style.width = '400px'; 549 div.style.backgroundColor = 'white'; 550 div.style.border = '2px solid silver'; 551 div.style.padding = '20px'; 552 document.body.appendChild(div); 553 554 var p = document.createElement('p'); 555 p.innerHTML = BlogEngineRes.i18n.apmlDescription; 556 p.style.margin = '0px'; 557 div.appendChild(p); 558 559 var form = document.createElement('form'); 560 form.method = 'get'; 561 form.style.display = 'inline'; 562 form.action = BlogEngineRes.webRoot; 563 div.appendChild(form); 564 565 var textbox = document.createElement('input'); 566 textbox.type = 'text'; 567 textbox.value = BlogEngine.getCookieValue('url') || 'http://'; 568 textbox.style.width = '320px'; 569 textbox.id = 'txtapml'; 570 textbox.name = 'apml'; 571 textbox.style.background = 'url(' + BlogEngineRes.webRoot + 'Content/images/blog/apml.png) no-repeat 2px center'; 572 textbox.style.paddingLeft = '16px'; 573 form.appendChild(textbox); 574 textbox.focus(); 575 576 var button = document.createElement('input'); 577 button.type = 'submit'; 578 button.value = BlogEngineRes.i18n.filter; 579 button.onclick = function () { location.href = BlogEngineRes.webRoot + '?apml=' + encodeURIComponent(BlogEngine.$('txtapml').value); }; 580 form.appendChild(button); 581 582 var br = document.createElement('br'); 583 div.appendChild(br); 584 585 var a = document.createElement('a'); 586 a.innerHTML = BlogEngineRes.i18n.cancel; 587 a.href = 'javascript:void(0)'; 588 a.onclick = function () { document.body.removeChild(BlogEngine.$('layer')); document.body.removeChild(BlogEngine.$('apmlfilter')); document.body.style.position = ''; }; 589 div.appendChild(a); 590 } 591 , 592 getCookieValue: function (name) { 593 var cookie = new String(document.cookie); 594 595 if (cookie != null && cookie.indexOf('comment=') > -1) { 596 var start = cookie.indexOf(name + '=') + name.length + 1; 597 var end = cookie.indexOf('&', start); 598 if (end > start && start > -1) 599 return cookie.substring(start, end); 600 } 601 602 return null; 603 } 604 , 605 test: function () { 606 alert('test'); 607 } 608 , 609 comments: { 610 flagImage: null, 611 contentBox: null, 612 moderation: null, 613 checkName: null, 614 postAuthor: null, 615 nameBox: null, 616 emailBox: null, 617 websiteBox: null, 618 countryDropDown: null, 619 captchaField: null, 620 controlId: null, 621 replyToId: null 622 } 623}; 624 625BlogEngine.addLoadEvent(BlogEngine.hightLightXfn); 626 627// add this to global if it doesn't exist yet 628if (typeof ($) == 'undefined') 629 window.$ = BlogEngine.$; 630 631// apply ratings after registerVariables. 632BlogEngine.addLoadEvent(BlogEngine.applyRatings);
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.