Setting Focus to Control in an IFRAME using JQuery

Had a gnarly problem this afternoon, while trying to set focus to a control in an IFRAME.

Using JQuery, I had created the IFRAME with the JQuery plugin ThickBox. ThickBox provides functionality that can simulate a modal dialog using an IFRAME, loading a page from a URL into the IFRAME (check out the demo here - scroll down to "Inline Content"). The page loaded inside the IFRAME contained code to set the focus which was actually being called, but after the page loaded something else was stealing the focus.

I began to look at the javascript code in the parent that created the IFRAME.

I discovered to set the focus to a control in an IFRAME that has already been loaded, you need to set the focus to the IFRAME first (thanks Alex King). I also benefited from "How to access IFRAME in JQuery" over at ProCoding (thanks Taras Ilnytskyy).

Here's the code to set focus to a control in an IFRAME using JQuery (called from the parent window, after the IFRAME has been loaded and shown):
	
//get the IFRAME element - note no hashes in the name, we're using browser functionality
var iframeRef = document.getElementById("IFRAMEID");
//focus the IFRAME element
$(iframeRef).focus();
//use JQuery to find the control in the IFRAME and set focus
$(iframeRef).contents().find("#CONTROLID").focus();
I hope this helps someone!

UPDATE: Fixed formatting.

Tags: , , ,

Firefox vs Flock

I've blogged previously about how I use the Flock web browser, but recently decided to try my luck at the latest release of Firefox.

Flock had several features that enticed me to adopt it in late 2007: social media sidebar integrated with Facebook, blog post editor, in-built image uploader which connected to Flickr and Picasa, media bar, and one-click access to services I constantly used (like Delicious).

My biggest gripe with Flock was that the user interface was not customisable enough. Also, the browser had more features than I'd ever need.

Buying a widescreen monitor with very limited vertical space was the straw that finally made me switch from Flock to Firefox, permanently. Here's a comparison between the two (the red highlights represent the menu & toolbar space used):

I use a couple of Firefox add-ons to reduce the vertical space used (that's the other thing...Firefox has an unbelievable collection of add-ons):
Flock was good to me. Now, I just need the screen space, and don't need a lot of its features.

Tags: , ,

5 Firefox Add-Ons I Can't Live Without

Inspired by Martin over at gHacks, here's my list of Firefox browser add-ons that I consider essential:

  1. Mouse Gestures RedoxNavigate back and forward, close windows, and more with just the mouse. I turn on "mouse trails" to make it easier to see what I'm doing.
  2. Easy DragToGoDrag a link to open it in a new background or foreground tab.
  3. Adblock PlusBlocks ads, and is very configurable. Having a little "block" link I can click next to images and flash is extremely handy.
  4. FirebugIndispensable for web development, especially the ability to edit, "live", any part of a page. Also has some of its own add-ons available.
  5. SingletonFox, ChromaTabs PlusOK, that's two items at number 5, but I couldn't decide which one was more useful - making sure only a single instance of Firefox is open, or slight tab coloring depending on the site to make for easy identification of tabs.

These are fairly stock-standard add-ons, particularly numbers 1-3 which I've been using in some form or another since 2002 and MyIE. In addition, they're all very unintrusive - between the 6 add-ons, only 1 toolbar button is added (I like to keep my toolbars, menus and status bar lean).

Any browser add-ons that you couldn't live without?

Tags: , ,

Ever wanted to turn off Windows Beep?

The other day my PC started beeping at me. Every "Are you sure?" message box was accompanied by a "beep". I don't know how or why this started...I only wanted to make it go away.

First check, Control Panel -> Sounds. I confirmed that I had my sound scheme set to "No Sounds", but the beep stubbornly refused to budge.

Next, Google. Did you know there's a "Beep" driver? Neither did I! The HowToGeek has a nice article on disabling this driver on XP, only issue is you have to be admin.

I rolled up my sleeves, ran an elevated command prompt using MakeMeAdmin, then ran System Properties from the command prompt using "sysdm.cpl", and finally followed all the instructions in HowToGeek's article to stop the driver, disable the driver, and disable startup of the driver.

Now, I'm beep free - fan-beeping-tastic!

Tags: , ,

The Story Of WordPerfect: Almost Perfect

Jeff Atwood blogged about the free online book Almost Perfect earlier this week. Author Pete Peterson was part of WordPerfect for 12 years and opens a window into development process, marketing, competition, and highs and lows of the company, from a small starter to a big corporation.

I think the broader themes in this book are still applicable today - the enthusiastic team learning on its feet, finding creative ways to compete, dealing with customers and incorporating feedback, handling "feature creep" and release schedules, and the culture of an organisation (in this case, run by programmers). Pete doesn't come across as a particularly sympathetic guy, but tells an interesting tale and gives an insight into the IT culture of the mid 80's to the early 90's.

I was never a WordPerfect user but remember seeing it in shops and magazines; amazingly, WordPerfect was available on almost every operating system under the sun - DOS, AmigaOS, Windows, OS/2, Apple IIe, Apple IIGS, Apricot, Tandy, even Atari (with the enormous differences in architecture and capabilities, that almost equates to x number of different products, aside from all the different versions!)

I'm glad Jeff posted about Almost Perfect. It's well worth the read.

Tags: ,

OT: I’m 10% (or so) April Fool

OK, I’ll admit I got got by a couple of the April Fool’s pranks around on Wednesday. I was duped by Bill Harris at newly-subscribed Dubious Quality blog with his corker post on asthma and gravity. I was suckered by TheRuntime’s own Jay Kimble who had me worried when he blogged about closing this site. I only raised an eyebrow at the phoney SaveIE6 campaign...at least I think it’s phoney...

I feel like about 10% of an April Fool. I’d better pay more attention next year :-)

