Created
November 4, 2011 15:41
-
-
Save roundcorners/1339624 to your computer and use it in GitHub Desktop.
Class that adds functionality to help nodes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sky.home_move.Popouts = function(pod) { | |
sky.home_move.Popouts.pods.push(pod); | |
this.pod = $(pod); | |
this.helpBtn = this.pod.find('a.help').eq(0); | |
this.inputs = this.pod.find(':input:not(:image, :radio)'); | |
this.radios = this.pod.find('input[type="radio"]'); | |
this.setupEventListeners(); | |
if (sky.home_move.Popouts.pods[0]) { | |
this.errorCheck(); | |
} | |
}; | |
sky.home_move.Popouts.pods = []; | |
sky.home_move.Popouts.prototype = { | |
setupEventListeners: function() { | |
this.helpBtn.bind('click', $.proxy(this.toggleThisHelp, this)); | |
this.inputs.bind('focus', $.proxy(this.showThisHelp, this)); | |
this.radios.bind('change', $.proxy(this.showThisHelp, this)); | |
}, | |
errorCheck: function() { | |
if ((document.getElementById('errorList') !== null || false) && (this.pod.hasClass('initHelp'))) { | |
this.hideHelpInstructions(); | |
this.hideAllHelp(); | |
} | |
}, | |
hideAllHelp: function() { | |
var i, | |
pods = sky.home_move.Popouts.pods, | |
len = pods.length; | |
return (function(inst) { | |
for (i = 0; i < len; i++) { | |
if (inst.pod[0] !== pods[i]) { | |
$(pods[i]).removeClass('pod_active'); | |
} | |
$(pods[0]).removeClass('initHelp'); | |
} | |
}(this)); | |
}, | |
hideHelpInstructions: function() { | |
this.pod.removeClass('initHelp'); | |
}, | |
showThisHelp: function() { | |
this.hideAllHelp(); | |
this.pod.addClass('pod_active'); | |
}, | |
hideThisHelp: function() { | |
this.pod.removeClass('pod_active'); | |
}, | |
toggleThisHelp: function(e) { | |
if (this.pod.hasClass('pod_active')) { | |
this.hideThisHelp(); | |
} else { | |
this.showThisHelp(); | |
} | |
e.preventDefault(); | |
}, | |
teardown: function() { | |
this.inputs.unbind(); | |
this.radios.unbind(); | |
this.helpBtn.unbind(); | |
} | |
}; | |
// Create an object for each help node | |
for (i = 0; i < len; i++) { | |
if ($(pods[i]).find('a.help').length > 0) { | |
podList[pods[i]] = new hm.Popouts(pods[i]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment