Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
--- untitled +++ (clipboard) @@ -1,13 +1,4 @@ -The wrong JS -<$mt:Var name="AjaxCGIPath" value="http://blogs.amctv.com/mt/"$> - - // The cookie name to use for storing the blog-side comment session cookie. -var mtCookieName = "<$mt:UserSessionCookieName$>"; -var mtCookieDomain = "<$mt:UserSessionCookieDomain$>"; -var mtCookiePath = "<$mt:UserSessionCookiePath$>"; -var mtCookieTimeout = <$mt:UserSessionCookieTimeout$>; - - +The right JS <mt:Ignore> /*** * Movable Type Community Solution Functions @@ -47,597 +38,6 @@ } } -if(!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');};}}()); - -var MT = window.MT || {}; - -MT.cons = function () { - return { - LOG : 'log', - WARN : 'warn', - DEBUG : 'debug', - INFO : 'info', - ERR : 'error', - JSON : 'json' - }; -}(); - -<mt:Ignore> -/** - * Used for base functionality related to MT - * - * @package MT - * @class core - * @global - * @param {Object} o optional configuration object - * Options: - */ -</mt:Ignore> -MT.core = function (o) { - var _debug = false; - - return { - <mt:Ignore> - /** - * Makes remote call and handles response - * - * @param {String} url The URL endpoint - * @param {String} respType The type of response expected - * @param {Function} respHandler The function to handle the response - * @return void - */ - </mt:Ignore> - connect : function (url,respType,respHandler) { - var xh = mtGetXmlHttp(); - if (!xh) return false; - - xh.onreadystatechange = function() { - if ( xh.readyState == 4 ) { - if ( xh.status && ( xh.status != 200 ) ) { - // error - ignore - } else { - switch (respType) { - case 'json': - respHandler(JSON.parse(xh.responseText)); - break; - - case 'xml': - break; - - case 'text': - break; - } - } - } - }; - - xh.open('GET',url); - xh.send(null); - }, - - getEl : function (el) { - return MT.util.checkNodeType(el)==='element' ? id : (document.getElementById(el) || false); - }, - - addEvent : function (el,type,func,obj) { - if(!obj && document.addEventListener) { - el.addEventListener(type,func,false); - } else if(obj && document.addEventListener) { - el.addEventListener(type,function () { - func.call(obj,event); - },false); - } else { - if(obj) { - el.attachEvent('on' + type,function () { - func.call(obj,event); - }); - } else { - el.attachEvent('on' + type,function () { - func.call(el,event); - }); - } - } - }, - - <mt:Ignore> - /** - * Basic logging function - * - * @param {String} level The log level (WARN|DEBUG|INFO|ERROR|LOG) - * Specified by one of the MT constants - * @param {String} msg The log message - * @return void - */ - </mt:Ignore> - log : function (level,msg) { - if(_debug && window.console) { - switch(level) { - case 'warn': - case 'debug': - case 'info': - case 'error': - case 'log': - console[level](msg); - break; - - default: - return false; - } - } else { - return false; - } - } - } -}(); - -<mt:Ignore> -/** - * Utilities class - * - * @package MT - * @class util - * @global - * Options: - */ -</mt:Ignore> -MT.util = function () { - return { - toggleVisibility : { - show : function () { - var i = arguments.length; - - while(i--) { - if(MT.util.checkNodeType(arguments[i])==='element') { - arguments[i].style.visibility = 'visible'; - } else { - MT.core.getEl(arguments[i]).style.visibility = 'visible'; - } - } - }, - - hide : function () { - var i = arguments.length; - while(i--) { - if(MT.util.checkNodeType(arguments[i])==='element') { - arguments[i].style.visibility = 'hidden'; - } else { - MT.core.getEl(arguments[i]).style.visibility = 'hidden'; - } - } - } - }, - - toggleDisplay : { - show : function () { - var i = arguments.length; - while(i--) { - if(MT.util.checkNodeType(arguments[i])==='element') { - arguments[i].style.display = ''; - } else { - MT.core.getEl(arguments[i]).style.display = ''; - } - } - }, - - hide : function () { - var i = arguments.length; - while(i--) { - if(MT.util.checkNodeType(arguments[i])==='element') { - arguments[i].style.display = 'none'; - } else { - MT.core.getEl(arguments[i]).style.display = 'none'; - } - } - } - }, - - <mt:Ignore> - /** - * Finds the nearest defining (i.e. with an id) parent to the given element - * - * @param {HTMLElement} origin the node from which to start the search - * @return {HTMLElement|Boolean} The parent node with an id attribute or false - */ - </mt:Ignore> - findDefiningParent : function (origin) { - if(MT.util.checkNodeType(origin)==='element') { - for(var node=origin.parentNode;node.parentNode;node=node.parentNode) { - if((node.hasAttribute && node.hasAttribute('id')) || node.getAttribute('id')) { - return node; - } - } - } - return false; - }, - - <mt:Ignore> - /** - * Tests objects to verify if they are DOM nodes - * - * @param {Object} obj The object to be tested - * @return {String} the values 'element'|'textnode'|'whitespace' - */ - </mt:Ignore> - checkNodeType : function (obj) { - if (obj && obj.nodeName){ - switch (obj.nodeType) { - case 1: return 'element'; - case 3: return (/\S/).test(obj.nodeValue) ? 'textnode' : 'whitespace'; - } - } - } - } -}(); - -<mt:Ignore> -/** - * mtPaginateComments takes the currently generated static page and either: - * - Attempts to find an individual comment link in the query string - * - If no link is found, the static page loads - * In either case, the pagination event is set - */ -</mt:Ignore> -(function () { - var M = MT.core, - c = MT.cons, - u = MT.util, - cache, - isLoading, - direction, - currentComments, - commentAnchor, - commentArrId, - commentsPerPage, - commentsTotalPages, - loadingIcon, - pageNum, - commentsOffset, - totalComments, - entryID, - commentContentDiv, - topNav, - nav, - currentCommentsSpan, - topCurrentCommentsSpan; - - M.addEvent(window,'load',_init); - - /** - * Initializes the class - * - * @return void - */ - function _init () { - if(!MT.entryCommentCount) { - return; - } - - _initializeVariables(); - _setCommentOffset(false); - _checkForAnchor(); - _setCurrentComments(); - _toggleNavLinks(); - _initializeEvents(); - } - - <mt:Ignore> - /** - * Initializes variables to their initial values - * - * @return void - */ - </mt:Ignore> - function _initializeVariables() { - cache = {}; - isLoading = false; - commentAnchor = ''; - commentArrId = ''; - commentsPerPage = MT.commentsPerPage || 50; - currentComments = ''; - direction = 'ascend'; - entryID = MT.entryID; - totalComments = MT.entryCommentCount; - commentsTotalPages = Math.ceil(totalComments / commentsPerPage); - pageNum = 1; - - loadingIcon = "<img title='Loading...' src='<$MTStaticWebPath$>images/indicator.white.gif' alt='Loading' />"; - - commentContentDiv = M.getEl("comments-content"); - topNav = M.getEl("top-comment-nav"); - nav = M.getEl("comment-nav"); - - currentCommentsSpan = M.getEl("current-comments"); - topCurrentCommentsSpan = M.getEl("top-current-comments"); - } - - function _initializeEvents() { - if (commentsPerPage < totalComments) { - M.addEvent(nav,'click',_handleEvents); - M.addEvent(topNav,'click',_handleEvents); - } - } - - <mt:Ignore> - /** - * Checks for an existing anchor tag in the query string - * If found, it looks for it on the current page - * If that fails, it tries to find it in comment list and loads - * the desired page - * - * @return void - */ - </mt:Ignore> - function _checkForAnchor() { - var found = String(window.location.hash).match( /comment-(\d{1,6})/ ); - - if (found) { - M.log(c.DEBUG,found); - if (!M.getEl(found[0]).hasOwnProperty('className')) { - if (_findIdMatch(found[1])) { - pageNum = Math.floor(commentArrId / commentsPerPage) + 1; - M.log(c.DEBUG,'Comment Array Id: ' + commentArrId); - M.log(c.DEBUG,'Comments Per Page: ' + commentsPerPage); - M.log(c.DEBUG,'Page Number: ' + pageNum); - M.log(c.DEBUG,'Comment Offset: ' + _getCommentOffset()); - _updateComments(); - } - } - } - } - - <mt:Ignore> - /** - * Sets commentsOffset (i.e. the offset number to the remote list) - * - * @return void - */ - </mt:Ignore> - function _setCommentOffset() { - commentsOffset = commentsPerPage * (pageNum-1); - } - - <mt:Ignore> - /** - * Gets the commentsOffset (i.e. the offset number to the remote list) - * - * @return void - */ - </mt:Ignore> - function _getCommentOffset() { - return commentsOffset; - } - - <mt:Ignore> - /** - * General event handler - * - * @param {Event} e The event object - * @return void - */ - </mt:Ignore> - function _handleEvents (e) { - var origin = e.target || e.srcElement, - parentId; - - // stupid IE - origin = origin.id && M.getEl(origin.id) || false; - - if(origin) { - parentId = u.checkNodeType(origin.parentNode)==='element' && origin.parentNode.getAttribute('id') && origin.parentNode.id; - } else { - return false; - } - - switch(origin.nodeName) { - case 'A': - switch (parentId) { - case 'prev-comments': - case 'top-prev-comments': - if(e.preventDefault) { - e.preventDefault(); - } else { - e.returnValue = false; - } - if(!isLoading) { - _previousPage(); - } - break; - case 'next-comments': - case 'top-next-comments': - if(e.preventDefault) { - e.preventDefault(); - } else { - e.returnValue = false; - } - if(!isLoading) { - _nextPage(); - } - break; - } - break; - } - } - - <mt:Ignore> - /** - * Toggles the visibility of the navigation links - * - * @return void - */ - </mt:Ignore> - function _toggleNavLinks () { - M.log(c.DEBUG,M.getEl('top-prev-comments')); - if(pageNum <= commentsTotalPages && pageNum !== 1) { - u.toggleVisibility.show('prev-comments'); - u.toggleVisibility.show('top-prev-comments'); - } - - if(pageNum >= 1 && pageNum !== commentsTotalPages) { - u.toggleVisibility.show('next-comments'); - u.toggleVisibility.show('top-next-comments'); - } - - if(pageNum===1 || nav.style.visibility==='hidden') { - u.toggleVisibility.hide('prev-comments'); - u.toggleVisibility.hide('top-prev-comments'); - } - - if(pageNum===commentsTotalPages || nav.style.visibility==='hidden') { - u.toggleVisibility.hide('next-comments'); - u.toggleVisibility.hide('top-next-comments'); - } - } - - <mt:Ignore> - /** - * Determines appropriate action based on the id of the parent - * clicked link. Decrements pageNum based on id. - * - * @param {String} id the id of the parent of the clicked link - * @return void - */ - </mt:Ignore> - function _nextPage () { - if(pageNum < commentsTotalPages) { - pageNum++; - _updateComments(); - } - } - - <mt:Ignore> - /** - * Determines appropriate action based on the id of the parent - * clicked link. Increments/decrements pageNum based on id. - * - * @param {String} id the id of the parent of the clicked link - * @return void - */ - </mt:Ignore> - function _previousPage() { - if(pageNum > 1) { - pageNum--; - _updateComments(); - } - } - - <mt:Ignore> - /** - * Searches for a particular comment in the list of ids - * - * @param {String} id The id for which to search - * @return {Boolean} true, if found, false otherwise - */ - </mt:Ignore> - function _findIdMatch (id) { - var len = MT.commentIds.length; - - while (len--) { - if (MT.commentIds[len] == id) { - commentAnchor = "comment-" + id; - commentArrId = len; - return true; - } - } - - return false; - } - - <mt:Ignore> - /** - * Sets the current comment counts on the page - * - * @return void - */ - </mt:Ignore> - function _setCurrentComments() { - var commentsOnPage = pageNum != commentsTotalPages ? commentsOffset + commentsPerPage : totalComments; - - _setCurrentCommentsContent([commentsOffset+1," - ",commentsOnPage].join('')); - } - - <mt:Ignore> - /** - * Sets the "current-comments" element with the HTML value - * - * @param {String|Element} currentCommentsHTML The content to be set - * @return void - */ - </mt:Ignore> - function _setCurrentCommentsContent(currentCommentsHTML) { - currentCommentsSpan.innerHTML = currentCommentsHTML; - topCurrentCommentsSpan.innerHTML = currentCommentsHTML; - } - - <mt:Ignore> - /** - * Sets the content of the comment list - * - * @param {String|Element} commentHTML The content to be set - * @return void - */ - </mt:Ignore> - function _setCommentContent(commentHTML) { - commentContentDiv.innerHTML = commentHTML; - } - - <mt:Ignore> - /** - * Builds the appropriate URL to make a remote call to get the - * next set of comments - * - * @return void - */ - </mt:Ignore> - function _updateComments() { - var comments, jsonUrl; - isLoading = true; - _setCurrentCommentsContent(loadingIcon); - _setCommentOffset(); - - jsonUrl = [ - "<$mt:CGIPath$>mt-comments.cgi?__mode=comment_listing&direction=", - direction, - "&entry_id=", - entryID, - "&limit=", - commentsPerPage, - "&offset=", - _getCommentOffset() - ].join(''); - - if (!commentAnchor) { - commentAnchor = "comments-content"; - } - - if(cache.hasOwnProperty(jsonUrl)) { - _refreshComments(cache[jsonUrl]); - isLoading = false; - } else { - M.connect(jsonUrl,c.JSON,function (json) { - cache[jsonUrl] = json.comments; - _refreshComments(json.comments); - isLoading = false; - }); - } - } - - <mt:Ignore> - /** - * Refreshes the comment data with the current - * - * @param {String} commentData The data used to replace current comments - * @return void - */ - </mt:Ignore> - function _refreshComments(commentData) { - _setCommentContent(commentData); - _setCurrentComments(); - window.location.hash = 'reset'; - window.location.hash = commentAnchor; - _toggleNavLinks(); - } -})(); - <mt:Ignore> /*** * Functions for scoring entries @@ -646,22 +46,17 @@ </mt:Ignore> <mt:IfBlog> function mtScore(entry_id) { - var span = $('#scoring-id-' + entry_id); - var scoringLabel = span.children('.scoring-vote'); - + var span = DOM.getElement('scoring-id-' + entry_id); if (!span) return false; - if (span.hasClass('scoring-pending')) return false; - if (span.hasClass('scoring-scored')) return false; - if (!span.hasClass('scoring-scorable')) return false; + if (DOM.hasClassName(span, 'scoring-pending')) return false; + if (DOM.hasClassName(span, 'scoring-scored')) return false; + if (!DOM.hasClassName(span, 'scoring-scorable')) return false; var xh = mtGetXmlHttp(); if (!xh) return false; - span.addClass( 'scoring-pending' ); - span.removeClass( 'scoring-scorable' ) - if (scoringLabel) scoringLabel.html ('<img src="<MTStaticWebPath$>images/indicator.white.gif" height="10" width="10" alt="voting..." />'); - - var url = '<$mt:Var name="AjaxCGIPath"$><$mt:CommunityScript$>'; + DOM.addClassName( span, 'scoring-pending' ); + var url = '<$mt:CGIPath$><$mt:CommunityScript$>'; xh.open('POST', url, true); xh.onreadystatechange = function() { if ( xh.readyState == 4 ) { @@ -697,7 +92,7 @@ var xh = mtGetXmlHttp(); if (!xh) return false; - var url = '<$mt:Var name="AjaxCGIPath"$><$mt:CommunityScript$>'; + var url = '<$mt:CGIPath$><$mt:CommunityScript$>'; xh.open('POST', url, true); xh.onreadystatechange = function() { if ( xh.readyState == 4 ) { @@ -716,45 +111,148 @@ function mtScore_cb(s_hash) { var u = mtGetUser(); if (s_hash['error']) { - - if (s_hash['error'] == 'Already scored for this object.\n') { - if ($('.scoring-pending .scoring-vote')) - $('.scoring-pending .scoring-vote').html('Already recommended').css('color','#FF0000'); - $('.scoring-pending').removeClass('scoring-scorable'); - } else { - alert(s_hash['error']); - } - var els = DOM.getElementsByClassName('scoring-pending'); for (var i = 0; i < els.length; i++) DOM.removeClassName(els[i], 'scoring-pending'); // display error - //alert(s_hash['error']); + alert(s_hash['error']); return; } for (var id in s_hash) { - var span = $('#scoring-id-' + id); + var span = DOM.getElement('scoring-id-' + id); if ( span ) { - span.removeClass( 'scoring-pending' ); - span.removeClass( 'scoring-scorable' ); + DOM.removeClassName( span, 'scoring-pending' ); + DOM.removeClassName( span, 'scoring-scorable' ); if ( s_hash[id].scored ) { - span.addClass( 'scoring-scored' ); - span.children('.scoring-vote').html('Recommended'); + DOM.addClassName( span, 'scoring-scored' ); } else { <mt:IfAnonymousRecommendAllowed> - span.addClass( 'scoring-scorable' ); + DOM.addClassName( span, 'scoring-scorable' ); <mt:Else> if ( u && u.is_authenticated ) - span.addClass( 'scoring-scorable' ); + DOM.addClassName( span, 'scoring-scorable' ); </mt:IfAnonymousRecommendAllowed> } } - var score = $('#scoring-score-' + id); + var score = DOM.getElement('scoring-score-' + id); if ( score ) - score.html (s_hash[id].count ? s_hash[id].count : 0); + score.innerHTML = s_hash[id].count ? s_hash[id].count : 0; var label = DOM.getElement('scoring-score-label-' + id); + if ( label ) { + switch ( s_hash[id].count ) { + case 1: + label.innerHTML = 'Vote'; + break; + default: + label.innerHTML = 'Votes'; + break; + } + } + } +} +</mt:IfBlog> + +<mt:Ignore> +/*** + * Legacy functions for favoriting entries + */ +</mt:Ignore> +<mt:IfBlog> +function insert_score(s_hash, id, div_id, span, span_else) { + conditional_block((s_hash[id] && s_hash[id].scored), div_id); + if (span || span_else) { + if (s_hash[id] && s_hash[id].sum) { + if (span) + span.innerHTML = s_hash[id].sum; + if (span_else) + span_else.innerHTML = s_hash[id].sum; + } + else { + if (span) + span.innerHTML = '0'; + if (span_else) + span_else.innerHTML = '0'; + } + } +} + +var favorite_cb_callbacks = []; +function favorite_cb(s_hash) { + for (var id in s_hash) { + var span = document.getElementById('scored_' + id + '_score'); + var span_else = document.getElementById('scored_' + id + '_else_score'); + conditional_block((s_hash[id] && s_hash[id].scored), 'scored_' + id); + // insert_score(s_hash, id, 'scored_' + id, span, span_else); + } + for (var idx in favorite_cb_callbacks) { + favorite_cb_callbacks[idx](s_hash); + } +} + +function anchor(id, eid, cl, score) { + var span = document.getElementById(id); + if (span) { + var elem = span.parentNode; + var func; + if (score) + func = function(evt) { favorite(evt, eid, score) }; + else + func = function(evt) { favorite(evt, eid, id) }; + var a = document.createElement('a'); + a.href = 'javascript:void(0);'; + if (cl) a.className = cl; + attachEvent(a, 'click', func); + a.appendChild(span); + elem.appendChild(a); } } + +function attachEvent(element, eventName, func) { + if( !element ) + return; + if( element.addEventListener ) + element.addEventListener( eventName, func, true ); + else if( element.attachEvent ) + element.attachEvent( "on" + eventName, func ); + else + element[ "on" + eventName ] = func; +} + + function detachEvent(element, eventName, func) { + if( !element ) + return; + if( element.removeEventListener ) + element.removeEventListener( eventName, func, true ); + else if( element.detachEvent ) + element.detachEvent( "on" + eventName, func ); + else + element[ "on" + eventName ] = null; + } + +function favorite(evt, entry_id, score_span) { + var xh = mtGetXmlHttp(); + if (!xh) return false; + evt = evt || event; + var src = evt.target || evt.srcElement; + if (src) detachEvent(src, 'click', arguments.callee); + + var url = '<$mt:CGIPath$><$mt:CommunityScript$>'; + xh.open('POST', url, true); + xh.onreadystatechange = function() { + if ( xh.readyState == 4 ) { + if ( xh.status && ( xh.status != 200 ) ) { + // error - ignore + } else { + eval(xh.responseText); + } + } + }; + xh.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' ); + xh.send( '__mode=vote&blog_id=<$mt:BlogID$>&f=scored,sum&jsonp=favorite_cb&id=' + entry_id); + var span = document.getElementById(score_span); + if (span) span.innerHTML = '<img src="<$mt:StaticWebPath$>images/indicator.white.gif" height="10" width="10" alt="favoriting..." />'; + +} </mt:IfBlog> <mt:Ignore> @@ -969,36 +467,36 @@ function switchTabs( id, el ) { - var hash = document.location.hash; - if ( hash ) - hash = hash.replace( /^#/, '' ); - - if ( el === undefined && hash ) - el = hash; - else if ( el !== undefined ) - el = el.href.match( /#(.*)/ )[ 1 ]; - - var tablist = DOM.getElement( id ); - var es = tablist.getElementsByTagName( "*" ); - var tabContent, tabId; - for ( var i = 0, len = es.length; i < len; i++ ) { - if ( es[ i ].href && es[ i ].href.match( /#.*/ ) ) { - tabId = es[ i ].href.match( /#(.*)/ )[ 1 ]; - var tabContent = DOM.getElement( tabId ); - if ( tabContent === undefined ) - continue; - - if ( el ) { - if ( tabId == el ) { - DOM.addClassName( es[ i ], "active" ); - DOM.removeClassName( tabContent, "hidden" ); - } else { - DOM.removeClassName( es[ i ], "active" ); - DOM.addClassName( tabContent, "hidden" ); - } - } - } - } + var hash = document.location.hash; + if ( hash ) + hash = hash.replace( /^#/, '' ); + + if ( el === undefined && hash ) + el = hash; + else if ( el !== undefined ) + el = el.href.match( /#(.*)/ )[ 1 ]; + + var tablist = DOM.getElement( id ); + var es = tablist.getElementsByTagName( "*" ); + var tabContent, tabId; + for ( var i = 0, len = es.length; i < len; i++ ) { + if ( es[ i ].href && es[ i ].href.match( /#.*/ ) ) { + tabId = es[ i ].href.match( /#(.*)/ )[ 1 ]; + var tabContent = DOM.getElement( tabId ); + if ( tabContent === undefined ) + continue; + + if ( el ) { + if ( tabId == el ) { + DOM.addClassName( es[ i ], "active" ); + DOM.removeClassName( tabContent, "hidden" ); + } else { + DOM.removeClassName( es[ i ], "active" ); + DOM.addClassName( tabContent, "hidden" ); + } + } + } + } } function defaultInputFocus( event ) { @@ -1477,9 +975,9 @@ if (u && u.sid && cf.sid) cf.sid.value = u.sid; } - if (cf.post && cf.post.disabled) + if (cf.post.disabled) cf.post.disabled = false; - if (cf.preview_button && cf.preview_button.disabled) + if (cf.preview_button.disabled) cf.preview_button.disabled = false; mtRequestSubmitted = false; } @@ -1928,811 +1426,3 @@ </mt:IfRegistrationAllowed> </mt:IfBlog> -<mt:include module="required_42_javascript"> - - -<mt:IfBlog> -<mt:else> - <script type="text/javascript" charset="utf-8"> -</mt:IfBlog> -function conditional_block(cond, id) { - var true_block = document.getElementById(id); - var false_block = document.getElementById(id + '_else'); - if (cond) { - if (true_block) { - var display = true_block.getAttribute('mt:display_style'); - if (!display && false_block) - display = false_block.getAttribute('mt:display_style'); - if (!display) display = ''; - true_block.style.display = display; - } - if (false_block) - false_block.style.display = 'none'; - } - else { - if (true_block) - true_block.style.display = 'none'; - if (false_block) { - var display = false_block.getAttribute('mt:display_style'); - if (!display && true_block) - display = false_block.getAttribute('mt:display_style'); - if (!display) display = ''; - false_block.style.display = display; - } - } -} - -function insert_score(s_hash, id, div_id, span, span_else) { - conditional_block((s_hash[id] && s_hash[id].scored), div_id); - if (span || span_else) { - if (s_hash[id] && s_hash[id].sum) { - if (span) - span.innerHTML = s_hash[id].sum; - if (span_else) - span_else.innerHTML = s_hash[id].sum; - } - else { - if (span) - span.innerHTML = '0'; - if (span_else) - span_else.innerHTML = '0'; - } - } -} - -var favorite_cb_callbacks = []; -function favorite_cb(s_hash) { - for (var id in s_hash) { - var span = document.getElementById('scored_' + id + '_score'); - var span_else = document.getElementById('scored_' + id + '_else_score'); - conditional_block((s_hash[id] && s_hash[id].scored), 'scored_' + id); - // insert_score(s_hash, id, 'scored_' + id, span, span_else); - } - for (var idx in favorite_cb_callbacks) { - favorite_cb_callbacks[idx](s_hash); - } -} - -function anchor(id, eid, cl, score) { - var span = document.getElementById(id); - if (span) { - var elem = span.parentNode; - var func; - if (score) - func = function(evt) { favorite(evt, eid, score) }; - else - func = function(evt) { favorite(evt, eid, id) }; - var a = document.createElement('a'); - a.href = 'javascript:void(0);'; - if (cl) a.className = cl; - attachEvent(a, 'click', func); - a.appendChild(span); - elem.appendChild(a); - } -} - -function attachEvent(element, eventName, func) { - if( !element ) - return; - if( element.addEventListener ) - element.addEventListener( eventName, func, true ); - else if( element.attachEvent ) - element.attachEvent( "on" + eventName, func ); - else - element[ "on" + eventName ] = func; -} - -function detachEvent(element, eventName, func) { - if( !element ) - return; - if( element.removeEventListener ) - element.removeEventListener( eventName, func, true ); - else if( element.detachEvent ) - element.detachEvent( "on" + eventName, func ); - else - element[ "on" + eventName ] = null; -} - -function getXmlHttp() { - if ( !window.XMLHttpRequest ) { - window.XMLHttpRequest = function() { - var types = [ - "Microsoft.XMLHTTP", - "MSXML2.XMLHTTP.5.0", - "MSXML2.XMLHTTP.4.0", - "MSXML2.XMLHTTP.3.0", - "MSXML2.XMLHTTP" - ]; - - for ( var i = 0; i < types.length; i++ ) { - try { - return new ActiveXObject( types[ i ] ); - } catch( e ) {} - } - - return undefined; - }; - } - if ( window.XMLHttpRequest ) - return new XMLHttpRequest(); -} - -function favorite(evt, entry_id, score_span) { - var xh = getXmlHttp(); - if (!xh) return false; - evt = evt || event; - var src = evt.target || evt.srcElement; - if (src) detachEvent(src, 'click', arguments.callee); - - var url = '/mt/mt-cp.cgi'; - try { - xh.open('POST', url, true); - xh.onreadystatechange = function() { - if ( xh.readyState == 4 ) { - if ( xh.status && ( xh.status != 200 ) ) { - // error - ignore - } else { - eval(xh.responseText); - } - } - }; - xh.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' ); - xh.send( '__mode=vote&blog_id=<$MTBlogID$>&f=scored,sum&jsonp=favorite_cb&id=' + entry_id); - var span = document.getElementById(score_span); - if (span) span.innerHTML = '<img src="<MTStaticWebPath$>images/indicator.white.gif" height="10" width="10" alt="voting..." />'; - } catch (e) { - - } -} - -function hideDocumentElement(id) { - var el = document.getElementById(id); - if (el) el.style.display = 'none'; -} - -function showDocumentElement(id) { - var el = document.getElementById(id); - if (el) el.style.display = 'block'; -} - -<Mt:Ignore> -function showAnonymousForm() { - showDocumentElement('comments-form'); -<MTIfNonEmpty tag="MTCaptchaFields"> - captcha_timer = setInterval('delayShowCaptcha()', 1000); -</MTIfNonEmpty> -} -</Mt:Ignore> -function showAnonymousForm() { - showDocumentElement('comments-form'); - showDocumentElement('comments-form-container'); -<MTIfRequireCommentEmails> - showDocumentElement('comment-form-name'); - showDocumentElement('comment-form-email'); - var o = document.getElementById('comment-author'); if (o) { o.value = 'Anonymous'; } -</MTIfRequireCommentEmails> -<MTIfNonEmpty tag="MTCaptchaFields"> - captcha_timer = setInterval('delayShowCaptcha()', 1000); -</MTIfNonEmpty> -} -<MTIfNonEmpty tag="MTCaptchaFields"> -var captcha_timer; -function delayShowCaptcha() { - clearInterval(captcha_timer); - var div = document.getElementById('comments-open-captcha'); - if (div) { - div.innerHTML = '<$MTCaptchaFields$>'; - } -} -</MTIfNonEmpty> - -var commenter_name; -var commenter_blog_ids; -var is_preview; -var mtcmtmail; -var mtcmtauth; -var mtcmthome; - -function check_permission(commenter_name, entry_id, blog_id, commenter_id, commenter_url) { - if ( !commenter_name ) - return false; - - if ( commenter_name && - ( !commenter_id - || commenter_blog_ids.indexOf("'" + blog_id + "'") > -1)) - return true; - - var xh = getXmlHttp(); - if (!xh) return false; - - var url = '<$MTCGIPath$><$MTCommunityScript$>'; - xh.open('POST', url, false); - xh.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); - xh.send('__mode=check_perm_js&blog_id=' + blog_id); - if ( xh.status && ( xh.status != 200 ) ) { - return false; - } else { - var result = eval('(' + xh.responseText + ')'); - if (result && (result.result.blog_id)) { - commenter_blog_ids += ",'" + result.result.blog_id + "'"; - return true; - } - } - return false; -} - -var user; -var user_id; -var can_post_entry = false; -var magic_token; -<mt:IfBlog> -//document.write('<script type="text/javascript" src="<$MTCGIPath$><$MTCommunityScript$>?__mode=loggedin_js&blog_id=<MTBlogID>"></script>'); -<mt:else> - </script> - <mt:ignore><script type="text/javascript" src="<$MTCGIPath$><$MTCommunityScript$>?__mode=loggedin_js"></script></mt:ignore> - <script type="text/javascript" charset="utf-8"> -</mt:IfBlog> - -<mt:IfBlog> -function individualArchivesOnLoad(commenter_name) { - <MTIfCommentsAccepted> - <MTElse> - hideDocumentElement('comments-open'); - </MTIfCommentsAccepted> - <MTIfPingsAccepted> - <MTElse> - hideDocumentElement('trackbacks-info'); - </MTIfPingsAccepted> - <MTIfRegistrationAllowed> - <MTIfRegistrationRequired> - if ( commenter_name && - ( !commenter_id - || commenter_blog_ids.indexOf("'<$MTBlogID$>'") > -1)) - { - hideDocumentElement('comment-form-name'); - hideDocumentElement('comment-form-email'); - showDocumentElement('comments-open-text'); - showDocumentElement('comments-open-footer'); - } else { - hideDocumentElement('comments-open-data'); - hideDocumentElement('comments-open-text'); - hideDocumentElement('comments-open-footer'); - } - <MTElse> - // comments are allowed but registration not required - if ( commenter_name && - ( !commenter_id - || commenter_blog_ids.indexOf("'<$MTBlogID$>'") > -1)) - { - hideDocumentElement('comment-form-name'); - hideDocumentElement('comment-form-email'); - } else if (is_preview) { - <MTIfNonEmpty tag="MTCaptchaFields"> - delayShowCaptcha(); - </MTIfNonEmpty> - } else { - hideDocumentElement('comments-form'); - } - </MTIfRegistrationRequired> - </MTIfRegistrationAllowed> - if (document.comments_form) { - if (!commenter_name && (document.comments_form.email != undefined) && - (mtcmtmail = getCookie("mtcmtmail"))) - document.comments_form.email.value = mtcmtmail; - if (!commenter_name && (document.comments_form.author != undefined) && - (mtcmtauth = getCookie("mtcmtauth"))) - document.comments_form.author.value = mtcmtauth; - if (document.comments_form.url != undefined && - (mtcmthome = getCookie("mtcmthome"))) - document.comments_form.url.value = mtcmthome; - if (document.comments_form["bakecookie"]) { - if (mtcmtauth || mtcmthome) { - document.comments_form.bakecookie.checked = true; - } else { - document.comments_form.bakecookie.checked = false; - } - } - } -} -</mt:IfBlog> - -// Copyright (c) 1996-1997 Athenia Associates. -// http://www.webreference.com/js/ -// License is granted if and only if this entire -// copyright notice is included. By Tomer Shiran. - - function setCookie (name, value, expires, path, domain, secure) { - var curCookie = name + "=" + escape(value) + (expires ? "; expires=" + expires.toGMTString() : "") + - (path ? "; path=" + path : "") + (domain ? "; domain=" + domain : "") + (secure ? "secure" : ""); - document.cookie = curCookie; - } - - function getCookie (name) { - var prefix = name + '='; - var c = document.cookie; - var nullstring = ''; - var cookieStartIndex = c.indexOf(prefix); - if (cookieStartIndex == -1) - return nullstring; - var cookieEndIndex = c.indexOf(";", cookieStartIndex + prefix.length); - if (cookieEndIndex == -1) - cookieEndIndex = c.length; - return unescape(c.substring(cookieStartIndex + prefix.length, cookieEndIndex)); - } - - function deleteCookie (name, path, domain) { - if (getCookie(name)) - document.cookie = name + "=" + ((path) ? "; path=" + path : "") + - ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT"; - } - - function fixDate (date) { - var base = new Date(0); - var skew = base.getTime(); - if (skew > 0) - date.setTime(date.getTime() - skew); - } - - function rememberMe (f) { - var now = new Date(); - fixDate(now); - now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000); - now = now.toGMTString(); - if (f.author != undefined) - setCookie('mtcmtauth', f.author.value, now, '/', '', ''); - if (f.email != undefined) - setCookie('mtcmtmail', f.email.value, now, '/', '', ''); - if (f.url != undefined) - setCookie('mtcmthome', f.url.value, now, '/', '', ''); - } - - function forgetMe (f) { - deleteCookie('mtcmtmail', '/', ''); - deleteCookie('mtcmthome', '/', ''); - deleteCookie('mtcmtauth', '/', ''); - f.email.value = ''; - f.author.value = ''; - f.url.value = ''; - } - -// Profile Functions - - req = null; - function getCommenterName() { - cValue = ""; - dc = document.cookie; - cookies = dc.split(";"); - for (x=0;x<cookies.length;x++) { - if (cookies[x].match(/commenter_name=/)) { - cValue = cookies[x].replace(/commenter_name=/, ""); - } - } - if (cValue.length>1) { - return unescape(cValue); - } else { - return ""; - } - } - - function trimString (str) { - str = this != window? this : str; - return str.replace(/^\s+/g, '').replace(/\s+$/g, ''); - } - -<mt:IfBlog> - <MTIfRegistrationAllowed> -if ('<$MTCGIHost exclude_port="1"$>' != '<$MTBlogHost exclude_port="1"$>') { - document.write('<script type="text/javascript" src="<$MTCGIPath$><$MTCommentScript$>?__mode=cmtr_name_js"></script>'); -} else { - commenter_name = getCookie('commenter_name'); - ids = getCookie('commenter_id').split(':'); - commenter_id = ids[0]; - commenter_blog_ids = ids[1]; - commenter_url = getCookie('commenter_url'); -} - </MTIfRegistrationAllowed> -</mt:IfBlog> - -defined = function( x ) { return x !== undefined; }; - -if ( !window.Event ) - try { window.Event = {} } catch(e) { }; - -Event.prep = function( ev ) { - ev = ev || window.event; - if( !defined( ev.stop ) ) - ev.stop = this.stop; - if( !defined( ev.target ) ) - ev.target = ev.srcElement; - if( !defined( ev.relatedTarget ) ) { - ev.relatedTarget = (event.type == "mouseover" || event.type == "mouseenter") - ? ev.fromElement - : ev.toElement; - } - return ev; - }; - -if ( !window.DOM ) - DOM = { - - getElement: function( e ) { - return (typeof e == "string" || typeof e == "number") ? document.getElementById( e ) : e; - }, - - - addEventListener: function( e, en, f, uc ) { - try { - if( e.addEventListener ) - e.addEventListener( en, f, uc ); - else if( e.attachEvent ) - e.attachEvent( "on" + en, f ); - else - e[ "on" + en ] = f; - } catch( e ) {} - }, - - - getClassNames: function( e ) { - if( !e || !e.className ) - return []; - return e.className.split( /\s+/g ); - }, - - - hasClassName: function( e, cn ) { - e = DOM.getElement( e ); - if( !e || !e.className ) - return false; - var cs = DOM.getClassNames( e ); - for( var i = 0; i < cs.length; i++ ) { - if( cs[ i ] == cn ) - return true; - } - return false; - }, - - - addClassName: function( e, cn ) { - e = DOM.getElement( e ); - if( !e || !cn ) - return false; - var cs = DOM.getClassNames( e ); - for( var i = 0; i < cs.length; i++ ) { - if( cs[ i ] == cn ) - return true; - } - cs.push( cn ); - e.className = cs.join( " " ); - return false; - }, - - - removeClassName: function( e, cn ) { - var r = false; - e = DOM.getElement( e ); - if( !e || !e.className || !cn ) - return r; - var cs = (e.className && e.className.length) - ? e.className.split( /\s+/g ) - : []; - var ncs = []; - /* support regex */ - if( cn instanceof RegExp ) { - for( var i = 0; i < cs.length; i++ ) { - if ( cn.test( cs[ i ] ) ) { - r = true; - continue; - } - ncs.push( cs[ i ] ); - } - } else { - for( var i = 0; i < cs.length; i++ ) { - if( cs[ i ] == cn ) { - r = true; - continue; - } - ncs.push( cs[ i ] ); - } - } - if( r ) - e.className = ncs.join( " " ); - return r; - } - - }; - - -function switchTabs( id, el ) { - var hash = document.location.hash; - if ( hash ) - hash = hash.replace( /^#/, '' ); - - if ( el === undefined && hash ) - el = hash; - else if ( el !== undefined ) - el = el.href.match( /#(.*)/ )[ 1 ]; - - var tablist = DOM.getElement( id ); - var es = tablist.getElementsByTagName( "*" ); - var tabContent, tabId; - for ( var i = 0, len = es.length; i < len; i++ ) { - if ( es[ i ].href && es[ i ].href.match( /#.*/ ) ) { - tabId = es[ i ].href.match( /#(.*)/ )[ 1 ]; - var tabContent = DOM.getElement( tabId ); - if ( tabContent === undefined ) - continue; - - if ( el ) { - if ( tabId == el ) { - DOM.addClassName( es[ i ], "active" ); - DOM.removeClassName( tabContent, "hidden" ); - } else { - DOM.removeClassName( es[ i ], "active" ); - DOM.addClassName( tabContent, "hidden" ); - } - } - } - } -} - -function defaultInputFocus( event ) { - try { - event = Event.prep( event ); - } catch( e ) {}; - - var el = event.target; - if ( el.value == el.getAttribute( "mt:default" ) ) { - el.value = ''; - DOM.removeClassName( el, "input-default" ); - } -} - -function defaultInputBlur( event ) { - try { - event = Event.prep( event ); - } catch( e ) {}; - - var el = event.target; - if ( el.value == '' ) { - el.value = el.getAttribute( "mt:default" ); - DOM.addClassName( el, "input-default" ); - } -} - -function setupInputDefault() { - var es = document.getElementsByTagName( "INPUT" ); - for ( var i = 0, len = es.length; i < len; i++ ) { - if ( !es[ i ].getAttribute ) - continue; - var val = es[ i ].getAttribute( "mt:default" ); - if ( !val ) - continue; - - if ( es[ i ].value == '' ) { - DOM.addClassName( es[ i ], 'input-default' ); - es[ i ].value = val; - } - DOM.addEventListener( es[ i ], 'focus', defaultInputFocus ); - DOM.addEventListener( es[ i ], 'focusin', defaultInputFocus ); - DOM.addEventListener( es[ i ], 'blur', defaultInputBlur ); - } -} - - -function init(){ - if (arguments.callee.done) return; - arguments.callee.done = true; - window.setTimeout(setupInputDefault, 200); - $(document).ready(function(){ setupMenu(); }); - -} - -/* fast start init */ -/* moz */ -if ( document.addEventListener ) { - document.addEventListener( "DOMContentLoaded", init, false ); -} else if (window.attachEvent) { - window.attachEvent('onload', init); -} -/* ie */ -/*@cc_on @*/ -/*@if (@_win32) - // document.write("<script defer src='<$MTStaticWebPath$>addons/Community.pack/js/ie_onload.js'><\/script>"); -/*@end @*/ - -/* others */ -window.onload = init; - - - -function writeCommenterGreeting(commenter_name, entry_id, blog_id, commenter_id, commenter_url) { -<MTIfRegistrationAllowed> - if ( check_permission(commenter_name, entry_id, blog_id, commenter_id, commenter_url) ) - { - var url; - if (commenter_id) { - url = '<$MTCGIPath$><$MTCommunityScript$>?__mode=edit&return_to=' + encodeURIComponent(document.URL) + '&id=' + commenter_id + '&blog_id=' + blog_id; - } else if (commenter_url) { - url = commenter_url; - } else { - url = null; - } - var content = 'Thanks for signing in, '; - if (url) { - content += '<a href="' + url + '">' + commenter_name + '</a>'; - } else { - content += commenter_name; - } - content += '. Now you can comment. (<a href="<$MTRemoteSignOutLink static="1"$>&entry_id=' + entry_id + '">sign out</a>)'; - document.write(content); - } else if (commenter_name) { - document.write('You do not have permission to comment on this blog. (<a href="<$MTRemoteSignOutLink static="1"$>&entry_id=' + entry_id + '">sign out</a>)'); - } else { -<MTIfRegistrationRequired> - document.write('<a href="<$MTCGIPath$><$MTCommunityScript$>?__mode=login&blog_id=<mt:blogid>&return_to=' + encodeURIComponent(document.URL) + '">Sign in' + '</a>' + ' to comment on this entry.'); -<MTElse> - document.write('<a href="<$MTCGIPath$><$MTCommunityScript$>?__mode=login&blog_id=<mt:blogid>&return_to=' + encodeURIComponent(document.URL) + '">Sign in' + '</a>' + ' to comment on this entry, or <a href="javascript:void(0);" onclick="showAnonymousForm();">comment anonymously.</a>'); -</MTIfRegistrationRequired> - } -</MTIfRegistrationAllowed> -} - - function loggedin_process(loggedin, eid) { - if (!loggedin) - loggedin = commenter_name ? true : false; - conditional_block(loggedin, eid); - var result = []; - var greet; - if (user) { - // MT Native User - result.push('<div class="profile-text"><h6>Hello <a href="<mt:CGIPath><mt:CommunityScript>?__mode=view&id=' + user_id + '">' + user + '</a></h6>\n'); - result.push('<p><a href="<mt:CGIPath><mt:CommunityScript>?__mode=edit&blog_id=1&return_to=' + encodeURIComponent(document.URL) + '">Edit Profile</a> <span class="separator">|</span>'); - result.push('<a href="<mt:CGIPath><mt:CommunityScript>?__mode=logout&blog_id=1&return_to=' + encodeURIComponent(document.URL) + '">Log out</a></p></div>\n'); - greet = document.getElementById('loggedin_greeting'); - } - else { - result.push('<div class="profile-text"><p><a href="<mt:CGIPath><mt:CommunityScript>?__mode=login&blog_id=1&return_to=' + encodeURIComponent(document.URL) + '">Sign in</a> <span class="separator">|</span>'); - result.push('Not a member? <a href="<mt:CGIPath><mt:CommunityScript>?__mode=register&blog_id=1&return_to=' + encodeURIComponent(document.URL) + '">Register</a></p>\n'); - greet = document.getElementById('loggedin_greeting_else'); - - } - if (!greet) return; - greet.innerHTML = result.join('\n'); - } - - function comment_loggedin_process(loggedin, eid) { - if (!loggedin){ - //loggedin = commenter_name ? true : false; - var m_user = mtGetUser(); - loggedin = m_user && !m_user.is_anonymous ? true : false; - } -<MTIfRegistrationNotRequired> - // anonymous commenters are not logged in but need to preview their comments too. - // if global var is_preview is true, then fein a loggedin state to enable preview - if (!loggedin <MT:Ignore>&& window['is_preview']</MT:Ignore>) { - loggedin = true; -<MTIfRequireCommentEmails> - showDocumentElement('comment-form-name'); - showDocumentElement('comment-form-email'); -</MTIfRequireCommentEmails> - } -</MTIfRegistrationNotRequired> - conditional_block(loggedin, eid); - } - -// Sidebar Most- Widget Show/Hide - -function setupMenu() { - $("#recent-content").hide(); - $("#recommended-content").hide(); - $("#recommended-title").click(function() { - if ($("#recommended-content").is(":hidden")) { - $("#recommended-content").slideDown(); - $("#recent-content,#popular-content").slideUp(); - $("#recommended-title").css({ backgroundImage: "url('<$MTBlogURL$>images/most_recommended_hover.gif')" }); - $("#popular-title").css({ backgroundImage: "url('<$MTBlogURL$>images/most_popular.gif')" }); - $("#recent-title").css({ backgroundImage: "url('<$MTBlogURL$>images/most_recent.gif')" }); - return false; - } - return false; - }); - $("#recent-title").click(function() { - if ($("#recent-content").is(":hidden")) { - $("#recent-content").slideDown(); - $("#recommended-content,#popular-content").slideUp(); - $("#recent-title").css({ backgroundImage: "url('<$MTBlogURL$>images/most_recent_hover.gif')" }); - $("#popular-title").css({ backgroundImage: "url('<$MTBlogURL$>images/most_popular.gif')" }); - $("#recommended-title").css({ backgroundImage: "url('<$MTBlogURL$>images/most_recommended.gif')" }); - return false; - } - return false; - }); - $("#popular-title").click(function() { - if ($("#popular-content").is(":hidden")) { - $("#popular-content").slideDown(); - $("#recent-content,#recommended-content").slideUp(); - $("#popular-title").css({ backgroundImage: "url('<$MTBlogURL$>images/most_popular_hover.gif')" }); - $("#recommended-title").css({ backgroundImage: "url('<$MTBlogURL$>images/most_recommended.gif')" }); - $("#recent-title").css({ backgroundImage: "url('<$MTBlogURL$>images/most_recent.gif')" }); - return false; - } - return false; - }); -} - -function insertTexasAd(){ - var targetContainer = document.getElementById('header-blog'); - var newDiv = document.createElement('div'); - newDiv.className = 'texas-widget-contianer clearFix'; -newDiv.style.position= 'absolute'; -newDiv.style.top = '15px'; -newDiv.style.left = '255px'; - - var img1 = document.createElement('img'); - img1.src = 'http://static.amctv.com/amc-widgets/texas-ad/img/texas-ad.png'; - img1.className = 'texas-ad'; - - var img2 = document.createElement('img'); - img2.src = 'http://static.amctv.com/amc-widgets/texas-ad/img/sxsw-ad.png'; - img2.className = 'sxsw-ad'; - img2.onclick = function(){ - } - img1.onclick = function(){ - - } - - //newDiv.appendChild(img2); - newDiv.appendChild(img1); - - - targetContainer.appendChild(newDiv); -} - -// limit submit to one instance per post - -var startTalking = { - disableSubmit:function() { - jQuery(document.forms.startTalkingForm).submit(function() { - jQuery('input[type=image]', this).attr('disabled', 'disabled'); - }); - - } -}; -jQuery(document).ready(startTalking.disableSubmit); - -function injectQuant(scriptLocation){var getHeader=document.getElementsByTagName("head")[0];var newScript=document.createElement('script');newScript.type="text/javascript";newScript.src=scriptLocation;getHeader.appendChild(newScript);}setTimeout("injectQuant('http://blogs.amctv.com/quantcast/quantcast-injects.js')",100); -document.domain = "amctv.com"; - -deleteCookie ('commenter_id', '/', '.blog.amctv.com'); -deleteCookie ('commenter_name', '/', '.blog.amctv.com'); -deleteCookie ('mt_commenter', '/', '.blog.amctv.com'); -deleteCookie ('mt_user', '/mt/', '.blog.amctv.com'); - - function copy(elem) { - var text2copy = elem.val(); - if (window.clipboardData) { - window.clipboardData.setData("Text",text2copy); - } else { - var flashcopier = 'flashcopier'; - if(!document.getElementById(flashcopier)) { - var divholder = document.createElement('div'); - divholder.id = flashcopier; - document.body.appendChild(divholder); - } - document.getElementById(flashcopier).innerHTML = ''; - var divinfo = '<embed src="/swf/_clipboard.swf" FlashVars="clipboard='+escape(text2copy)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>'; - document.getElementById(flashcopier).innerHTML = divinfo; - } -} - - - -<mt:IfBlog> -<mt:else> - - - - </script> -</mt:IfBlog> - -<!-- --> \ No newline at end of file
This paste will be private.
From the Design Piracy series on my blog: