Raindrop Elements: V1

Documentation:

JS:

/********** Raindrop Global Object (this contains all of the constructed objects) **********/ var Raindrop = {}; /********** Raindrop Carousel **********/ function RD_Carousel(elem, interval) { this.elem = elem; this.interval = interval; this.function = jQuery(elem).attr('data-function'); this.current_item = 1; this.max_items = 1; this.init = function(){ if (!this.elem) { console.log('Element selector does not exist within carousels.'); return; } if (!this.interval) { this.interval = 5000; } var target = jQuery(this.elem); // Setting classes for parent and children elements target.addClass('rd-carousel'); target.children().addClass('rd-carousel-item'); // Finding amount of items to carousel through this.max_items = target.children().length; // Preparing the first item target.children('.rd-carousel-item:nth-child(' + this.current_item + ')').addClass('rd-carousel-item-active'); if (this.function) { if (typeof window[this.function] == 'function') { window[this.function](this); } else { console.log('Undefined function invocation attempt within carousels.'); } } setInterval(this.carousel.bind(this), this.interval); }; this.carousel = function(dir){ var target = jQuery(this.elem); switch (dir) { case 'prev': this.current_item--; if (this.current_item < 1) { this.current_item = this.max_items; } break; case 'next': default: this.current_item++; if (this.current_item > this.max_items) { this.current_item = 1; } break; } target.children('.rd-carousel-item').removeClass('rd-carousel-item-active'); target.children('.rd-carousel-item:nth-child(' + this.current_item + ')').addClass('rd-carousel-item-active'); if (this.function) { if (typeof window[this.function] == 'function') { window[this.function](this); } else { console.log('Undefined function invocation attempt within carousels.'); } } }; this.init(); } /********** Raindrop Animation **********/ // Raindrop Animation: Object Constructor function RD_Animation(elem) { this.elem = jQuery(elem); this.function = jQuery(elem).attr('data-function'); this.hT = jQuery(elem).offset().top; this.hH = jQuery(elem).outerHeight(); } /********** Initialize Function **********/ jQuery(document).ready(function() { jQuery('[data-raindrop-element]').each(function(){ var type = jQuery(this).data('raindrop-element'); switch(type) { case 'carousel': if (!Raindrop.carousels) { Raindrop.carousels = []; } var interval = jQuery(this).data('interval'); Raindrop.carousels.push(new RD_Carousel(this, interval)); break; case 'animation': if (!Raindrop.animations) { Raindrop.animations = []; } Raindrop.animations.push(new RD_Animation(this)); break; case 'animation': if (!Raindrop.animations) { Raindrop.accordions = []; } Raindrop.accordions.push(new RD_Accordion(this)); break; default: break; } }); // Raindrop Animation: Scroll Check if (Raindrop.animations) { if (Raindrop.animations.length > 0) { jQuery(window).scroll(function() { var wH = jQuery(window).height(), wS = jQuery(this).scrollTop(); for (var i = 0; i < Raindrop.animations.length; i++) { if (wS > (Raindrop.animations[i].hT+Raindrop.animations[i].hH-wH) && (Raindrop.animations[i].hT > wS) && (wS+wH > Raindrop.animations[i].hT+Raindrop.animations[i].hH)){ Raindrop.animations[i].elem.addClass('rd-animation-active'); if (Raindrop.animations[i].function) { if (typeof window[Raindrop.animations[i].function] == 'function') { window[Raindrop.animations[i].function](); } else { console.log('Undefined function invocation attempt within animations.'); } } Raindrop.animations.splice(i, 1); } } }); } } }); /* Raindrop Accordion */ var raindrop_accordion = { resizing: null, current_width: jQuery(window).width(), resized_width: jQuery(window).width(), open_first_accordion: true, collapse_other_accordions: true, init: function() { jQuery('.rd-accordion').each(function(){ var accordion = jQuery(this); var h = accordion.children('.rd-accordion-inner').outerHeight(); var collapsed_h = accordion.find('.rd-accordion-title').outerHeight(); accordion.attr('data-expanded-height', h); accordion.attr('data-collapsed-height', collapsed_h); accordion.css('height', collapsed_h + 'px'); }); jQuery('.rd-accordion-title').click(function(){ var target = jQuery(this).parents('.rd-accordion'); raindrop_accordion.click(target); }); jQuery(document).ready(function() { raindrop_accordion.ready(); }); jQuery( window ).resize(function() { raindrop_accordion.resize(); }); }, ready: function() { jQuery('.rd-accordion-hidden').css('display', 'none'); jQuery('.rd-accordion-container').addClass('rd-accordion-loaded'); var open_first_accordion = jQuery('.rd-accordion-container').attr('data-first-expand'); if (open_first_accordion == 'false') { raindrop_accordion.open_first_accordion = false; } if (raindrop_accordion.open_first_accordion == true) { var target = jQuery('.rd-accordion-container').children('.rd-accordion:first-child'); raindrop_accordion.click(target); } }, resize: function() { if (!this.resizing && jQuery(window).width() != this.current_width) { jQuery('.rd-accordion-container').removeClass('rd-accordion-loaded'); this.resizing = setInterval(this.resize_check, 500); } }, click: function(target) { var accordion = target; var current_h = accordion.outerHeight(); var expanded_h = accordion.attr('data-expanded-height'); var collapsed_h = accordion.attr('data-collapsed-height'); if (raindrop_accordion.collapse_other_accordions) { accordion.parents('.rd-accordion-container').children('.rd-accordion').each(function(){ var collapsed_other_accordions_h = jQuery(this).attr('data-collapsed-height'); jQuery(this).removeClass('rd-accordion-expanded'); jQuery(this).css('height', collapsed_h + 'px'); }); } if (current_h == expanded_h) { accordion.css('height', collapsed_h + 'px'); accordion.removeClass('rd-accordion-expanded'); } else { accordion.css('height', expanded_h + 'px'); accordion.addClass('rd-accordion-expanded'); } }, resize_check: function() { this.current_width = jQuery(window).width(); setTimeout(function(){ this.resized_width = jQuery(window).width(); if (this.current_width == this.resized_width) { clearInterval(raindrop_accordion.resizing); raindrop_accordion.resizing = null; setTimeout(function() { raindrop_accordion.reset(); }, 600); } }, 250); }, reset: function() { jQuery('.rd-accordion').removeAttr("style"); jQuery('.rd-accordion').removeClass('rd-accordion-expanded'); jQuery('.rd-accordion').each(function(){ var accordion = jQuery(this); var h = accordion.children('.rd-accordion-inner').outerHeight(); var collapsed_h = accordion.find('.rd-accordion-title').outerHeight(); accordion.attr('data-expanded-height', h); accordion.attr('data-collapsed-height', collapsed_h); accordion.css('height', collapsed_h + 'px'); }); this.ready(); }, reveal: function() { jQuery('.rd-accordion-hidden').css('display', 'block'); jQuery('.rd-accordion-hidden').each(function(i){ var t = i * 300; var elem = jQuery(this); setTimeout(function(){ elem.removeClass('rd-accordion-hidden'); }, t); }); } } raindrop_accordion.init(); /* Raindrop Slider */ var rd_slider = { interval: 5000, current_slide: 1, max_slides: 1, init: function() { this.max_slides = jQuery("#main-slider-slides").children().length; jQuery('#main-slider-slides .main-slider-item:nth-child(' + this.current_slide + ')').addClass('main-slider-item-active'); this.current_slide++; setInterval(function(){ rd_slider.carousel(); }, this.interval); }, carousel: function() { if (this.current_slide > this.max_slides) { this.current_slide = 1; } jQuery('.main-slider-item').removeClass('main-slider-item-active'); jQuery('#main-slider-slides .main-slider-item:nth-child(' + this.current_slide + ')').addClass('main-slider-item-active'); this.current_slide++; }, } rd_slider.init(); function is_mobile(width) { if (width) { var i = width; } else { var i = 768; } if (jQuery(window).width() < i) { return true; } else { return false; } } function validateEmail(emailAddress) {
 /* NOTE: This regular expression is identical to the one used by Enterprise for e-mail address validation */
 var regExp = /^\s*[a-zA-Z\d][a-zA-Z\d\.!#$%&'*+\-\/=?^_`{|}~]*@([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}\s*$/;
 if (emailAddress.length <= 200 && regExp.test(emailAddress)) {
 return true;
 } else {
 alert("The email address you have entered is invalid. Please try again!");
 return false;
 }
 } function open_maps(address_query) { var link = false; if (device_type.iOS()) { link = 'http://maps.apple.com/?q=' + address_query; } else { link = 'https://www.google.com/maps/search/?api=1&query=' + address_query; } window.location.href = link; } /******* Mobile Gestures - hammer.js ********/ var gallery_home_elem = document.getElementById('gallery-home-carousel'); if (gallery_home_elem) { var gallery_home_elem_hammer = new Hammer(gallery_home_elem); gallery_home_elem_hammer.on('swipeleft', function(ev) { jQuery('#gallery-home-carousel').carousel('next'); }); gallery_home_elem_hammer.on('swiperight', function(ev) { jQuery('#gallery-home-carousel').carousel('prev'); }); } var device_type = { Android: function() { return navigator.userAgent.match(/Android/i); }, BlackBerry: function() { return navigator.userAgent.match(/BlackBerry/i); }, iOS: function() { return navigator.userAgent.match(/iPhone|iPad|iPod/i); }, Opera: function() { return navigator.userAgent.match(/Opera Mini/i); }, Windows: function() { return navigator.userAgent.match(/IEMobile/i); }, any: function() { return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows()); } };