Tags: ,

Enhancing Visualisation of Common Elements Across Groups Using Color in Reporting Services 2005, Part 2

As I discussed last week in part 1 of this article, color can be used to highlight common elements across groups. As promised, here's the necessary code to achieve this effect in Reporting Services 2005 (or you can download the finished report here):

1. Create a new report, and add a query. I've used AdventureWorks and a simple query that returns employees and years of service:

--get employees by Department, with years of service from AdventureWorks
SELECT  TOP 50 D.[Name] AS [DepartmentName], 
        EMP.[EmployeeId], C.[FirstName] + ' ' + C.[LastName] AS [EmployeeName], 
        --just an example: really simple, bogus calculation for years of service 
        --from start date till now 
        DATEDIFF(year, EMP.[HireDate], GETDATE()) AS [YearsOfService] 
FROM    --Employees 
        HumanResources.[Employee] EMP WITH (NOLOCK) INNER JOIN 
            --Person details (name) 
            Person.[Contact] C WITH (NOLOCK) ON 
                EMP.[ContactID] = C.[ContactID] INNER JOIN 
            --current/last Department 
            HumanResources.[EmployeeDepartmentHistory] EDH WITH (NOLOCK) ON 
                EMP.[EmployeeId] = EDH.[EmployeeId] AND 
                EDH.[EndDate] IS NULL INNER JOIN 
            --Department details 
            HumanResources.[Department] D WITH (NOLOCK) ON 
                EDH.[DepartmentID] = D.[DepartmentID] 
ORDER BY D.[Name], EMP.[EmployeeId]

2. Create a table in the report. For my AdventureWorks sample, I've listed the employee's name and years of service by department groups.

3. Add the code for assigning a random color based on a passed value. This goes under "Properties", "Code". The code is fairly self-explanatory; it creates an empty dictionary called m_dic_KeyAndColors and each time GetBackgroundColor is called, checks if the passed item is already in the dictionary. If the passed item is in the dictionary, the color associated with it is returned. If not, new random color is assigned and added to the dictionary before being returned:

''' <summary>
''' Dictionary of passed string and matching colors, populated as it is used
''' </summary>
Private m_dic_KeyAndColors As New System.Collections.Generic.Dictionary(Of String, String)

''' <summary>
''' New random object, based on code at http://www.developerfusion.co.uk/show/3940/ 
''' </summary>
Private objRandom As New System.Random(CType(System.DateTime.Now.Ticks Mod System.Int32.MaxValue, Integer))

''' <summary>
''' Returns a set color based on the passed string.
''' </summary>
Public Function GetBackgroundColor(ByVal s As String) As String 

    Try

        ' does the dictionary have an entry with the passed string and matching color?
        If m_dic_KeyAndColors.ContainsKey(s) Then
            ' return the pre-stored color
            Return m_dic_KeyAndColors(s)
        Else
            ' get a new random color by calling "GetRandomBackgroundColor", add it and the 
            ' passed string to the dictionary, and return the color
            m_dic_KeyAndColors.Add(s, GetRandomBackgroundColor())
            Return m_dic_KeyAndColors(s)
        End If
    Catch ex As Exception
        ' return neutral color
        Return "#ececed"
    End Try

End Function

''' <summary>
''' Return a random web color where 2 of R, G or B are fixed by the passed
''' "Highest" and "Lowest" hues, and a random value between the two is generated
''' for the remaining. Which values get assigned to R, G and B is also randomised.
''' For .NET-centric explanation of colors, see Dave Lean's blog post at  
''' http://blogs.msdn.com/davidlean/archive/2009/02/17/sql-reporting-how-to-conditional-color-2-4-functions-for-tables-charts.aspx 
''' </summary>
''' <param name="Highest">Highest hue value (0-255), set to light color with low saturation by default</param>
''' <param name="Lowest">Lowest hue value (0-255), set to light color with low saturation by default</param>
''' <returns>Hex color string in he format "#RRGGBB"</returns>
''' <remarks>Adapted from http://www.perlmonks.org/?node_id=305209 </remarks>
Public Function GetRandomBackgroundColor(Optional ByVal Highest As Integer = 215, Optional ByVal Lowest As Integer = 153) As String

    ' sanity check: ensure "highest" and "lowest" are between 0-255 
    If Highest > 255 Then Highest = 255
    If Highest < 0 Then Highest = 0
    If Lowest > 255 Then Lowest = 255
    If Lowest < 0 Then Lowest = 0
    ' sanity check: is "highest" higher than "lowest"
    If Highest < Lowest Then
        Dim temp As Integer
        temp = Lowest
        Lowest = Highest
        Highest = temp
    End If

    ' get a random number in the middle of highest and lowest 
    Dim Middle As Integer = objRandom.[Next](Lowest, Highest + 1)

    ' create an array with the 3 values - Highest, Lowest and Middle 
    Dim a() As Integer = New Integer() {Highest, Lowest, Middle}

    ' randomise the order of the 3 values with Fisher-Yates shuffle 
    ' see also http://www.codinghorror.com/blog/archives/001015.html 
    For i As Integer = 2 To 0 Step -1
        Dim n As Integer = objRandom.[Next](i + 1)
        Dim temp As Integer = a(i)
        a(i) = a(n)
        a(n) = temp
    Next

    ' return a web color string using hex/"X2" formatting
    Return String.Format("#{0:X2}{1:X2}{2:X2}", a(0), a(1), a(2))

