/* created on : 12/02/2015, 7:06:03 pm author : robin spark dependencies : isonscreen jquery plugin: http://upshots.org/javascript/jquery-test-if-element-is-in-viewport-visible-on-screen free for commerical purposes. */ /** * perform global replacement * @param string source contains characters to be replaced * @param string search contains characters to be searched for * @param string replacement contains the replacement characters * @returns string result of replacement */ function replaceallinstances(source, search, replacement) { var regex = new regexp(search, "g"); var result = source.replace(regex, replacement); return result; } $.fn.isonscreen = function (x, y) { if (x == null || typeof x == 'undefined') x = 1; if (y == null || typeof y == 'undefined') y = 1; var win = $(window); var viewport = { top: win.scrolltop(), left: win.scrollleft() }; viewport.right = viewport.left + win.width(); viewport.bottom = viewport.top + win.height(); var height = this.outerheight(); var width = this.outerwidth(); if (!width || !height) { return false; } var bounds = this.offset(); bounds.right = bounds.left + width; bounds.bottom = bounds.top + height; var visible = (!(viewport.right < bounds.left || viewport.left > bounds.right || viewport.bottom < bounds.top || viewport.top > bounds.bottom)); if (!visible) { return false; } var deltas = { top: math.min(1, (bounds.bottom - viewport.top) / height), bottom: math.min(1, (viewport.bottom - bounds.top) / height), left: math.min(1, (bounds.right - viewport.left) / width), right: math.min(1, (viewport.right - bounds.left) / width) }; return (deltas.left * deltas.right) >= x && (deltas.top * deltas.bottom) >= y; }; /* * init specified element so it can be gradually revealed. * * limitations: * only works on backgrounds with a solid color. * * @param options = { * id:'box3' * ,background='#ffffff' //default * ,delay='0' //default * } * */ $.fn.initreveal = function (options) { console.log('-------------'); console.log('selector:' + this.selector); var parent = $(this).parent(); //grab a copy of the contents, then remove it from dom var contents = $(this).clone(); $(this).empty(); var revealhtmlblock = "