PageSourceSearch

https://3oclock.com/takamen/js/mt.js

js 3oclock.com collected 2026-10-04 01:57:49 UTC 31,246 bytes, 1,066 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 = ".3oclock.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='https://3oclock.com/__apps/mtos5210/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 (!Object.prototype.hasOwnProperty.call(M.getEl(found[0]), '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    _setCurrentCommentsContent(pageNum);
420  }
421  
422  
423  function _setCurrentCommentsContent(currentCommentsHTML) {
424    currentCommentsSpan.innerHTML = currentCommentsHTML;
425    topCurrentCommentsSpan.innerHTML = currentCommentsHTML;
426  }
427  
428  
429  function _setCommentContent(commentHTML) {
430    commentContentDiv.innerHTML = commentHTML;
431  }
432  
433  
434  function _updateComments() {
435    var comments, jsonUrl;
436    isLoading = true;
437    _setCurrentCommentsContent(loadingIcon);
438    _setCommentOffset();
439    
440    jsonUrl = [
441        "https://3oclock.com/__apps/mtos5210/mt-comments.cgi?__mode=comment_listing&direction=",
442        direction,
443        "&entry_id=",
444        entryID,
445        "&limit=",
446        commentsPerPage,
447        "&offset=",
448        _getCommentOffset()
449      ].join('');
450  	
451  	if (!commentAnchor) {
452      commentAnchor = "comments-content";
453    }
454    
455    if(cache.hasOwnProperty(jsonUrl)) {
456      _refreshComments(cache[jsonUrl]);
457      isLoading = false;
458    } else {
459      M.connect(jsonUrl,c.JSON,function (json) {
460        cache[jsonUrl] = json.comments;
461    	  _refreshComments(json.comments);
462    	  isLoading = false;
463      });
464    }
465  }
466  
467  
468  function _refreshComments(commentData) {
469    _setCommentContent(commentData);
470    _setCurrentComments();
471    window.location.hash = 'reset';
472    window.location.hash = commentAnchor;
473    _toggleNavLinks();
474  }
475})();
476
477
478function mtRelativeDate(ts, fds) {
479    var now = new Date();
480    var ref = ts;
481    var delta = Math.floor((now.getTime() - ref.getTime()) / 1000);
482
483    var str;
484    if (delta < 60) {
485        str = '直前';
486    } else if (delta <= 86400) {
487        // less than 1 day
488        var hours = Math.floor(delta / 3600);
489        var min = Math.floor((delta % 3600) / 60);
490        if (hours == 1)
491            str = '1 時間前';
492        else if (hours > 1)
493            str = '2 時間前'.replace(/2/, hours);
494        else if (min == 1)
495            str = '1 分前';
496        else
497            str = '2 分前'.replace(/2/, min);
498    } else if (delta <= 604800) {
499        // less than 1 week
500        var days = Math.floor(delta / 86400);
501        var hours = Math.floor((delta % 86400) / 3600);
502        if (days == 1)
503            str = '1 日前';
504        else if (days > 1)
505            str = '2 日前'.replace(/2/, days);
506        else if (hours == 1)
507            str = '1 時間前';
508        else
509            str = '2 時間前'.replace(/2/, hours);
510    }
511    return str ? str : fds;
512}
513
514
515function mtEditLink(entry_id, author_id) {
516    var u = mtGetUser();
517    if (! u) return;
518    if (! entry_id) return;
519    if (! author_id) return;
520    if (u.id != author_id) return;
521    var link = '<a href="mt.cgi?__mode=view&amp;_type=entry&amp;id=' + entry_id + '">編集</a>';
522    document.write(link);
523}
524
525
526function mtCommentFormOnFocus() {
527    // if CAPTCHA is enabled, this causes the captcha image to be
528    // displayed if it hasn't been already.
529    mtShowCaptcha();
530}
531
532
533var mtCaptchaVisible = false;
534function mtShowCaptcha() {
535    var u = mtGetUser();
536    if ( u && u.is_authenticated ) return;
537    if (mtCaptchaVisible) return;
538    var div = document.getElementById('comments-open-captcha');
539    if (div) {
540        div.innerHTML = '';
541        mtCaptchaVisible = true;
542    }
543}
544
545
546
547var is_preview;
548var user;
549
550function mtSetUser(u) {
551    if (u) {
552        // persist this
553        user = u;
554        mtSaveUser();
555        // sync up user greeting
556        mtFireEvent('usersignin');
557    }
558}
559
560
561function mtEscapeJS(s) {
562    s = s.replace(/'/g, "&apos;");
563    return s;
564}
565
566
567function mtUnescapeJS(s) {
568    s = s.replace(/&apos;/g, "'");
569    return s;
570}
571
572
573function mtBakeUserCookie(u) {
574    var str = "";
575    if (u.name) str += "name:'" + mtEscapeJS(u.name) + "';";
576    if (u.url) str += "url:'" + mtEscapeJS(u.url) + "';";
577    if (u.email) str += "email:'" + mtEscapeJS(u.email) + "';";
578    if (u.is_authenticated) str += "is_authenticated:'1';";
579    if (u.profile) str += "profile:'" + mtEscapeJS(u.profile) + "';";
580    if (u.userpic) str += "userpic:'" + mtEscapeJS(u.userpic) + "';";
581    if (u.sid) str += "sid:'" + mtEscapeJS(u.sid) + "';";
582    str += "is_trusted:'" + (u.is_trusted ? "1" : "0") + "';";
583    str += "is_author:'" + (u.is_author ? "1" : "0") + "';";
584    str += "is_banned:'" + (u.is_banned ? "1" : "0") + "';";
585    str += "can_post:'" + (u.can_post ? "1" : "0") + "';";
586    str += "can_comment:'" + (u.can_comment ? "1" : "0") + "';";
587    str = str.replace(/;$/, '');
588    return str;
589}
590
591
592function mtUnbakeUserCookie(s) {
593    if (!s) return;
594
595    var u = {};
596    var m;
597    while (m = s.match(/^((name|url|email|is_authenticated|profile|userpic|sid|is_trusted|is_author|is_banned|can_post|can_comment):'([^']+?)';?)/)) {
598        s = s.substring(m[1].length);
599        if (m[2].match(/^(is|can)_/)) // boolean fields
600            u[m[2]] = m[3] == '1' ? true : false;
601        else
602            u[m[2]] = mtUnescapeJS(m[3]);
603    }
604    if (u.is_authenticated) {
605        u.is_anonymous = false;
606    } else {
607        u.is_anonymous = true;
608        u.can_post = false;
609        u.is_author = false;
610        u.is_banned = false;
611        u.is_trusted = false;
612    }
613    return u;
614}
615
616
617function mtGetUser() {
618    if (!user) {
619        var cookie = mtGetCookie(mtCookieName);
620        if (!cookie) return;
621        user = mtUnbakeUserCookie(cookie);
622        if (! user) {
623            user = {};
624            user.is_anonymous = true;
625            user.can_post = false;
626            user.is_author = false;
627            user.is_banned = false;
628            user.is_trusted = false;
629        }
630    }
631    return user;
632}
633
634
635var mtFetchedUser = false;
636
637function mtFetchUser(cb) {
638    if (!cb) cb = 'mtSetUser';
639    if ( ( cb == 'mtSetUser' ) && mtGetUser() ) {
640        var url = document.URL;
641        url = url.replace(/#.+$/, '');
642        url += '#comments-open';
643        location.href = url;
644    } else {
645        // we aren't using AJAX for this, since we may have to request
646        // from a different domain. JSONP to the rescue.
647        mtFetchedUser = true;
648        var script = document.createElement('script');
649        var ts = new Date().getTime();
650        script.src = 'https://3oclock.com/__apps/mtos5210/mt-comments.cgi?__mode=session_js&blog_id=9&jsonp=' + cb + '&ts=' + ts;
651        (document.getElementsByTagName('head'))[0].appendChild(script);
652    }
653}
654
655
656
657function mtRememberMeOnClick(b) {
658    if (!b.checked)
659        mtClearUser(b.form);
660    return true;
661}
662
663
664
665var mtRequestSubmitted = false;
666function mtCommentOnSubmit(f) {
667    if (!mtRequestSubmitted) {
668        mtRequestSubmitted = true;
669
670        if (f.armor)
671            f.armor.value = 'b990fd6f796c12ce52e937901ed9c8da30af58cc';
672        if (f.bakecookie && f.bakecookie.checked)
673            mtSaveUser(f);
674
675        // disable submit buttons
676        if (f.preview_button) f.preview_button.disabled = true;
677        if (f.post) f.post.disabled = true;
678
679        var u = mtGetUser();
680        if ( !is_preview && ( u && u.is_authenticated ) ) {
681            // validate session; then submit
682            mtFetchedUser = false;
683            mtFetchUser('mtCommentSessionVerify');
684            return false;
685        }
686
687        return true;
688    }
689    return false;
690}
691
692function mtCommentSessionVerify(app_user) {
693    var u = mtGetUser();
694    var f = document.getElementById('commentsForm');
695    if ( u && app_user && app_user.sid && ( u.sid == app_user.sid ) ) {
696        f.submit();
697    } else {
698        alert('セッションの有効期限が切れています。再度サインインしてください。');
699        mtClearUser();
700        mtFireEvent('usersignin');
701
702    }
703}
704
705function mtUserOnLoad() {
706    var u = mtGetUser();
707
708    // if the user is authenticated, hide the 'anonymous' fields
709    // and any captcha input if already shown
710    if ( document.getElementById('commentsForm')) {
711        if ( u && u.is_authenticated ) {
712            mtShow('commentsForm');
713            mtHide('comments-open-data');
714            if (mtCaptchaVisible)
715                mtHide('comments-open-captcha');
716        } else {
717
718        }
719        if ( u && u.is_banned )
720            mtHide('commentsForm');
721
722        // if we're previewing a comment, make sure the captcha
723        // field is visible
724        if (is_preview)
725            mtShowCaptcha();
726        else
727            mtShowGreeting();
728
729        // populate anonymous comment fields if user is cookied as anonymous
730        var cf = document.getElementById('commentsForm');
731        if (cf) {
732            if (u && u.is_anonymous) {
733                if (u.email) cf.email.value = u.email;
734                if (u.name) cf.author.value = u.name;
735                if (u.url) cf.url.value = u.url;
736                if (cf.bakecookie)
737                    cf.bakecookie.checked = u.name || u.email;
738            } else {
739                if (u && u.sid && cf.sid)
740                    cf.sid.value = u.sid;
741            }
742            if (cf.post && cf.post.disabled)
743                cf.post.disabled = false;
744            if (cf.preview_button && cf.preview_button.disabled)
745                cf.preview_button.disabled = false;
746            mtRequestSubmitted = false;
747        }
748    }
749}
750
751
752
753
754function mtEntryOnLoad() {
755    var cf = document.getElementById('commentsForm');
756    if (cf && cf.preview) cf.preview.value = '';
757    
758    
759    mtFireEvent('usersignin');
760}
761
762function mtEntryOnUnload() {
763    if (mtRequestSubmitted) {
764        var cf = document.getElementById('commentsForm');
765        if (cf) {
766            if (cf.post && cf.post.disabled)
767                cf.post.disabled = false;
768            if (cf.preview_button && cf.preview_button.disabled)
769                cf.preview_button.disabled = false;
770        }
771        mtRequestSubmitted = false;
772    }
773    return true;
774}
775
776mtAttachEvent('usersignin', mtUserOnLoad);
777
778
779
780function mtSignIn() {
781    var doc_url = document.URL;
782    doc_url = doc_url.replace(/#.+/, '');
783    var url = 'https://3oclock.com/__apps/mtos5210/mt-comments.cgi?__mode=login&blog_id=9';
784    if (is_preview) {
785        if ( document.getElementById('commentsForm') ) {
786            var entry_id = document.getElementById('commentsForm').entry_id.value;
787            url += '&entry_id=' + entry_id;
788        } else {
789            url += '&return_url=https%3A%2F%2F3oclock.com%2Ftakamen%2F';
790        }
791    } else {
792        url += '&return_url=' + encodeURIComponent(doc_url);
793    }
794    mtClearUser();
795    location.href = url;
796}
797
798function mtSignInOnClick(sign_in_element) {
799    var el;
800    if (sign_in_element) {
801        // display throbber
802        el = document.getElementById(sign_in_element);
803        if (!el)  // legacy MT 4.x element id
804            el = document.getElementById('comment-form-external-auth');
805    }
806    if (el)
807        el.innerHTML = 'サインインします... <span class="status-indicator">&nbsp;</span>';
808
809    mtClearUser(); // clear any 'anonymous' user cookie to allow sign in
810    mtFetchUser('mtSetUserOrLogin');
811    return false;
812}
813
814function mtSetUserOrLogin(u) {
815    if (u && u.is_authenticated) {
816        mtSetUser(u);
817    } else {
818        // user really isn't logged in; so let's do this!
819        mtSignIn();
820    }
821}
822
823
824function mtSignOut(entry_id) {
825    mtClearUser();
826    var doc_url = document.URL;
827    doc_url = doc_url.replace(/#.+/, '');
828    var url = 'https://3oclock.com/__apps/mtos5210/mt-comments.cgi?__mode=handle_sign_in&static=0&logout=1&blog_id=9';
829    if (is_preview) {
830        if ( document.getElementById('commentsForm') ) {
831            var entry_id = document.getElementById('commentsForm').entry_id.value;
832            url += '&entry_id=' + entry_id;
833        } else {
834            url += '&return_url=https%3A%2F%2F3oclock.com%2Ftakamen%2F';
835        }
836    } else {
837        url += '&return_url=' + encodeURIComponent(doc_url);
838    }
839    location.href = url;
840}
841
842
843function mtSignOutOnClick() {
844    mtSignOut();
845    return false;
846}
847
848
849
850function mtShowGreeting() {
851
852    mtShowCaptcha();
853
854}
855
856
857
858function mtReplyCommentOnClick(parent_id, author) {
859    mtShow('commentForm-reply');
860
861    var checkbox = document.getElementById('comment-reply');
862    var label = document.getElementById('comment-reply-label');
863    var text = document.getElementById('comment-text');
864
865    // Populate label with new values
866    var reply_text = '\<a href=\"#comment-__PARENT__\" onclick=\"location.href=this.href; return false\"\>__AUTHOR__からのコメント\<\/a\>に返信';
867    reply_text = reply_text.replace(/__PARENT__/, parent_id);
868    reply_text = reply_text.replace(/__AUTHOR__/, author);
869    label.innerHTML = reply_text;
870
871    checkbox.value = parent_id; 
872    checkbox.checked = true;
873    try {
874        // text field may be hidden
875        text.focus();
876    } catch(e) {
877    }
878
879    mtSetCommentParentID();
880}
881
882
883function mtSetCommentParentID() {
884    var checkbox = document.getElementById('comment-reply');
885    var parent_id_field = document.getElementById('comment-parent-id');
886    if (!checkbox || !parent_id_field) return;
887
888    var pid = 0;
889    if (checkbox.checked == true)
890        pid = checkbox.value;
891    parent_id_field.value = pid;
892}
893
894
895function mtSaveUser(f) {
896    // We can't reliably store the user cookie during a preview.
897    if (is_preview) return;
898
899    var u = mtGetUser();
900
901    if (f && (!u || u.is_anonymous)) {
902        if ( !u ) {
903            u = {};
904            u.is_authenticated = false;
905            u.can_comment = true;
906            u.is_author = false;
907            u.is_banned = false;
908            u.is_anonymous = true;
909            u.is_trusted = false;
910        }
911        if (f.author != undefined) u.name = f.author.value;
912        if (f.email != undefined) u.email = f.email.value;
913        if (f.url != undefined) u.url = f.url.value;
914    }
915
916    if (!u) return;
917
918    var cache_period = mtCookieTimeout * 1000;
919
920    // cache anonymous user info for a long period if the
921    // user has requested to be remembered
922    if (u.is_anonymous && f && f.bakecookie && f.bakecookie.checked)
923        cache_period = 365 * 24 * 60 * 60 * 1000;
924
925    var now = new Date();
926    mtFixDate(now);
927    now.setTime(now.getTime() + cache_period);
928
929    var cmtcookie = mtBakeUserCookie(u);
930    mtSetCookie(mtCookieName, cmtcookie, now, mtCookiePath, mtCookieDomain,
931        location.protocol == 'https:');
932}
933
934
935function mtClearUser() {
936    user = null;
937    mtDeleteCookie(mtCookieName, mtCookiePath, mtCookieDomain,
938        location.protocol == 'https:');
939}
940
941
942function mtSetCookie(name, value, expires, path, domain, secure) {
943    if (domain && domain.match(/^\.?localhost$/))
944        domain = null;
945    var curCookie = name + "=" + escape(value) +
946        (expires ? "; expires=" + expires.toGMTString() : "") +
947        (path ? "; path=" + path : "") +
948        (domain ? "; domain=" + domain : "") +
949        (secure ? "; secure" : "");
950    document.cookie = curCookie;
951}
952
953
954function mtGetCookie(name) {
955    var prefix = name + '=';
956    var c = document.cookie;
957    var cookieStartIndex = c.indexOf(prefix);
958    if (cookieStartIndex == -1)
959        return '';
960    var cookieEndIndex = c.indexOf(";", cookieStartIndex + prefix.length);
961    if (cookieEndIndex == -1)
962        cookieEndIndex = c.length;
963    return unescape(c.substring(cookieStartIndex + prefix.length, cookieEndIndex));
964}
965
966
967function mtDeleteCookie(name, path, domain, secure) {
968    if (mtGetCookie(name)) {
969        if (domain && domain.match(/^\.?localhost$/))
970            domain = null;
971        document.cookie = name + "=" +
972            (path ? "; path=" + path : "") +
973            (domain ? "; domain=" + domain : "") +
974            (secure ? "; secure" : "") +
975            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
976    }
977}
978
979function mtFixDate(date) {
980    var skew = (new Date(0)).getTime();
981    if (skew > 0)
982        date.setTime(date.getTime() - skew);
983}
984
985
986function mtGetXmlHttp() {
987    if ( !window.XMLHttpRequest ) {
988        window.XMLHttpRequest = function() {
989            var types = [
990                "Microsoft.XMLHTTP",
991                "MSXML2.XMLHTTP.5.0",
992                "MSXML2.XMLHTTP.4.0",
993                "MSXML2.XMLHTTP.3.0",
994                "MSXML2.XMLHTTP"
995            ];
996
997            for ( var i = 0; i < types.length; i++ ) {
998                try {
999                    return new ActiveXObject( types[ i ] );
1000                } catch( e ) {}
1001            }
1002
1003            return undefined;
1004        };
1005    }
1006    if ( window.XMLHttpRequest )
1007        return new XMLHttpRequest();
1008}
1009
1010// BEGIN: fast browser onload init
1011// Modifications by David Davis, DWD
1012// Dean Edwards/Matthias Miller/John Resig
1013// http://dean.edwards.name/weblog/2006/06/again/?full#comment5338
1014
1015function mtInit() {
1016    // quit if this function has already been called
1017    if (arguments.callee.done) return;
1018
1019    // flag this function so we don't do the same thing twice
1020    arguments.callee.done = true;
1021
1022    // kill the timer
1023    // DWD - check against window
1024    if ( window._timer ) clearInterval(window._timer);
1025
1026    // DWD - fire the window onload now, and replace it
1027    if ( window.onload && ( window.onload !== window.mtInit ) ) {
1028        window.onload();
1029        window.onload = function() {};
1030    }
1031}
1032
1033/* for Mozilla/Opera9 */
1034if (document.addEventListener) {
1035    document.addEventListener("DOMContentLoaded", mtInit, false);
1036}
1037
1038/* for Internet Explorer */
1039/*@cc_on @*/
1040/*@if (@_win32)
1041document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
1042var script = document.getElementById("__ie_onload");
1043script.onreadystatechange = function() {
1044    if (this.readyState == "complete") {
1045        mtInit(); // call the onload handler
1046    }
1047};
1048/*@end @*/
1049
1050/* for Safari */
1051if (/WebKit/i.test(navigator.userAgent)) { // sniff
1052    _timer = setInterval(function() {
1053        if (/loaded|complete/.test(document.readyState)) {
1054            mtInit(); // call the onload handler
1055        }
1056    }, 10);
1057}
1058
1059/* for other browsers */
1060window.onload = mtInit;
1061
1062// END: fast browser onload init
1063
1064
1065
1066

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.