End Function

4. In the background color expression for the table cell to be colored, call "=Code.GetBackgroundColor([YourFieldValue])". In my example, the background color expression is "=Code.GetBackgroundColor(Fields!YearsOfService.Value)".

Here's the end result, downloadable from CodePlex:

Aside: Why Did I Randomly Generate the Colors?
Initially I had an array of pastel colors that I'd already selected. That was until I came across Dave Lean's series on generating random colors for reports which explains how to generate random colors and convert decimal to hex. Suitably inspired, I looked around and found a useful snippet to generate light random colors only at this PERL forum posting (which forms the basis for my GetRandomBackgroundColor function).

Optional Steps

Repeating text can be turned off so that the color "groups" the data together.

Limitations

  • Color should not be used as the sole indicator to make distinctions for important data, as there's a percentage of the population who have trouble telling colors apart (color blindness or color deficiency). You can find more information here.
  • This technique only makes sense on a small scale and I would not use it on large amounts of data. For large amounts of data, groups and sub-groups identify relationships in data better than color alone. Also, with many distinct items, you run the risk of having very similar colors that makes highlighting by color less effective.
  • This technique has only been tested in Visual Studio 2005.
  • As you can see from the finished result, this is not a heatmap. Each item is assigned a new totally random color.
  • Every time the report is run, different random colors will be generated.

Tags: , , ,

Enhancing Visualisation of Common Elements Across Groups Using Color in Reporting Services 2005, Part 1

Often a report must be able to be grouped by one or more categories, depending on the user's requirements.

Sometimes, across groups, it's helpful to highlight common elements. Imagine that the illustration below lists employees by department (the main grouping), with the last column being a common element to all employees:

It's difficult to identify common elements across the main group for the last column in figure 1, even though values like "AAAAA" and "ZZZZZ" are repeated. In fact, it's not possible to draw any conclusions about the last column (like how many employees share the common element "ZZZZZ") without physically scanning the entire text of the last column. It would be easier to visualise if the last column was in its own sub-group - although doing so would interrupt the flow of the main group, department.

Here's a revised illustration where the only change is color to the last column:

From the revised illustration in figure 2, it's easy to see how many "ZZZZZ" employees there are (highlighted in oceanic aqua), and even the fact that there's some in both sets, without really having to read the text.

Color is being used here as a "Pre-Attentive Variable": something that may convey information to a user, before they've paid attention to it. Next week, in part 2 of "Enhancing Visualisation of Common Elements Across Groups Using Color in Reporting Services 2005", I'll demonstrate the code to color Reporting Services table cells without hardcoding the variables, so my technique is re-useable between reports.

Tags: , , ,

Index Rebuild, Re-Organise or Just a Statistics Update? Use "IndexOptimise"!

Ola Hallengren recently posted an all-in-one solution for backups, integrity checks and index optimisation for SQL Server 2005 and 2008 here (http://blog.ola.hallengren.com/blog/_archives/2008/1/1/3440068.html).

I'm particularly interested in Ola's extremely flexible index optimisation stored procedure, IndexOptimise (you also need his CommandExecute and DatabaseSelect scripts to run it).

By default, IndexOptimise rebuilds indexes with fragmentation over 30%, re-organises indexes with fragmentation between 5% and 30%, and ignores indexes with fragmentation under 5% or smaller than a configurable size. The level of configurability offered improves on Maintenance Plans - see Ola's comparison here - because changes to indexes that don't need changing increase differential backup sizes (and I'm always confused about which to use...a rebuild, re-organise or just a statistics update?)

Ola has also gone to the trouble of documenting his solution and creating a 1-script install.

Well done Ola! (via Paul Randall)

Tags: , , ,

David Lean's Conditional Color in Reporting Services Series

Microsoft's David Lean has a great series of posts on "heatmapping" and other color-based conditional formatting in Reporting Services tables and charts (link is to part 4 of the series) (via Robert Bruckner).

 

Particularly useful are Dave's algorithms that work on colors and shades and conversion to hex values; part 2 of the series has how to change hue, while part 3 details how to change saturation. And, Dave packs as much useful content into his tips and asides as his main content!

Tags: , ,

«July»
SunMonTueWedThuFriSat
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678