Signin  Pricing  Examples  Support

Libraries > daily-puzzle.js

daily-puzzle.js - Search Live Website Code
It's like doing CTRL+F on millions of websites' source code



NerdyData is a search engine for source code. Search the source code of 200 million websites.


JAVASCRIPT FILE http://gameknot.com/daily-puzzle.js

Function Explorer








Libraries on gameknot.com


common.js

social-connect.js



Explore More


jquery.js

lang.js

misc.js

scripts.js

daily-puzzle.js
				
    
var head = document.getElementsByTagName('head')[0];

var styles =
    '#gk-daily-puzzle td { border: 0px !important; vertical-align: middle !important; }\n'+
    '.boardlabel td { font-size: 75% !important; text-align: center !important; padding: 0px !important; margin: 0px !important; overflow: hidden !important; }\n';

var css = document.createElement('style');
css.type = 'text/css';
if (css.styleSheet) css.styleSheet.cssText = styles;
	       else css.appendChild(document.createTextNode(styles));
head.appendChild(css);

var e = document.createElement('script');
e.type = 'text/javascript';
e.src = '//gameknot.com/js/chess-diagram-ext.js';
head.appendChild(e);

var ie_version = parseFloat(navigator.appVersion.split('MSIE')[1]);

var gk_board_style = 5;
var gk_board_size;
var gk_board_color = 14;
var gk_board_padding = 40;

function gk_get_el(name)
{
    var d = document;
    if (d.getElementById) return d.getElementById(name);
    if (d.all) return d.all[name];
    return null;
}

function gk_get_glop(num,_default)
{
    if (num==14) return gk_board_style; 	// style
    if (num==15) return gk_board_size;		// size
    if (num==16) return gk_board_color+1;	// color
    return _default;
}

function prnd( seed )
{
    this.rnd = function( max )
    {
	this.iterate();
	return Math.floor(this.seed / 65536) % max;
    };
    
    this.iterate = function()
    {
	this.seed = ( this.seed * 1103515245 + 12345 ) & 0x7fffffff;
    };
    
    this.seed = (typeof seed)=='undefined' ? get_time() : seed;
}

function popwindow(path,w,h)
{
    var x = Math.floor( (window.screen.width-w)/2 );
    var y = Math.floor( (window.screen.height-h)/2 );
    if ((x+w)>window.screen.availWidth) x = window.screen.availWidth - w;
    if ((y+h)>window.screen.availHeight) y = window.screen.availHeight - h;

    var params = 'left='+x+',top='+y+',width='+w+',height='+h+',resizable=1,toolbar=0,location=0,directories=0,status=1,menubar=0';
    var ww = window.open(path,'_blank',params);
    if (ww)
    {
	ww.focus();
    }
    else
    {
	alert('Pop-up windows appear to be blocked on your computer. Unable to proceed...');
    }
}

var gk_main_div_name = 'gk-daily-puzzle';
var gk_element_old_text = '';

var o = gk_get_el(gk_main_div_name);
if (o && !o.gk_processed)
{
    o.gk_processed = 1;
    
    gk_element_old_text = o.innerHTML;

    var b_border = 1;
    
    var reg_ops = /<!--\s*(.+?)\s*-->/;
    var reg_split = /(\w)=(\d+)/g;
    
    var ops = reg_ops.exec(gk_element_old_text);
    if (ops && ops.length>0)
    {
	ops = ops[1];
	var op;
	while( op = reg_split.exec(ops) )
	{
	    if (!op || op.length<3) continue;
	    var key = op[1];
	    var val = parseInt(op[2]);
	    if (key=='s') gk_board_size = val;
	    if (key=='c') gk_board_color = val;
	    if (key=='p') gk_board_style = val;
	    if (key=='b') b_border = val;
	}
    }
    
    if (o.className=='gk-mini') b_border = 0;
    
    var os = o.style;

    os.lineHeight = '100%';
    os.textAlign = 'center';
    if (b_border)
    {
	os.border = '1px dotted #444455';
	os.padding = '5px';
    }
    else
    {
	gk_board_padding = 10;
	os.padding = '10px 0px';
    }

    o.innerHTML = 'Loading...';
    
    window.setTimeout( 'gk_launch_daily_puzzle()', 100 );
}

function gk_launch_daily_puzzle()
{
    var o = gk_get_el(gk_main_div_name);
    if (!o) return;

    if ( (typeof draw_chess_diagram)!='function' )
    {
	window.setTimeout( 'gk_launch_daily_puzzle()', 200 );
	return;
    }

    if (!gk_board_size)
    {
	gk_board_size = 2;
	while(gk_board_size<4)
	{
	    if ( ((gk_board_size+1)*80 + gk_board_padding) >= o.clientWidth ) break;
	    gk_board_size++;
	}
    }

    var os = o.style;
    os.width = ( gk_board_size*80 + gk_board_padding )+'px';
    os.margin = 'auto';

    var board_div_name = 'chess-puzzle'+Math.random();

    var url = 'http://gameknot.com/chess-puzzle.pl?pz=16763&daily=2';

    o.innerHTML = 
	'<table border=0 cellspacing=0 cellpadding=0 style="text-align: center;">'+
	'<tr><td style="text-align: left;"><div style="float: right; font-size: 80%;">&raquo; <a href="http://gameknot.com/" target="_blank">GameKnot.com</a></div><b>Daily puzzle:</b></td></tr>'+
	'<tr><td onClick="popwindow(\''+url+'\',700,680)" style="cursor:pointer;" title="click to solve the puzzle">'+
	'<div id="gk-daily-puzzle-board"></div>'+
	'</td></tr>'+
	'<tr><td style="text-align: center;">'+
	'<a href="javascript:popwindow(\''+url+'\',700,680)" title="click to solve the puzzle">White to move, mate in 2</a>'+
	'</td></tr>'+
	'</table>'+
	'<noscript><h1 style="font-size: 50%">'+gk_element_old_text+'</h1></noscript>';
    
    if (!gk_render_puzzle_board()) setTimeout( "gk_render_puzzle_board()", 100 );
}

function gk_render_puzzle_board() 
{
    var o = gk_get_el('gk-daily-puzzle-board');
    if (!o) return 0;
    draw_chess_diagram( o, 'N3Kb2/5p2/p1p5/rknb3R/nB5R/4QNp1/4r1q1/5B2 w - -', gk_board_size );
    return 1;
}



A B C D E F G H I J K L M N O P Q R S T U V W X Y Z