Skip to content

Instantly share code, notes, and snippets.

@roykolak
Created January 28, 2009 22:49
Show Gist options
  • Save roykolak/54235 to your computer and use it in GitHub Desktop.
Save roykolak/54235 to your computer and use it in GitHub Desktop.
Popup class
function PopupClass(link, launch_now) {
if(link !== undefined) {
if(typeof link == "string") {
var link = $("#"+link);
}
this.href = link.attr('href');
this.title = link.attr('title');
this.properties = this.setProperties();
if(launch_now !== undefined && launch_now == true) {
return this.launch();
}
}
}
PopupClass.prototype.setProperties = function() {
return { scrollbars:true, toolbar:false, status:false, width:800, height:600, resizable:true };
}
PopupClass.prototype.boolToInt = function(bool) {
return (bool ? 1 : 0);
}
PopupClass.prototype.buildPropertiesString = function() {
var properties = "";
for(var key in this.properties) {
if(typeof this.properties[key] == "boolean") {
this.properties[key] = this.boolToInt(this.properties[key]);
}
properties = properties + key + '=' + this.properties[key] + ',';
}
// return string minus the last comma
return properties.substring(0, (properties.length - 1));
}
PopupClass.prototype.launch = function() {
return window.open(this.href, this.title, this.buildPropertiesString());
}
// Inheritance helper
function inherit(subclass, superclass) {
var temp = function() {};
temp.prototype = superclass.prototype;
subclass.prototype = new temp();
}
// New Custom Popup Class
CustomPopupClass = function(link, launch_now) {
PopupClass.call(this, link, launch_now);
}
inherit(CustomPopupClass, PopupClass);
CustomPopupClass.prototype.setProperties = function() {
return { scrollbars:true, toolbar:false, status:false, width:360, height:300, resizable:true };
}
// Example Usage
$('a.js_CustomPopup').click(function() {
new CustomPopupClass($(this), true);
return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment