Created
May 20, 2011 13:08
-
-
Save codersatx/982851 to your computer and use it in GitHub Desktop.
Arbritrary jQuery code which handles some ui items.
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
jQuery(document).ready(function(){ | |
//----------------------------------------------------------------------------- | |
//Temporary code to set the classes on the body tag based on the current segments. | |
//This will be used to style specific pages or sections or to qualify an already defined general class on that page. | |
//Get the segments in the url after the host name | |
var pathArray = window.location.pathname.split( '/' ); | |
//Get each segment from our array | |
var segment_1 = pathArray[1] ? pathArray[1] : ''; | |
var segment_2 = pathArray[2] ? pathArray[2] : ''; | |
var segment_3 = pathArray[3] ? pathArray[3] : ''; | |
var segment_4 = pathArray[4] ? pathArray[4] : ''; | |
var segment_5 = pathArray[5] ? pathArray[5] : ''; | |
//Replace the extension if it has one. | |
var seg_1 = clean_string(segment_1); | |
var seg_2 = clean_string(segment_2); | |
var seg_3 = clean_string(segment_3); | |
var seg_4 = clean_string(segment_4); | |
var seg_5 = clean_string(segment_5); | |
//Add the segment name to the body tag | |
jQuery('body').addClass(seg_1); | |
jQuery('body').addClass(seg_2); | |
jQuery('body').addClass(seg_3); | |
jQuery('body').addClass(seg_4); | |
jQuery('body').addClass(seg_5); | |
//Removes unwanted charagres from our string to be used in the class. | |
function clean_string(string) | |
{ | |
//An array of items to replace in our string. Add new items as needed. | |
var garbage = ['.aspx','---','--','-']; | |
for(var i in garbage) | |
{ | |
string = string.replace(garbage[i], ''); | |
} | |
return string; | |
} | |
//----------------------------------------------------------------------------- | |
// Set the default text when the page is loaded. | |
jQuery('.SearchTextBox').val('Search'); | |
//Used to set the css class on the textbox so the text the user enters | |
//does not look like the default text (gray and italic) | |
function set_search_class() | |
{ | |
var search_val = jQuery('.SearchTextBox').val(); | |
if (search_val == 'Search') | |
{ | |
jQuery('.SearchTextBox').addClass('SearchTextBoxDefault'); | |
} | |
else | |
{ | |
jQuery('.SearchTextBox').removeClass('SearchTextBoxDefault'); | |
} | |
} | |
//Call the set class function on page load | |
set_search_class(); | |
//Called when the users mouse enters the text box | |
jQuery('.SearchTextBox').focus(function(){ | |
if(jQuery(this).val() == 'Search') | |
{ | |
jQuery(this).val(''); | |
} | |
set_search_class(); | |
}); | |
//Called when the users mouse leaves the text box | |
jQuery('.SearchTextBox').blur(function(){ | |
if(jQuery(this).val() == '') | |
{ | |
jQuery(this).val('Search'); | |
} | |
set_search_class(); | |
}); | |
//----------------------------------------------------------------------------- | |
//Since the facebook images can come in different sizes and dimensions let's get | |
//the url of the image, hide image and use the url as the background image of the | |
//wrapper div. This way we can center the image so at least we can have some | |
//control over how it displays. | |
jQuery('.facebook-feed-picture').each(function(){ | |
var img = jQuery(this).attr('src'); | |
jQuery(this).hide(); | |
jQuery(this).parent().css('background-image', 'url('+ img +')'); | |
jQuery(this).parent().css('background-position', 'top, center'); | |
}); | |
//If the p.class element is empty let's hide it so it does not add extra space at the bottom of the news items. | |
jQuery('.NewsPreviewSummary p.deck').each(function(){ | |
if(jQuery(this).html() == ' ' || jQuery(this).html() == '') | |
{ | |
jQuery(this).hide(); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment