PageSourceSearch

http://www.yunokuni.com/mt.js

js yunokuni.com collected 2026-10-02 11:48:30 UTC 33,423 bytes, 1,130 lines download raw bytes

1// The cookie name to use for storing the blog-side comment session cookie.
2var mtCookieName = "mt_blog_user";
3var mtCookieDomain = ".yunokuni.com";
4var mtCookiePath = "/";
5var mtCookieTimeout = 14400;
6
7
8function mtHide(id) {
9    var el = (typeof id == "string") ? document.getElementById(id) : id;
10    if (el) el.style.display = 'none';
11}
12
13
14function mtShow(id) {
15    var el = (typeof id == "string") ? document.getElementById(id) : id;
16    if (el) el.style.display = 'block';
17}
18
19
20function mtAttachEvent(eventName,func) {
21    var onEventName = 'on' + eventName;
22    var old = window[onEventName];
23    if( typeof old != 'function' )
24        window[onEventName] = func;
25    else {
26        window[onEventName] = function( evt ) {
27            old( evt );
28            return func( evt );
29        };
30    }
31}
32
33
34function mtFireEvent(eventName,param) {
35    var fn = window['on' + eventName];
36    if (typeof fn == 'function') return fn(param);
37    return;
38}
39
40if(!this.JSON){JSON={};}(function(){function f(n){return n<10?'0'+n:n;}if(typeof Date.prototype.toJSON!=='function'){Date.prototype.toJSON=function(key){return this.getUTCFullYear()+'-'+f(this.getUTCMonth()+1)+'-'+f(this.getUTCDate())+'T'+f(this.getUTCHours())+':'+f(this.getUTCMinutes())+':'+f(this.getUTCSeconds())+'Z';};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(key){return this.valueOf();};}var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'},rep;function quote(string){escapable.lastIndex=0;return escapable.test(string)?'"'+string.replace(escapable,function(a){var c=meta[a];return typeof c==='string'?c:'\\u'+('0000'+a.charCodeAt(0).toString(16)).slice(-4);})+'"':'"'+string+'"';}function str(key,holder){var i,k,v,length,mind=gap,partial,value=holder[key];if(value&&typeof value==='object'&&typeof value.toJSON==='function'){value=value.toJSON(key);}if(typeof rep==='function'){value=rep.call(holder,key,value);}switch(typeof value){case'string':return quote(value);case'number':return isFinite(value)?String(value):'null';case'boolean':case'null':return String(value);case'object':if(!value){return'null';}gap+=indent;partial=[];if(Object.prototype.toString.apply(value)==='[object Array]'){length=value.length;for(i=0;i<length;i+=1){partial[i]=str(i,value)||'null';}v=partial.length===0?'[]':gap?'[\n'+gap+partial.join(',\n'+gap)+'\n'+mind+']':'['+partial.join(',')+']';gap=mind;return v;}if(rep&&typeof rep==='object'){length=rep.length;for(i=0;i<length;i+=1){k=rep[i];if(typeof k==='string'){v=str(k,value);if(v){partial.push(quote(k)+(gap?': ':':')+v);}}}}else{for(k in value){if(Object.hasOwnProperty.call(value,k)){v=str(k,value);if(v){partial.push(quote(k)+(gap?': ':':')+v);}}}}v=partial.length===0?'{}':gap?'{\n'+gap+partial.join(',\n'+gap)+'\n'+mind+'}':'{'+partial.join(',')+'}';gap=mind;return v;}}if(typeof JSON.stringify!=='function'){JSON.stringify=function(value,replacer,space){var i;gap='';indent='';if(typeof space==='number'){for(i=0;i<space;i+=1){indent+=' ';}}else if(typeof space==='string'){indent=space;}rep=replacer;if(replacer&&typeof replacer!=='function'&&(typeof replacer!=='object'||typeof replacer.length!=='number')){throw new Error('JSON.stringify');}return str('',{'':value});};}if(typeof JSON.parse!=='function'){JSON.parse=function(text,reviver){var j;function walk(holder,key){var k,v,value=holder[key];if(value&&typeof value==='object'){for(k in value){if(Object.hasOwnProperty.call(value,k)){v=walk(value,k);if(v!==undefined){value[k]=v;}else{delete value[k];}}}}return reviver.call(holder,key,value);}cx.lastIndex=0;if(cx.test(text)){text=text.replace(cx,function(a){return'\\u'+('0000'+a.charCodeAt(0).toString(16)).slice(-4);});}if(/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,'@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']').replace(/(?:^|:|,)(?:\s*\[)+/g,''))){j=eval('('+text+')');return typeof reviver==='function'?walk({'':j},''):j;}throw new SyntaxError('JSON.parse');};}}());
41
42var MT = window.MT || {};
43
44MT.cons = function () {
45  return {
46    LOG : 'log',
47    WARN : 'warn',
48    DEBUG : 'debug',
49    INFO : 'info',
50    ERR : 'error',
51    JSON : 'json'
52  };
53}();
54
55
56MT.core = function (o) {
57  var _debug = false;
58  
59  return {
60    
61    connect : function (url,respType,respHandler) {
62      var xh = mtGetXmlHttp();
63      if (!xh) return false;
64      
65      xh.onreadystatechange = function() {
66        if ( xh.readyState == 4 ) {
67          if ( xh.status && ( xh.status != 200 ) ) {
68            // error - ignore
69          } else {
70            switch (respType) {
71              case 'json':
72                respHandler(JSON.parse(xh.responseText));
73                break;
74                
75              case 'xml':
76                break;
77                
78              case 'text':
79                break;
80            }
81          }
82        }
83      };
84      
85      xh.open('GET',url);
86      xh.send(null);
87    },
88    
89    getEl : function (el) {
90      return MT.util.checkNodeType(el)==='element' ? id : (document.getElementById(el) || false);
91    },
92    
93    addEvent : function (el,type,func,obj) {
94      if(!obj && document.addEventListener) {
95        el.addEventListener(type,func,false);
96      } else if(obj && document.addEventListener) {
97        el.addEventListener(type,function () {
98          func.call(obj,event);
99        },false);
100      } else {
101        if(obj) {
102          el.attachEvent('on' + type,function () {
103            func.call(obj,event);
104          });
105        } else {
106          el.attachEvent('on' + type,function () {          
107            func.call(el,event);
108          });
109        }
110      }
111    },
112    
113    
114    log : function (level,msg) {
115      if(_debug && window.console) {
116        switch(level) {
117          case 'warn':
118          case 'debug':
119          case 'info':
120          case 'error':
121          case 'log':
122            console[level](msg);
123            break;
124            
125          default:
126            return false; 
127        }
128      } else {
129        return false;
130      }
131    }
132  }
133}();
134
135
136MT.util = function () {
137  return {
138    toggleVisibility : {
139      show : function () {
140        var i = arguments.length;
141        
142        while(i--) {
143          if(MT.util.checkNodeType(arguments[i])==='element') {
144            arguments[i].style.visibility = 'visible';
145          } else {
146            MT.core.getEl(arguments[i]).style.visibility = 'visible';
147          }
148        }
149      },
150      
151      hide : function () {
152        var i = arguments.length;
153        while(i--) {
154          if(MT.util.checkNodeType(arguments[i])==='element') {
155            arguments[i].style.visibility = 'hidden';
156          } else {
157            MT.core.getEl(arguments[i]).style.visibility = 'hidden';
158          }
159        }
160      }
161    },
162    
163    toggleDisplay : {
164      show : function () {
165        var i = arguments.length;
166        while(i--) {
167          if(MT.util.checkNodeType(arguments[i])==='element') {
168            arguments[i].style.display = '';
169          } else {
170            MT.core.getEl(arguments[i]).style.display = '';
171          }
172        }
173      },
174      
175      hide : function () {
176        var i = arguments.length;
177        while(i--) {
178          if(MT.util.checkNodeType(arguments[i])==='element') {
179            arguments[i].style.display = 'none';
180          } else {
181            MT.core.getEl(arguments[i]).style.display = 'none';
182          }
183        }
184      }
185    },
186    
187    
188    findDefiningParent : function (origin) {
189      if(MT.util.checkNodeType(origin)==='element') {
190        for(var node=origin.parentNode;node.parentNode;node=node.parentNode) {
191          if((node.hasAttribute && node.hasAttribute('id')) || node.getAttribute('id')) {
192            return node;
193          }
194        }
195      }
196      return false;
197    },
198    
199    
200    checkNodeType : function (obj) {
201      if (obj && obj.nodeName){
202        switch (obj.nodeType) {
203          case 1: return 'element';
204          case 3: return (/\S/).test(obj.nodeValue) ? 'textnode' : 'whitespace';
205        }
206      }
207    }
208  }
209}();
210
211
212(function () {
213  var M = MT.core,
214      c = MT.cons,
215      u = MT.util,
216      cache,
217      isLoading,
218      direction,
219      currentComments,
220      commentAnchor,
221      commentArrId,
222      commentsPerPage,
223      commentsTotalPages,
224      loadingIcon,
225      pageNum,
226      commentsOffset,
227      totalComments,
228      entryID,
229      commentContentDiv,
230      topNav,
231      nav,
232      currentCommentsSpan,
233      topCurrentCommentsSpan;
234            
235  M.addEvent(window,'load',_init);
236  
237  /**
238   * Initializes the class
239   * 
240   * @return void
241   */
242  function _init () {
243    if(!MT.entryCommentCount) {
244      return;
245    }
246    
247    _initializeVariables();
248    _setCommentOffset(false);
249    _checkForAnchor();
250		_setCurrentComments();
251    _toggleNavLinks();
252    _initializeEvents();
253  }
254  
255  
256  function _initializeVariables() {
257    cache = {};
258    isLoading = false;
259    commentAnchor = '';
260    commentArrId = '';
261    commentsPerPage = MT.commentsPerPage || 50;
262    currentComments = '';
263    direction = 'ascend';
264    entryID = MT.entryID;
265    totalComments = MT.entryCommentCount;
266    commentsTotalPages = Math.ceil(totalComments / commentsPerPage);
267    pageNum = 1;
268    
269    loadingIcon = "<img title='Loading...' src='http://yunokuni.com/mt5/mt-static/images/indicator.white.gif' alt='Loading' />";
270    
271    commentContentDiv = M.getEl("comments-content");
272    topNav = M.getEl("top-comment-nav");
273    nav = M.getEl("comment-nav");
274    
275    currentCommentsSpan = M.getEl("current-comments");
276    topCurrentCommentsSpan = M.getEl("top-current-comments");
277  }
278  
279  function _initializeEvents() {
280    if (commentsPerPage < totalComments) {
281      M.addEvent(nav,'click',_handleEvents);
282      M.addEvent(topNav,'click',_handleEvents);
283    }
284  }
285  
286  
287  function _checkForAnchor() {
288    var found = String(window.location.hash).match( /comment-(\d{1,6})/ );
289		
290		if (found) {
291		  M.log(c.DEBUG,found);
292			if (!M.getEl(found[0]).hasOwnProperty('className')) {
293				if (_findIdMatch(found[1])) {
294    			pageNum = Math.floor(commentArrId / commentsPerPage) + 1;
295    			M.log(c.DEBUG,'Comment Array Id: ' + commentArrId);
296    			M.log(c.DEBUG,'Comments Per Page: ' + commentsPerPage);
297    			M.log(c.DEBUG,'Page Number: ' + pageNum);
298    			M.log(c.DEBUG,'Comment Offset: ' + _getCommentOffset());
299    			_updateComments();
300    		}
301			}
302		}
303  }
304  
305  
306  function _setCommentOffset() {
307    commentsOffset = commentsPerPage * (pageNum-1);
308  }
309  
310  
311  function _getCommentOffset() {
312    return commentsOffset;
313  }
314  
315  
316  function _handleEvents (e) {
317    var origin = e.target || e.srcElement,
318        parentId;
319        
320    // stupid IE
321    origin = origin.id && M.getEl(origin.id) || false;
322
323    if(origin) {
324      parentId = u.checkNodeType(origin.parentNode)==='element' && origin.parentNode.getAttribute('id') && origin.parentNode.id;
325    } else {
326      return false;
327    }
328    
329    switch(origin.nodeName) {
330      case 'A':
331        switch (parentId) {
332          case 'prev-comments':
333          case 'top-prev-comments':
334            if(e.preventDefault) {
335              e.preventDefault();
336            } else {
337              e.returnValue =	false;
338            }
339            if(!isLoading) {
340              _previousPage();
341            }
342            break;
343          case 'next-comments':
344          case 'top-next-comments':
345            if(e.preventDefault) {
346              e.preventDefault();
347            } else {
348              e.returnValue =	false;
349            }
350            if(!isLoading) {
351              _nextPage();
352            }
353            break;
354        }
355        break;
356    }
357  }
358  
359  
360  function _toggleNavLinks () {
361    M.log(c.DEBUG,M.getEl('top-prev-comments'));
362    if(pageNum <= commentsTotalPages && pageNum !== 1) {
363      u.toggleVisibility.show('prev-comments');
364      u.toggleVisibility.show('top-prev-comments');
365    }
366    
367    if(pageNum >= 1 && pageNum !== commentsTotalPages) {
368      u.toggleVisibility.show('next-comments');
369      u.toggleVisibility.show('top-next-comments');
370    }
371    
372    if(pageNum===1 || nav.style.visibility==='hidden') {
373      u.toggleVisibility.hide('prev-comments');
374      u.toggleVisibility.hide('top-prev-comments');
375    }
376    
377    if(pageNum===commentsTotalPages || nav.style.visibility==='hidden') {
378      u.toggleVisibility.hide('next-comments');
379      u.toggleVisibility.hide('top-next-comments');
380    }
381  }
382  
383  
384  function _nextPage () {
385    if(pageNum < commentsTotalPages) {
386      pageNum++;
387      _updateComments();
388    }
389  }
390  
391  
392  function _previousPage() {
393    if(pageNum > 1) {
394      pageNum--;
395      _updateComments();
396    }
397  }
398  
399  
400  function _findIdMatch (id) {
401    var len = MT.commentIds.length;
402    
403  	while (len--) {
404  		if (MT.commentIds[len] == id) {
405  			commentAnchor = "comment-" + id;
406  			commentArrId = len;
407  			return true;
408  		}
409  	}
410  	
411  	return false;
412  }
413  
414  
415  function _setCurrentComments() {
416    var commentsOnPage = pageNum != commentsTotalPages ? commentsOffset + commentsPerPage : totalComments;
417    
418    _setCurrentCommentsContent([commentsOffset+1," - ",commentsOnPage].join(''));
419  }
420  
421  
422  function _setCurrentCommentsContent(currentCommentsHTML) {
423    currentCommentsSpan.innerHTML = currentCommentsHTML;
424    topCurrentCommentsSpan.innerHTML = currentCommentsHTML;
425  }
426  
427  
428  function _setCommentContent(commentHTML) {
429    commentContentDiv.innerHTML = commentHTML;
430  }
431  
432  
433  function _updateComments() {
434    var comments, jsonUrl;
435    isLoading = true;
436    _setCurrentCommentsContent(loadingIcon);
437    _setCommentOffset();
438    
439    jsonUrl = [
440        "http://www.yunokuni.com/mt5/mt-comments.cgi?__mode=comment_listing&direction=",
441        direction,
442        "&entry_id=",
443        entryID,
444        "&limit=",
445        commentsPerPage,
446        "&offset=",
447        _getCommentOffset()
448      ].join('');
449  	
450  	if (!commentAnchor) {
451      commentAnchor = "comments-content";
452    }
453    
454    if(cache.hasOwnProperty(jsonUrl)) {
455      _refreshComments(cache[jsonUrl]);
456      isLoading = false;
457    } else {
458      M.connect(jsonUrl,c.JSON,function (json) {
459        cache[jsonUrl] = json.comments;
460    	  _refreshComments(json.comments);
461    	  isLoading = false;
462      });
463    }
464  }
465  
466  
467  function _refreshComments(commentData) {
468    _setCommentContent(commentData);
469    _setCurrentComments();
470    window.location.hash = 'reset';
471    window.location.hash = commentAnchor;
472    _toggleNavLinks();
473  }
474})();
475
476
477function mtRelativeDate(ts, fds) {
478    var now = new Date();
479    var ref = ts;
480    var delta = Math.floor((now.getTime() - ref.getTime()) / 1000);
481
482    var str;
483    if (delta < 60) {
484        str = 'ľÁ°';
485    } else if (delta <= 86400) {
486        // less than 1 day
487        var hours = Math.floor(delta / 3600);
488        var min = Math.floor((delta % 3600) / 60);
489        if (hours == 1)
490            str = '1 »þ´ÖÁ°';
491        else if (hours > 1)
492            str = '2 »þ´ÖÁ°'.replace(/2/, hours);
493        else if (min == 1)
494            str = '1 ʬÁ°';
495        else
496            str = '2 ʬÁ°'.replace(/2/, min);
497    } else if (delta <= 604800) {
498        // less than 1 week
499        var days = Math.floor(delta / 86400);
500        var hours = Math.floor((delta % 86400) / 3600);
501        if (days == 1)
502            str = '1 ÆüÁ°';
503        else if (days > 1)
504            str = '2 ÆüÁ°'.replace(/2/, days);
505        else if (hours == 1)
506            str = '1 »þ´ÖÁ°';
507        else
508            str = '2 »þ´ÖÁ°'.replace(/2/, hours);
509    }
510    return str ? str : fds;
511}
512
513
514function mtEditLink(entry_id, author_id) {
515    var u = mtGetUser();
516    if (! u) return;
517    if (! entry_id) return;
518    if (! author_id) return;
519    if (u.id != author_id) return;
520    var link = '<a href="mt.cgi?__mode=view&amp;_type=entry&amp;id=' + entry_id + '">ÊÔ½¸</a>';
521    document.write(link);
522}
523
524
525function mtCommentFormOnFocus() {
526    // if CAPTCHA is enabled, this causes the captcha image to be
527    // displayed if it hasn't been already.
528    mtShowCaptcha();
529}
530
531
532var mtCaptchaVisible = false;
533function mtShowCaptcha() {
534    var u = mtGetUser();
535    if ( u && u.is_authenticated ) return;
536    if (mtCaptchaVisible) return;
537    var div = document.getElementById('comments-open-captcha');
538    if (div) {
539        div.innerHTML = '';
540        mtCaptchaVisible = true;
541    }
542}
543
544
545
546var is_preview;
547var user;
548
549function mtSetUser(u) {
550    if (u) {
551        // persist this
552        user = u;
553        mtSaveUser();
554        // sync up user greeting
555        mtFireEvent('usersignin');
556    }
557}
558
559
560function mtEscapeJS(s) {
561    s = s.replace(/'/g, "&apos;");
562    return s;
563}
564
565
566function mtUnescapeJS(s) {
567    s = s.replace(/&apos;/g, "'");
568    return s;
569}
570
571
572function mtBakeUserCookie(u) {
573    var str = "";
574    if (u.name) str += "name:'" + mtEscapeJS(u.name) + "';";
575    if (u.url) str += "url:'" + mtEscapeJS(u.url) + "';";
576    if (u.email) str += "email:'" + mtEscapeJS(u.email) + "';";
577    if (u.is_authenticated) str += "is_authenticated:'1';";
578    if (u.profile) str += "profile:'" + mtEscapeJS(u.profile) + "';";
579    if (u.userpic) str += "userpic:'" + mtEscapeJS(u.userpic) + "';";
580    if (u.sid) str += "sid:'" + mtEscapeJS(u.sid) + "';";
581    str += "is_trusted:'" + (u.is_trusted ? "1" : "0") + "';";
582    str += "is_author:'" + (u.is_author ? "1" : "0") + "';";
583    str += "is_banned:'" + (u.is_banned ? "1" : "0") + "';";
584    str += "can_post:'" + (u.can_post ? "1" : "0") + "';";
585    str += "can_comment:'" + (u.can_comment ? "1" : "0") + "';";
586    str = str.replace(/;$/, '');
587    return str;
588}
589
590
591function mtUnbakeUserCookie(s) {
592    if (!s) return;
593
594    var u = {};
595    var m;
596    while (m = s.match(/^((name|url|email|is_authenticated|profile|userpic|sid|is_trusted|is_author|is_banned|can_post|can_comment):'([^']+?)';?)/)) {
597        s = s.substring(m[1].length);
598        if (m[2].match(/^(is|can)_/)) // boolean fields
599            u[m[2]] = m[3] == '1' ? true : false;
600        else
601            u[m[2]] = mtUnescapeJS(m[3]);
602    }
603    if (u.is_authenticated) {
604        u.is_anonymous = false;
605    } else {
606        u.is_anonymous = true;
607        u.can_post = false;
608        u.is_author = false;
609        u.is_banned = false;
610        u.is_trusted = false;
611    }
612    return u;
613}
614
615
616function mtGetUser() {
617    if (!user) {
618        var cookie = mtGetCookie(mtCookieName);
619        if (!cookie) return;
620        user = mtUnbakeUserCookie(cookie);
621        if (! user) {
622            user = {};
623            user.is_anonymous = true;
624            user.can_post = false;
625            user.is_author = false;
626            user.is_banned = false;
627            user.is_trusted = false;
628        }
629    }
630    return user;
631}
632
633
634var mtFetchedUser = false;
635
636function mtFetchUser(cb) {
637    if (!cb) cb = 'mtSetUser';
638    if ( ( cb == 'mtSetUser' ) && mtGetUser() ) {
639        var url = document.URL;
640        url = url.replace(/#.+$/, '');
641        url += '#comments-open';
642        location.href = url;
643    } else {
644        // we aren't using AJAX for this, since we may have to request
645        // from a different domain. JSONP to the rescue.
646        mtFetchedUser = true;
647        var script = document.createElement('script');
648        var ts = new Date().getTime();
649        script.src = 'http://www.yunokuni.com/mt5/mt-comments.cgi?__mode=session_js&blog_id=17&jsonp=' + cb + '&ts=' + ts;
650        (document.getElementsByTagName('head'))[0].appendChild(script);
651    }
652}
653
654
655
656function mtRememberMeOnClick(b) {
657    if (!b.checked)
658        mtClearUser(b.form);
659    return true;
660}
661
662
663
664var mtRequestSubmitted = false;
665function mtCommentOnSubmit(f) {
666    if (!mtRequestSubmitted) {
667        mtRequestSubmitted = true;
668
669        if (f.armor)
670            f.armor.value = 'a12a5310c2681825a83864afac55cefe4447e0ab';
671        if (f.bakecookie && f.bakecookie.checked)
672            mtSaveUser(f);
673
674        // disable submit buttons
675        if (f.preview_button) f.preview_button.disabled = true;
676        if (f.post) f.post.disabled = true;
677
678        var u = mtGetUser();
679        if ( !is_preview && ( u && u.is_authenticated ) ) {
680            // validate session; then submit
681            mtFetchedUser = false;
682            mtFetchUser('mtCommentSessionVerify');
683            return false;
684        }
685
686        return true;
687    }
688    return false;
689}
690
691function mtCommentSessionVerify(app_user) {
692    var u = mtGetUser();
693    var f = document['comments_form'];
694    if ( u && app_user && app_user.sid && ( u.sid == app_user.sid ) ) {
695        f.submit();
696    } else {
697        alert('¥»¥Ã¥·¥ç¥ó¤ÎÍ­¸ú´ü¸Â¤¬ÀÚ¤ì¤Æ¤¤¤Þ¤¹¡£ºÆÅÙ¥µ¥¤¥ó¥¤¥ó¤·¤Æ¤¯¤À¤µ¤¤¡£');
698        mtClearUser();
699        mtFireEvent('usersignin');
700
701        mtShow('comments-form');
702        mtHide('comments-open-footer');
703
704    }
705}
706
707function mtUserOnLoad() {
708    var u = mtGetUser();
709
710    // if the user is authenticated, hide the 'anonymous' fields
711    // and any captcha input if already shown
712    if ( document.getElementById('comments-form')) {
713        if ( u && u.is_authenticated ) {
714            mtShow('comments-form');
715            mtHide('comments-open-data');
716            if (mtCaptchaVisible)
717                mtHide('comments-open-captcha');
718        } else {
719
720            mtHide('comments-form');
721
722        }
723        if ( u && u.is_banned )
724            mtHide('comments-form');
725
726        // if we're previewing a comment, make sure the captcha
727        // field is visible
728        if (is_preview)
729            mtShowCaptcha();
730        else
731            mtShowGreeting();
732
733        // populate anonymous comment fields if user is cookied as anonymous
734        var cf = document['comments_form'];
735        if (cf) {
736            if (u && u.is_anonymous) {
737                if (u.email) cf.email.value = u.email;
738                if (u.name) cf.author.value = u.name;
739                if (u.url) cf.url.value = u.url;
740                if (cf.bakecookie)
741                    cf.bakecookie.checked = u.name || u.email;
742            } else {
743                if (u && u.sid && cf.sid)
744                    cf.sid.value = u.sid;
745            }
746            if (cf.post && cf.post.disabled)
747                cf.post.disabled = false;
748            if (cf.preview_button && cf.preview_button.disabled)
749                cf.preview_button.disabled = false;
750            mtRequestSubmitted = false;
751        }
752    }
753}
754
755
756
757
758function mtEntryOnLoad() {
759    var cf = document['comments_form'];
760    if (cf && cf.preview) cf.preview.value = '';
761    
762    
763    mtFireEvent('usersignin');
764}
765
766function mtEntryOnUnload() {
767    if (mtRequestSubmitted) {
768        var cf = document['comments_form'];
769        if (cf) {
770            if (cf.post && cf.post.disabled)
771                cf.post.disabled = false;
772            if (cf.preview_button && cf.preview_button.disabled)
773                cf.preview_button.disabled = false;
774        }
775        mtRequestSubmitted = false;
776    }
777    return true;
778}
779
780mtAttachEvent('usersignin', mtUserOnLoad);
781
782
783
784function mtSignIn() {
785    var doc_url = document.URL;
786    doc_url = doc_url.replace(/#.+/, '');
787    var url = 'http://www.yunokuni.com/mt5/mt-cp.cgi?__mode=login&blog_id=17';
788    if (is_preview) {
789        if ( document['comments_form'] ) {
790            var entry_id = document['comments_form'].entry_id.value;
791            url += '&entry_id=' + entry_id;
792        } else {
793            url += '&return_url=http%3A%2F%2Fwww.yunokuni.com%2F';
794        }
795    } else {
796        url += '&return_url=' + encodeURIComponent(doc_url);
797    }
798    mtClearUser();
799    location.href = url;
800}
801
802function mtSignInOnClick(sign_in_element) {
803    var el;
804    if (sign_in_element) {
805        // display throbber
806        el = document.getElementById(sign_in_element);
807        if (!el)  // legacy MT 4.x element id
808            el = document.getElementById('comment-form-external-auth');
809    }
810    if (el)
811        el.innerHTML = '¥µ¥¤¥ó¥¤¥ó¤·¤Þ¤¹... <span class="status-indicator">&nbsp;</span>';
812
813    mtClearUser(); // clear any 'anonymous' user cookie to allow sign in
814    mtFetchUser('mtSetUserOrLogin');
815    return false;
816}
817
818function mtSetUserOrLogin(u) {
819    if (u && u.is_authenticated) {
820        mtSetUser(u);
821    } else {
822        // user really isn't logged in; so let's do this!
823        mtSignIn();
824    }
825}
826
827
828function mtSignOut(entry_id) {
829    mtClearUser();
830    var doc_url = document.URL;
831    doc_url = doc_url.replace(/#.+/, '');
832    var url = 'http://www.yunokuni.com/mt5/mt-cp.cgi?__mode=logout&static=0&blog_id=17';
833    if (is_preview) {
834        if ( document['comments_form'] ) {
835            var entry_id = document['comments_form'].entry_id.value;
836            url += '&entry_id=' + entry_id;
837        } else {
838            url += '&return_url=http%3A%2F%2Fwww.yunokuni.com%2F';
839        }
840    } else {
841        url += '&return_url=' + encodeURIComponent(doc_url);
842    }
843    location.href = url;
844}
845
846
847function mtSignOutOnClick() {
848    mtSignOut();
849    return false;
850}
851
852
853
854function mtShowGreeting() {
855
856    var reg_reqd = true;
857
858    var cf = document['comments_form'];
859    if (!cf) return;
860
861    var el = document.getElementById('comment-greeting');
862    if (!el)  // legacy MT 4.x element id
863        el = document.getElementById('comment-form-external-auth');
864    if (!el) return;
865
866    var eid = cf.entry_id;
867    var entry_id;
868    if (eid) entry_id = eid.value;
869
870    var phrase;
871    var u = mtGetUser();
872
873    if ( u && u.is_authenticated ) {
874        if ( u.is_banned ) {
875            phrase = '¤³¤Î¥Ö¥í¥°¤Ë¥³¥á¥ó¥È¤¹¤ë¸¢¸Â¤ò»ý¤Ã¤Æ¤¤¤Þ¤»¤ó¡£(\<a href=\"javas\cript:void(0);\" onclick=\"return mtSignOutOnClick();\"\>¥µ¥¤¥ó¥¢¥¦¥È¤¹¤ë\<\/a\>)';
876        } else {
877            var user_link;
878            if ( u.is_author ) {
879                user_link = '<a href="http://www.yunokuni.com/mt5/mt-comments.cgi?__mode=edit_profile&return_url=' + encodeURIComponent( location.href );
880                user_link += '">' + u.name + '</a>';
881            } else {
882                // registered user, but not a user with posting rights
883                if (u.url)
884                    user_link = '<a href="' + u.url + '">' + u.name + '</a>';
885                else
886                    user_link = u.name;
887            }
888            // TBD: supplement phrase with userpic if one is available.
889            phrase = '__NAME__¤È¤·¤Æ¥µ¥¤¥ó¥¤¥ó¤·¤Æ¤¤¤Þ¤¹¡£(\<a href=\"javas\cript:void(0)\" onclick=\"return mtSignOutOnClick();\"\>¥µ¥¤¥ó¥¢¥¦¥È\<\/a\>)';
890            phrase = phrase.replace(/__NAME__/, user_link);
891        }
892    } else {
893        if (reg_reqd) {
894            phrase = '¥³¥á¥ó¥È¤¹¤ë¤Ë¤Ï¤Þ¤º\<a href=\"javas\cript:void(0)\" onclick=\"return mtSignInOnClick(\'comment-greeting\')\"\>¥µ¥¤¥ó¥¤¥ó\<\/a\>¤·¤Æ¤¯¤À¤µ¤¤¡£';
895        } else {
896            phrase = '¥³¥á¥ó¥È¤¹¤ëÁ°¤Ë\<a href=\"javas\cript:void(0)\" onclick=\"return mtSignInOnClick(\'comment-greeting\')\"\>¥µ¥¤¥ó¥¤¥ó\<\/a\>¤¹¤ë¤³¤È¤â¤Ç¤­¤Þ¤¹¡£';
897        }
898    }
899    el.innerHTML = phrase;
900
901}
902
903
904
905function mtReplyCommentOnClick(parent_id, author) {
906    mtShow('comment-form-reply');
907
908    var checkbox = document.getElementById('comment-reply');
909    var label = document.getElementById('comment-reply-label');
910    var text = document.getElementById('comment-text');
911
912    // Populate label with new values
913    var reply_text = '\<a href=\"#comment-__PARENT__\" onclick=\"location.href=this.href; return false\"\>__AUTHOR__¤«¤é¤Î¥³¥á¥ó¥È\<\/a\>¤ËÊÖ¿®';
914    reply_text = reply_text.replace(/__PARENT__/, parent_id);
915    reply_text = reply_text.replace(/__AUTHOR__/, author);
916    label.innerHTML = reply_text;
917
918    checkbox.value = parent_id; 
919    checkbox.checked = true;
920    try {
921        // text field may be hidden
922        text.focus();
923    } catch(e) {
924    }
925
926    mtSetCommentParentID();
927}
928
929
930function mtSetCommentParentID() {
931    var checkbox = document.getElementById('comment-reply');
932    var parent_id_field = document.getElementById('comment-parent-id');
933    if (!checkbox || !parent_id_field) return;
934
935    var pid = 0;
936    if (checkbox.checked == true)
937        pid = checkbox.value;
938    parent_id_field.value = pid;
939}
940
941
942function mtSaveUser(f) {
943    // We can't reliably store the user cookie during a preview.
944    if (is_preview) return;
945
946    var u = mtGetUser();
947
948    if (f && (!u || u.is_anonymous)) {
949        if ( !u ) {
950            u = {};
951            u.is_authenticated = false;
952            u.can_comment = true;
953            u.is_author = false;
954            u.is_banned = false;
955            u.is_anonymous = true;
956            u.is_trusted = false;
957        }
958        if (f.author != undefined) u.name = f.author.value;
959        if (f.email != undefined) u.email = f.email.value;
960        if (f.url != undefined) u.url = f.url.value;
961    }
962
963    if (!u) return;
964
965    var cache_period = mtCookieTimeout * 1000;
966
967    // cache anonymous user info for a long period if the
968    // user has requested to be remembered
969    if (u.is_anonymous && f && f.bakecookie && f.bakecookie.checked)
970        cache_period = 365 * 24 * 60 * 60 * 1000;
971
972    var now = new Date();
973    mtFixDate(now);
974    now.setTime(now.getTime() + cache_period);
975
976    var cmtcookie = mtBakeUserCookie(u);
977    mtSetCookie(mtCookieName, cmtcookie, now, mtCookiePath, mtCookieDomain,
978        location.protocol == 'https:');
979}
980
981
982function mtClearUser() {
983    user = null;
984    mtDeleteCookie(mtCookieName, mtCookiePath, mtCookieDomain,
985        location.protocol == 'https:');
986}
987
988
989function mtSetCookie(name, value, expires, path, domain, secure) {
990    if (domain && domain.match(/^\.?localhost$/))
991        domain = null;
992    var curCookie = name + "=" + escape(value) +
993        (expires ? "; expires=" + expires.toGMTString() : "") +
994        (path ? "; path=" + path : "") +
995        (domain ? "; domain=" + domain : "") +
996        (secure ? "; secure" : "");
997    document.cookie = curCookie;
998}
999
1000
1001function mtGetCookie(name) {
1002    var prefix = name + '=';
1003    var c = document.cookie;
1004    var cookieStartIndex = c.indexOf(prefix);
1005    if (cookieStartIndex == -1)
1006        return '';
1007    var cookieEndIndex = c.indexOf(";", cookieStartIndex + prefix.length);
1008    if (cookieEndIndex == -1)
1009        cookieEndIndex = c.length;
1010    return unescape(c.substring(cookieStartIndex + prefix.length, cookieEndIndex));
1011}
1012
1013
1014function mtDeleteCookie(name, path, domain, secure) {
1015    if (mtGetCookie(name)) {
1016        if (domain && domain.match(/^\.?localhost$/))
1017            domain = null;
1018        document.cookie = name + "=" +
1019            (path ? "; path=" + path : "") +
1020            (domain ? "; domain=" + domain : "") +
1021            (secure ? "; secure" : "") +
1022            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
1023    }
1024}
1025
1026function mtFixDate(date) {
1027    var skew = (new Date(0)).getTime();
1028    if (skew > 0)
1029        date.setTime(date.getTime() - skew);
1030}
1031
1032
1033function mtGetXmlHttp() {
1034    if ( !window.XMLHttpRequest ) {
1035        window.XMLHttpRequest = function() {
1036            var types = [
1037                "Microsoft.XMLHTTP",
1038                "MSXML2.XMLHTTP.5.0",
1039                "MSXML2.XMLHTTP.4.0",
1040                "MSXML2.XMLHTTP.3.0",
1041                "MSXML2.XMLHTTP"
1042            ];
1043
1044            for ( var i = 0; i < types.length; i++ ) {
1045                try {
1046                    return new ActiveXObject( types[ i ] );
1047                } catch( e ) {}
1048            }
1049
1050            return undefined;
1051        };
1052    }
1053    if ( window.XMLHttpRequest )
1054        return new XMLHttpRequest();
1055}
1056
1057// BEGIN: fast browser onload init
1058// Modifications by David Davis, DWD
1059// Dean Edwards/Matthias Miller/John Resig
1060// http://dean.edwards.name/weblog/2006/06/again/?full#comment5338
1061
1062function mtInit() {
1063    // quit if this function has already been called
1064    if (arguments.callee.done) return;
1065
1066    // flag this function so we don't do the same thing twice
1067    arguments.callee.done = true;
1068
1069    // kill the timer
1070    // DWD - check against window
1071    if ( window._timer ) clearInterval(window._timer);
1072
1073    // DWD - fire the window onload now, and replace it
1074    if ( window.onload && ( window.onload !== window.mtInit ) ) {
1075        window.onload();
1076        window.onload = function() {};
1077    }
1078}
1079
1080/* for Mozilla/Opera9 */
1081if (document.addEventListener) {
1082    document.addEventListener("DOMContentLoaded", mtInit, false);
1083}
1084
1085/* for Internet Explorer */
1086/*@cc_on @*/
1087/*@if (@_win32)
1088document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
1089var script = document.getElementById("__ie_onload");
1090script.onreadystatechange = function() {
1091    if (this.readyState == "complete") {
1092        mtInit(); // call the onload handler
1093    }
1094};
1095/*@end @*/
1096
1097/* for Safari */
1098if (/WebKit/i.test(navigator.userAgent)) { // sniff
1099    _timer = setInterval(function() {
1100        if (/loaded|complete/.test(document.readyState)) {
1101            mtInit(); // call the onload handler
1102        }
1103    }, 10);
1104}
1105
1106/* for other browsers */
1107window.onload = mtInit;
1108
1109// END: fast browser onload init
1110
1111
1112
1113/***
1114 * If request contains a '#_login' or '#_logout' hash, use this to
1115 * also delete the blog-side user cookie, since we're coming back from
1116 * a login, logout or edit profile operation.
1117 */
1118var clearCookie = ( window.location.hash && window.location.hash.match( /^#_log(in|out)/ ) ) ? true : false;
1119if (clearCookie) {
1120    // clear any logged in state
1121    mtClearUser();
1122    if (RegExp.$1 == 'in')
1123        mtFetchUser();
1124} else {
1125    
1126    if ( is_preview && !user )
1127        mtFetchUser();
1128}
1129
1130

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.