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 = "Name is 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 = "Email is required."; 228 BlogEngine.$("status").className = "warning"; 229 BlogEngine.$("txtEmail").focus(); 230 return false; 231 } 232 if (BlogEngine.comments.contentBox.value.length < 1) { 233 BlogEngine.$("status").innerHTML = "Comment is required."; 234 BlogEngine.$("status").className = "warning"; 235 BlogEngine.$("txtContent").focus(); 236 return false; 237 } 238 239 //var bBuiltInValidationPasses = Page_ClientValidate('AddComment'); 240 //var bNameIsValid = BlogEngine.comments.nameBox.value.length > 0; 241 242 //document.getElementById('spnNameRequired').style.display = bNameIsValid ? 'none' : ''; 243 //var bAuthorNameIsValid = true; 244 //if (BlogEngine.comments.checkName) { 245 // var author = BlogEngine.comments.postAuthor; 246 // var visitor = BlogEngine.comments.nameBox.value; 247 // bAuthorNameIsValid = !this.equal(author, visitor); 248 //} 249 250 //document.getElementById('spnChooseOtherName').style.display = bAuthorNameIsValid ? 'none' : ''; 251 //if (bBuiltInValidationPasses && bNameIsValid && bAuthorNameIsValid) { 252 // BlogEngine.addComment(); 253 // return true; 254 //} 255 256 BlogEngine.addComment(); 257 return true; 258 } 259 260 , 261 262 addBbCode: function (v) { 263 try { 264 var contentBox = BlogEngine.comments.contentBox; 265 if (contentBox.selectionStart) // firefox 266 { 267 var pretxt = contentBox.value.substring(0, contentBox.selectionStart); 268 var therest = contentBox.value.substr(contentBox.selectionEnd); 269 var sel = contentBox.value.substring(contentBox.selectionStart, contentBox.selectionEnd); 270 contentBox.value = pretxt + "[" + v + "]" + sel + "[/" + v + "]" + therest; 271 contentBox.focus(); 272 } 273 else if (document.selection && document.selection.createRange) // IE 274 { 275 var str = document.selection.createRange().text; 276 contentBox.focus(); 277 var sel = document.selection.createRange(); 278 sel.text = "[" + v + "]" + str + "[/" + v + "]"; 279 } 280 } 281 catch (ex) { } 282 283 return; 284 } 285 , 286 // Searches the blog based on the entered text and 287 // searches comments as well if chosen. 288 search: function (root, searchfield) { 289 if (!searchfield) { 290 searchfield = 'searchfield'; 291 } 292 var input = this.$(searchfield); 293 var check = this.$("searchcomments"); 294 295 var searchPageExtension = typeof BlogEngineRes.fileExtension === "undefined" ? ".aspx" : BlogEngineRes.fileExtension; 296 var search = "search" + searchPageExtension + "?q=" + encodeURIComponent(input.value); 297 if (check != null && check.checked) 298 search += "&comment=true"; 299 300 top.location.href = root + search; 301 302 return false; 303 } 304 , 305 // Clears the search fields on focus. 306 searchClear: function (defaultText, searchfield) { 307 if (!searchfield) { 308 searchfield = 'searchfield'; 309 } 310 var input = this.$(searchfield); 311 if (input.value == defaultText) 312 input.value = ""; 313 else if (input.value == "") 314 input.value = defaultText; 315 } 316 , 317 rate: function (blogId, id, rating) { 318 this.createCallback("rating.axd?id=" + id + "&rating=" + rating, BlogEngine.ratingCallback, blogId); 319 } 320 , 321 ratingCallback: function (response) { 322 var rating = response.substring(0, 1); 323 var status = response.substring(1); 324 325 if (status == "OK") { 326 if (typeof OnRating != "undefined") 327 OnRating(rating); 328 329 alert(BlogEngineRes.i18n.ratingHasBeenRegistered); 330 } 331 else if (status == "HASRATED") { 332 alert(BlogEngineRes.i18n.hasRated); 333 } 334 else { 335 alert("An error occured while registering your rating. Please try again"); 336 } 337 } 338 , 339 /// <summary> 340 /// Creates a client callback back to the requesting page 341 /// and calls the callback method with the response as parameter. 342 /// </summary> 343 createCallback: function (url, callback, blogId) { 344 var http = BlogEngine.getHttpObject(); 345 http.open("GET", url, true); 346 347 if (blogId && http.setRequestHeader) { 348 http.setRequestHeader('x-blog-instance', blogId.toString()); 349 } 350 351 http.onreadystatechange = function () { 352 if (http.readyState == 4) { 353 if (http.responseText.length > 0 && callback != null) 354 callback(http.responseText); 355 } 356 }; 357 358 http.send(null); 359 } 360 , 361 /// <summary> 362 /// Creates a XmlHttpRequest object. 363 /// </summary> 364 getHttpObject: function () { 365 if (typeof XMLHttpRequest != 'undefined') 366 return new XMLHttpRequest(); 367 368 try { 369 return new ActiveXObject("Msxml2.XMLHTTP"); 370 } 371 catch (e) { 372 try { 373 return new ActiveXObject("Microsoft.XMLHTTP"); 374 } 375 catch (e) { } 376 } 377 378 return false;
379 } 380 , 381 // Updates the calendar from client-callback 382 updateCalendar: function (args, context) { 383 var cal = BlogEngine.$('calendarContainer'); 384 cal.innerHTML = args; 385 BlogEngine.Calendar.months[context] = args; 386 } 387 , 388 toggleMonth: function (year) { 389 var monthList = BlogEngine.$("monthList"); 390 var years = monthList.getElementsByTagName("ul"); 391 for (i = 0; i < years.length; i++) { 392 if (years[i].id == year) { 393 var state = years[i].className == "open" ? "" : "open"; 394 years[i].className = state; 395 break; 396 } 397 } 398 } 399 , 400 // Adds a trim method to all strings. 401 equal: function (first, second) { 402 var f = first.toLowerCase().replace(new RegExp(' ', 'gi'), ''); 403 var s = second.toLowerCase().replace(new RegExp(' ', 'gi'), ''); 404 return f == s; 405 } 406 , 407 /*----------------------------------------------------------------------------- 408 XFN HIGHLIGHTER 409 -----------------------------------------------------------------------------*/ 410 xfnRelationships: ['friend', 'acquaintance', 'contact', 'met' 411 , 'co-worker', 'colleague', 'co-resident' 412 , 'neighbor', 'child', 'parent', 'sibling' 413 , 'spouse', 'kin', 'muse', 'crush', 'date' 414 , 'sweetheart', 'me'] 415 , 416 // Applies the XFN tags of a link to the title tag 417 hightLightXfn: function () { 418 var content = BlogEngine.$('content'); 419 if (content == null) 420 return; 421 422 var links = content.getElementsByTagName('a'); 423 for (i = 0; i < links.length; i++) { 424 var link = links[i]; 425 var rel = link.getAttribute('rel'); 426 if (rel && rel != "nofollow") { 427 for (j = 0; j < BlogEngine.xfnRelationships.length; j++) { 428 if (rel.indexOf(BlogEngine.xfnRelationships[j]) > -1) { 429 link.title = 'XFN relationship: ' + rel; 430 break; 431 } 432 } 433 } 434 } 435 } 436 , 437 438 showRating: function (container, id, raters, rating, blogId) { 439 var div = document.createElement('div'); 440 div.className = 'rating'; 441 442 var p = document.createElement('p'); 443 div.appendChild(p); 444 if (raters == 0) { 445 p.innerHTML = BlogEngineRes.i18n.beTheFirstToRate; 446 } 447 else { 448 p.innerHTML = BlogEngineRes.i18n.currentlyRated.replace('{0}', new Number(rating).toFixed(1)).replace('{1}', raters); 449 } 450 451 var ul = document.createElement('ul'); 452 ul.className = 'star-rating small-star'; 453 div.appendChild(ul); 454 455 var li = document.createElement('li'); 456 li.className = 'current-rating'; 457 li.style.width = Math.round(rating * 20) + '%'; 458 li.innerHTML = 'Currently ' + rating + '/5 Stars.'; 459 ul.appendChild(li); 460 461 for (var i = 1; i <= 5; i++) { 462 var l = document.createElement('li'); 463 var a = document.createElement('a'); 464 a.innerHTML = i; 465 a.href = 'rate/' + i; 466 a.className = this.englishNumber(i); 467 a.title = BlogEngineRes.i18n.rateThisXStars.replace('{0}', i.toString()).replace('{1}', i == 1 ? '' : 's'); 468 a.rel = "nofollow"; 469 a.onclick = function () { 470 BlogEngine.rate(blogId, id, this.innerHTML); 471 return false; 472 }; 473 474 l.appendChild(a); 475 ul.appendChild(l); 476 } 477 478 container.innerHTML = ''; 479 container.appendChild(div); 480 container.style.visibility = 'visible'; 481 } 482 , 483 484 applyRatings: function () { 485 var divs = document.getElementsByTagName('div'); 486 for (var i = 0; i < divs.length; i++) { 487 if (divs[i].className == 'ratingcontainer') { 488 var args = divs[i].innerHTML.split('|'); 489 BlogEngine.showRating(divs[i], args[0], args[1], args[2], args[3]); 490 } 491 } 492 }, 493 494 englishNumber: function (number) { 495 if (number == 1) 496 return 'one-star'; 497 498 if (number == 2) 499 return 'two-stars'; 500 501 if (number == 3) 502 return 'three-stars'; 503 504 if (number == 4) 505 return 'four-stars'; 506 507 return 'five-stars'; 508 } 509 , 510 // Adds event to window.onload without overwriting currently assigned onload functions. 511 // Function found at Simon Willison's weblog - http://simon.incutio.com/ 512 addLoadEvent: function (func) { 513 var oldonload = window.onload; 514 if (typeof window.onload != 'function') { 515 window.onload = func; 516 } 517 else { 518 window.onload = function () { 519 oldonload(); 520 func(); 521 } 522 } 523 } 524 , 525 filterByAPML: function () { 526 var width = document.documentElement.clientWidth + document.documentElement.scrollLeft; 527 var height = document.documentElement.clientHeight + document.documentElement.scrollTop; 528 document.body.style.position = 'static'; 529 530 var layer = document.createElement('div'); 531 layer.style.zIndex = 2; 532 layer.id = 'layer'; 533 layer.style.position = 'absolute'; 534 layer.style.top = '0px'; 535 layer.style.left = '0px'; 536 layer.style.height = document.documentElement.scrollHeight + 'px'; 537 layer.style.width = width + 'px'; 538 layer.style.backgroundColor = 'black'; 539 layer.style.opacity = '.6'; 540 layer.style.filter += ("progid:DXImageTransform.Microsoft.Alpha(opacity=60)"); 541 document.body.appendChild(layer); 542 543 var div = document.createElement('div'); 544 div.style.zIndex = 3; 545 div.id = 'apmlfilter'; 546 div.style.position = (navigator.userAgent.indexOf('MSIE 6') > -1) ? 'absolute' : 'fixed'; 547 div.style.top = '200px'; 548 div.style.left = (width / 2) - (400 / 2) + 'px'; 549 div.style.height = '50px'; 550 div.style.width = '400px'; 551 div.style.backgroundColor = 'white'; 552 div.style.border = '2px solid silver'; 553 div.style.padding = '20px'; 554 document.body.appendChild(div); 555 556 var p = document.createElement('p'); 557 p.innerHTML = BlogEngineRes.i18n.apmlDescription; 558 p.style.margin = '0px'; 559 div.appendChild(p); 560 561 var form = document.createElement('form'); 562 form.method = 'get'; 563 form.style.display = 'inline'; 564 form.action = BlogEngineRes.webRoot; 565 div.appendChild(form); 566 567 var textbox = document.createElement('input'); 568 textbox.type = 'text'; 569 textbox.value = BlogEngine.getCookieValue('url') || 'http://'; 570 textbox.style.width = '320px'; 571 textbox.id = 'txtapml'; 572 textbox.name = 'apml'; 573 textbox.style.background = 'url(' + BlogEngineRes.webRoot + 'Content/images/blog/apml.png) no-repeat 2px center'; 574 textbox.style.paddingLeft = '16px'; 575 form.appendChild(textbox); 576 textbox.focus(); 577 578 var button = document.createElement('input'); 579 button.type = 'submit'; 580 button.value = BlogEngineRes.i18n.filter; 581 button.onclick = function () { location.href = BlogEngineRes.webRoot + '?apml=' + encodeURIComponent(BlogEngine.$('txtapml').value); }; 582 form.appendChild(button); 583 584 var br = document.createElement('br'); 585 div.appendChild(br); 586 587 var a = document.createElement('a'); 588 a.innerHTML = BlogEngineRes.i18n.cancel; 589 a.href = 'javascript:void(0)'; 590 a.onclick = function () { document.body.removeChild(BlogEngine.$('layer')); document.body.removeChild(BlogEngine.$('apmlfilter')); document.body.style.position = ''; }; 591 div.appendChild(a); 592 } 593 , 594 getCookieValue: function (name) { 595 var cookie = new String(document.cookie); 596 597 if (cookie != null && cookie.indexOf('comment=') > -1) { 598 var start = cookie.indexOf(name + '=') + name.length + 1; 599 var end = cookie.indexOf('&', start); 600 if (end > start && start > -1) 601 return cookie.substring(start, end); 602 } 603 604 return null; 605 } 606 , 607 test: function () { 608 alert('test'); 609 } 610 , 611 comments: { 612 flagImage: null, 613 contentBox: null, 614 moderation: null, 615 checkName: null, 616 postAuthor: null, 617 nameBox: null, 618 emailBox: null, 619 websiteBox: null, 620 countryDropDown: null, 621 captchaField: null, 622 controlId: null, 623 replyToId: null 624 } 625}; 626 627BlogEngine.addLoadEvent(BlogEngine.hightLightXfn); 628 629// add this to global if it doesn't exist yet 630if (typeof ($) == 'undefined') 631 window.$ = BlogEngine.$; 632 633// apply ratings after registerVariables. 634BlogEngine.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.