Skip to content

Instantly share code, notes, and snippets.

@tylersticka
Created January 19, 2012 04:04
Show Gist options
  • Save tylersticka/1637746 to your computer and use it in GitHub Desktop.
Save tylersticka/1637746 to your computer and use it in GitHub Desktop.
/*
* Plugin for creating new windows in JS
*/
(function($){
$.newWindow = function (el, w, h) {
var base = this;
base.$el = $(el);
base.init = function () {
base.features = 'width=' + w + ',height=' + h + ',left=' + ((screen.width-w)/2) + ',top=' + ((screen.height-h)/2 - 110);
base.$el.click(base.open);
}
base.open = function (e) {
e.preventDefault();
base.win = window.open(base.$el.attr('href'), 'newWindow' + (Math.round(Math.random() * 999999)), base.features);
}
base.init();
}
$.fn.newWindow = function (w, h, pos) {
return this.each(function(){
(new $.newWindow(this, w, h, pos));
});
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment