/*** DOCUMENTATION LAYER moshi myspace 95 thesis widget (m95.wx.js) Author: Tom at klenwell@gmail.com Last Updated: Nov 2006 FUNCTIONS wx_m95() wx_m95_html(text, num) js_get_script_path(js_fname) js_rand(min, max) NOTES To link: To display widget:
The following css settings may be used to modify appearance RECOMMENDED #m95_wrap { position:absolute; top:10px; right:10px; } .m95_wx { font-family:"Palatino Linotype", "Book Antiqua", Palatino, serif; font-size:14px; font-style:italic; font-weight:bold; color:#330000; } .m95_wx a { color:#993300; text-decoration:none; } .m95_wx a:hover { color:#ff9900; } OPTIONAL .m95_mid {} .m95_text {} .m95_num {} .m95_top {} DEPENDENCIES requires three image files for background: m95_top.png, m95_mid.png, m95_btm.png LICENSE GPL (see http://www.gnu.org/copyleft/gpl.html) This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY, &c. ______________________________________________________________________________*/ // global parameters var debug = 0; // debugging on? var list95_src_fname = 'm95.src.js' // thesis source file var m95_css_fname = 'm95.css'; var js_fname = 'm95.wx.js'; // this file (for autostyling below) // autostyle if ( typeof m95_autostyle == 'undefined' ) m95_autostyle = 0; // get script path var dir_path = js_get_script_path(js_fname); // background images var bg_top_src = dir_path + 'm95_top.png'; var bg_mid_src = dir_path + 'm95_mid.png'; var bg_btm_src = dir_path + 'm95_btm.png'; var list95_src = dir_path + list95_src_fname; // load thesis source file document.write(''); // wx_myspace95thesis /*____________________________________________________________________________*/ function wx_m95() { // *** DATA // hard parameters _debug = 0; // *** MANIPULATE // sanity check if ( !LIST95.length ) { if ( debug ) alert('95thesis array empty!'); return; } // num items in list var len = LIST95.length; // get random number var idx = js_rand(0, len-1); // get thesis selection selection = LIST95[idx]; // get number of entry num = ( idx == len-1 ) ? 95 : idx + 1; // build html for display m95_html = wx_m95_html(selection, num); // display document.write(m95_html); // return (void) return; } // end Fx /*____________________________________________________________________________*/ // wx_myspace95thesis /*____________________________________________________________________________*/ function wx_m95_html(text, num) { // *** DATA // elements var top_block = ''; var num_block = ''; var mid_block = ''; var m95_footer = ''; var yanker = ''; // return var html = ''; // *** MANIPULATE // internal style settings top_block_style = 'height:34px; background-image:url(' + bg_top_src + '); background-repeat:no-repeat; background-position:top center;'; mid_block_style = 'background-image:url(' + bg_mid_src + '); background-repeat:repeat-y; background-position:top center; padding:2px 20px;'; wx_style = 'position:relative; width:180px; padding-bottom:24px; background-image:url(' + bg_btm_src + '); background-repeat:no-repeat; background-position:bottom center; overflow:hidden; z-index:10;' num_style = 'font-size:1.4em; padding-left:1em; font-weight:bold;'; // top block top_block = '
'; // build num block if ( !isNaN(num) ) num_block = '
#' + num + '
'; // build text block m95_text = '
' + text + '
'; // build footer m95_footer = '
'; m95_footer += 'from the myspace 95 thesis'; m95_footer += '
for more info, click here
'; // build mid block mid_block = '
' + num_block + m95_text + m95_footer + '
'; // build yanker yanker = '
« yoink! »
'; // assemble block html = '
' + top_block + mid_block + yanker + "
"; // *** RETURN return html; } // end Fx /*____________________________________________________________________________*/ // js_get_script_path /*____________________________________________________________________________*/ function js_get_script_path(js_fname) { var _regex = js_fname; var _debug = 0; var _SCRIPTS = new Array(); var script_path = ""; // return // Get Script Tag Array _SCRIPTS = document.getElementsByTagName('script'); // Loop Search for m95 tag for ( i=0; i<_SCRIPTS.length; i++ ) { var _src = _SCRIPTS[i].src if ( _debug ) alert(_src); if ( _src.search(_regex) != -1 ) { if ( _debug ) alert('script_path [' + _src + '] found!'); script_path = _src.substr(0, _src.lastIndexOf('/') + 1); break; } } if ( _debug ) alert('returning script_path [' + script_path + ']'); return script_path; } /*____________________________________________________________________________*/ // Returns a random integer between min and max // Using Math.round() will give you a non-uniform distribution! // Source: http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Math:random function js_rand(min, max) { return Math.floor(Math.random() * (max - min + 1) + min); }