Show Bootstrap Tooltip Over Truncated Text

I had a need to prevent text-wrapping in a cell. I wanted the text to appear truncated to keep the row height consistent. The following worked well to crop the text and show an indicator of hidden text:
I referenced the classes like so:
Next, I wanted the user to be presented a tooltip if the text was truncated so they could see the full value. Here is my solution:
This snippet watches for mouse placement over the DIV. It then does some width comparisons to see if there is any hidden text. If so it creates a tooltip using Twitter Bootstrap and displays it. Simple as that.

BTW, you are not limited to simple tables. This will also work with jQuery Datatables. See my post on Datatable Tweaks.

See a DEMO.

Read More

Ajax Script Loading that Enforces Order of Execution

One awesome feature of jQuery is the ability to load external scripts on demand. The $.getScript method loads the script behind the scenes via ajax. In fact the function is simply an alias to call to jQuery’s $.ajax function. By default that alias does not look for a cached items. In my particular need I wanted to observe a cache and guarantee order of execution. I resorted to using the $.ajax function directly since it offers more options. I did not want a script to load before it’s dependency nor did I want to bog down my page by doing synchronous requests. In no time at all I built my own mechanism to handle script requests.

My code basically loads one script at a time and waits until it is completely loaded before iterating to the next file. Once they are all loaded it will call the loadComplete function which can take advantage of those scripts. This method will load scripts as memory and resources are available, then perform the final action when complete. The user could be presented a loading gif or progress bar in the meantime.

Below I am showing an example using CDN scripts:

Read More

AJAX and Bootstrap Tabbing in MVC

In this tutorial you will see the Twitter Bootstrap tabstrip in action. I will be using MVC, Razor and jQuery to accomplish this. If you visit the tabstrip documentation you will see an example that uses static tab content. I have expanded upon that code snippet, converting it to dynamic content using AJAX. I’m also utilizing a fading transition effect as the content loads. The tabstrip will interact with two partial views named: _SearchTab.cshtml and _SubmissionTab.cshtml. Notice that I am naming the tab ids the same as the partial views. Doing that reduces translation in the script when relaying the AJAX calls.

Markup:

The @Html.Partial will request the page on the active tab on page load. Place this call wherever the active class is being set.

Script:

The $.ajax() request retrieves the partial view. The cache parameter is necessary to ensure a fresh rebuild on each click. As for what path is requested you will notice a @ViewContext.RouteData.Values["controller"] call. It simply retrieves the controller of the current view, assuming the partial views are located in the same folder in the tree.

Controller:

The above methods are needed to relay the $.ajax() request to the proper partial view.

Now each time you click on a tab it will load dynamic content from a partial view. Keeping content separate can keep code cleaner and more organized. Download an example implementing this technique.

Read More

AutoHotKey – Start with Windows

AutoHotkey is a free, open-source scripting platform for Windows. You can use it to automate repetitive, tedious tasks or to turn just about any action into a keyboard shortcut. Once a script has been written and compiled there may be a need to have it automatically start with Windows. There are two ways to do this: startup folders or the registry. Both techniques are explained below:

Use a Shortcut

This will create a shortcut in the common startup folder to launch an application:
To create it in the user’s startup folder replace A_StartupCommon with A_Startup.

Start in the Registry

This will use the registry to launch the program. Below, a check is being done as to whether the script is compiled or not. It will still work either way but this way will only touch the registry when out of test mode. WindowsStart is a just a variable containing 1 or 0, based off the user’s settings.

Read More