Skip to content

Instantly share code, notes, and snippets.

@Jacke
Created January 16, 2013 10:00
Show Gist options
  • Select an option

  • Save Jacke/4546035 to your computer and use it in GitHub Desktop.

Select an option

Save Jacke/4546035 to your computer and use it in GitHub Desktop.
Shake object with tag form w/o jquery
addLoadEvent = function (func) {
if (typeof jQuery != "undefined") jQuery(document).ready(func);
else if (typeof wpOnload != 'function') {
wpOnload = func;
} else {
var oldonload = wpOnload;
wpOnload = function () {
oldonload();
func();
}
}
};
function s(id, pos) {
g(id).left = pos + 'px';
}
function g(id) {
return document.getElementById(id).style;
}
function shake(id, a, d) {
c = a.shift();
s(id, c);
if (a.length > 0) {
setTimeout(function () {
shake(id, a, d);
}, d);
} else {
try {
g(id).position = 'static';
wp_attempt_focus();
} catch (e) {}
}
}
addLoadEvent(function () {
var p = new Array(15, 30, 15, 0, -15, -30, -15, 0);
p = p.concat(p.concat(p));
var i = document.forms[0].id;
g(i).position = 'relative';
shake(i, p, 20);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment