Created
January 15, 2012 07:13
-
-
Save bobspryn/1614826 to your computer and use it in GitHub Desktop.
main.js
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
PP = {}; | |
// http://stackoverflow.com/questions/3075308/what-modernizer-scripts-exist-for-the-new-ecmascript-5-functions/3075818#3075818 | |
PP.object = { | |
}; | |
PP.object.create = function(o) | |
{ | |
function F() | |
{ | |
}; | |
F.prototype = o; | |
return new F(); | |
}; | |
var __hasProp = Object.prototype.hasOwnProperty; | |
PP.object.inherits = function(child, parent) { | |
for (var key in parent) { | |
if (__hasProp.call(parent, key)) child[key] = parent[key]; | |
} | |
function ctor() { this.constructor = child; } | |
ctor.prototype = parent.prototype; | |
child.prototype = new ctor; | |
child.__super__ = parent.prototype; | |
return child; | |
}; | |
PP.object.base = function(){}; | |
PP.object.base.prototype._setup = function(options, elem) | |
{ | |
default_options = { | |
errorClass: "ppStyle_Error" | |
}; | |
// Mix in the passed in options with the default options | |
this.options = $.extend(true, { | |
}, | |
this.options, options, default_options); | |
// Save the element reference, both as a jQuery | |
// reference and a normal reference | |
this.elem = elem; | |
this.$elem = $(elem); | |
this._storedEventHandlers = null; | |
return this; | |
}; | |
// for creating new jquery plugins | |
// a pattern we'll use for organizing js | |
// idea courtesy of: http://alexsexton.com/?p=51 | |
$.plugin = function(name, object) | |
{ | |
$.fn[name] = function(options) | |
{ | |
var args = Array.prototype.slice.call(arguments, 1); | |
// build the new plugin | |
var newPlugin = function(){}; | |
// plugin inherits from base | |
PP.object.inherits(newPlugin, PP.object.base); | |
// extend the plugin with the methods from our object | |
$.extend(newPlugin.prototype, object); | |
return this.each(function() | |
{ | |
var instance = $.data(this, name); | |
if (!instance) | |
{ | |
// instantiate the plugin | |
var objectInstance = new newPlugin; | |
// store it | |
instance = $.data(this, name, objectInstance._setup(options, this).init()); | |
} | |
}); | |
}; | |
}; | |
// placeholder functionality | |
$(document).ready(function() | |
{$('.close').click(function() | |
{$(this).parent().toggle('1000');});if(Modernizr.input.placeholder) | |
return;$('input[placeholder]').focus(function() | |
{if($(this).hasClass('ppStyle_Placeholder')) | |
{if($(this).val()==$(this).attr('placeholder')) | |
$(this).val('');$(this).removeClass('ppStyle_Placeholder');}});$('input[placeholder]').keypress(function() | |
{if($(this).hasClass('ppStyle_Placeholder')) | |
{if($(this).val()==$(this).attr('placeholder')) | |
$(this).val('');$(this).removeClass('ppStyle_Placeholder');}});$('input[placeholder]').blur(function() | |
{if($(this).val()!='') | |
return;$(this).addClass('ppStyle_Placeholder');$(this).val($(this).attr('placeholder'));});$('input[placeholder]').each(function() | |
{if($(this).val()!=''&&$(this).val()!=$(this).attr('placeholder')) | |
return;$(this).val($(this).attr('placeholder')).addClass('ppStyle_Placeholder');});$('form').submit(function() | |
{$(this).find('.placeholder').each(function() | |
{$(this).removeClass('ppStyle_Placeholder');$(this).val('');});});}); | |
(function (){ | |
var HomepageSplashModule = { | |
options: { | |
verbage: { | |
} | |
}, | |
init: function(options, elem) { | |
// setup module alert handlers | |
this.groups = ['A', 'B', 'C']; | |
this.$groups = {}; | |
this.$tabs = $(".ppList_HomeSplashTabs li", this.$elem); | |
$(".ppMod_HomeSplash-Images img").css({opacity: 0}); | |
this.animating = false; | |
this._setupGroups(); | |
this._startSplash(); | |
this._setupEventHandlers(); | |
}, | |
_setupGroups: function() { | |
var self = this; | |
$.each(this.groups, function (i, value) { | |
self.$groups[value] = $(".ppStyle_Group" + value, self.$elem); | |
}); | |
}, | |
_setupEventHandlers : function(){ | |
var self = this; | |
$("a", this.$tabs).click(this._eventHandlers().groupLinkHandler); | |
}, | |
_eventHandlers : function(){ | |
var self = this; | |
if(this._storedEventHandlers !== null) { | |
return this._storedEventHandlers; | |
} else { | |
return this._storedEventHandlers = { | |
groupLinkHandler: function(e){ | |
e.preventDefault(); | |
if(self.animating == false) | |
{ | |
var index = self.$tabs.index($(this).parent()); | |
self._resetInterval(); | |
self.showGroup(self.groups[index]); | |
} | |
} | |
}; | |
} | |
}, | |
_startSplash: function(){ | |
var self = this; | |
this.showGroup(this.groups[0]); | |
this._resetInterval(); | |
}, | |
_resetInterval: function() { | |
var self = this; | |
clearInterval(this.interval); | |
this.interval = setInterval(function(){ | |
self._splashInterval(); | |
},13000); | |
}, | |
_splashInterval: function() { | |
var newGroup; | |
if(this.currentGroup == this.groups.length - 1) | |
{ | |
newGroup = 0; | |
} else { | |
newGroup = this.currentGroup + 1; | |
} | |
this.showGroup(this.groups[newGroup]); | |
}, | |
showGroup : function(n) { | |
var self = this; | |
this.animating = true; | |
// n = A | |
this.oldGroup = this.currentGroup; | |
this.currentGroup = $.inArray(n,this.groups); | |
// n = A | |
if(this.oldGroup !== undefined) | |
{ | |
// fade out | |
this.$groups[this.groups[this.oldGroup]].filter("img").animate({opacity: 0}); | |
this.$groups[this.groups[this.oldGroup]].removeClass("ppStyle_Active"); | |
} | |
this.$groups[n].filter("img").animate({opacity: 1}, function(){ | |
self.animating = false; | |
}); | |
// animate to show | |
this.$groups[n].addClass("ppStyle_Active"); | |
} | |
}; | |
$.plugin('HomepageSplashModule', HomepageSplashModule); | |
})(); | |
$(function(){ | |
$(".ppMod_HomeSplash").HomepageSplashModule(); | |
}); | |
(function (){ | |
var ContactUsModule = { | |
options: { | |
verbage: { | |
} | |
}, | |
init: function(options, elem) { | |
this._setupEventHandlers(); | |
this._setupFormHandling(); | |
this.$loading = $('<span class="ppStyle_Image_Loading">Loading</span>'); | |
this.$success = $('<span class="ppStyle_IconText_Success">You\'re note was sent successfully! We\'ll be in touch!</span>'); | |
}, | |
_setupEventHandlers : function(){ | |
var self = this; | |
}, | |
_setupFormHandling: function() { | |
var self = this; | |
$(".ppForm_ContactUs", this.$elem).validate({ | |
errorClass: 'ppStyle_Error', | |
rules: { | |
email : { | |
required: true, | |
email: true | |
}, | |
name: "required" | |
}, | |
submitHandler: function(form){ | |
$(".ppStyle_Image_SendButton", self.$elem).hide().parent().append(self.$loading); | |
$("input, textarea").attr("disabled", "disabled"); | |
$(form).ajaxSubmit({ | |
success: function(response){ | |
self.$loading.remove(); | |
if (response.success == true) { | |
$(".ppStyle_Image_SendButton", self.$elem).parent().append(self.$success); | |
} else { | |
alert("Something went wrong. Please try again later or call instead."); | |
} | |
}, | |
error: function() { | |
self.$loading.remove(); | |
alert("Something went wrong. Please try again later or call instead."); | |
} | |
}); | |
} | |
}); | |
}, | |
_eventHandlers : function(){ | |
var self = this; | |
if(this._storedEventHandlers !== null) { | |
return this._storedEventHandlers; | |
} else { | |
return this._storedEventHandlers = { | |
}; | |
} | |
} | |
}; | |
$.plugin('ContactUsModule', ContactUsModule); | |
})(); | |
$(function(){ | |
$(".ppMod_ContactUs").ContactUsModule(); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment