Posts

Showing posts from June, 2006

Create CSS Class (JavaScript)

This function ( createCSSClass ) creates a new class with the given style. However, it does not work in version of Opera prior to 9, due to lack of support for document.styleSheets . For example, if you want all text in a pre element bold, you would do createCSSClass("pre", "font-weight: bold") . Note, that if you already have the rule defined, it will replace it, unless it is not a stylesheet with media type 'screen' (or media not set) or it is not the first linked/embedded screen stylesheet. So for example, if you had the following: <link rel="stylesheet" href="print.css" media="print" /> <link rel="stylesheet" href="screen.css" /> <style type="text/css">pre { border: 1px solid #000}</style> When you do createCSSClass("pre", "font-weight: bold") , it will replace the rule in screen.css (or add it if it does not exist). Any styles defined in print.css...

Date Manipulation - GoToWeek and WeekOfYear (C#)

GoToWeek goes to the specific week in a year (e.g. GoToWeek(2006, 10) would go return the start day of week 10 in 2006 - 27th February). WeekOfYear returns the given dates Week Number (e.g. GoToWeek(DateTime.Now) would return 27). Uses the current threads culture, so will work with whatever culture you have set the current thread to (e.g. System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-GB"); ). private DateTime GoToWeek(int year, int week) { // use the current culture System.Globalization.CultureInfo ci = System.Threading.Thread.CurrentThread.CurrentCulture; // get first day of week from culture DayOfWeek fdow = ci.DateTimeFormat.FirstDayOfWeek; // new empty Date (so starts 01/01/0001) DateTime d = new DateTime(); // year starts at 1, so take away 1 from desired year to prevent going to the next one d = d.AddYears(year - 1); // get day January 1st falls on int startDay = (int)d.DayOfWeek; // get the differe...

jQuery Sample: Collapsible List

jQuery Sample: Collapsible List is a sample of how to do a collapsible list using jQuery. Tags: Web Developer Blog , jQuery

jQuery Plugin: numeric (update)

I have updated jQuery Plugin: numeric with a few bug fixes.

StartOfWeek - get start of the week for supplied date (C#)

This function returns the date the week started from the supplied date. You can also supply which day is the start of the week through the overload. i.e. today is the 22nd June. StartOfWeek(DateTime.Now) would return 19th June. If the start day was Sunday, StartOfWeek(DateTime.Now, DayOfWeek.Sunday) would return 18th June. public static DateTime StartOfWeek(DateTime date) { return StartOfWeek(date, DayOfWeek.Monday); } public static DateTime StartOfWeek(DateTime date, DayOfWeek weekStart) { // get the difference in days between the start of the week and the supplied dates day of week int difference = (int)weekStart - (int)date.DayOfWeek; // if it is positive (i.e. in future), take away 7 if(difference > 0) { difference = difference - 7; } // return the new date return date.AddDays(difference); } Tags: Web Developer Blog , CSharp , DateTime

jQuery Plugin: numeric

jQuery Plugin: numeric is a plugin for jQuery that allows only valid numbers in a text box input. There are a few limitations that I have not found the solution for though (listed on the page).

jQIR - jQuery Image Replacement

A plugin built on jQuery that replaces text with images (for prettier headings for example). Demo and code: jQIR - jQuery Image Replacement

jQuery Plugin: outlineTextInputs

A plugin built on jQuery that adds an outline when a text field gains focus. Demo and code: jQuery Plugin: outlineTextInputs Tags: Web Developer Blog , jQuery

Dean Edwards - Levels of JavaScript Knowledge

You may have read Levels of CSS knowledge and Levels of HTML knowledge which rank users based on what they know about the technology in question. Higher ranks are not always better (unless they are one of the top two) - knowledge may be lacking in areas of importance (like standards, semantics and accessibility). Dean Edwards has done a version for JavaScript: Levels of JavaScript Knowledge . Filed under humour, so not to be taken too seriously. Tags: Web Developer Blog , JavaScript