I've been trying to learn about the greasemonkey craze, and a few tools
to enable greasemonkey compatibility in IE. One use for this may be to
add calendar controls to SQL Reporting Services for 2000 installations.
I know that the 2005 version has calendars, but we can't all migrate
just because the new version is out. Here is some sample code that
injects a calendar control into a page after the page loads. It relies
on the brilliant pure-JavaScript calendar code PopCalendarXP, available
here: http://www.calendarxp.net.
First, before I describe how to do it. Can anyone tell me where a
PUBLIC installation of SQL Reporting Services is so that I can try it?
I have never seen an example site running it. I have only used it on an
intranet, and I cannot access it right now.
Here is the HTML. The
"txtStartDate" element will have a calendar button injected next to it
after the page loads, provided that the sqlcal.user.js file is
installed with greasemonkey for FireFox or Turnabout
http://www.reifysoft.com/ for IE.
<HTML>
<HEAD><TITLE>Inject-A-Cal</TITLE>
</HEAD>
<BODY>
<FORM name="demoform">
Date Field: <input name="dc" value="" size="11" id="txtStartDate">
</FORM>
<a href="sqlcal.user.js">sqlcal.user.js</a>
</BODY>
</HTML>
Here is the sqlcal.user.js file:
// Released under the GPL license
// http://www.gnu.org/copyleft/gpl.html
//
// --------------------------------------------------------------------
//
// This is a Greasemonkey user script.
//
// To install, you need Greasemonkey: http://greasemonkey.mozdev.org/
// Then restart Firefox and revisit this script.
// Under Tools, there will be a new menu item to "Install User Script".
// Accept the default configuration and install.
//
// To uninstall, go to Tools/Manage User Scripts,
// select "Add Calendar to SQL Reporting Services", and click Uninstall.
//
// If you want to use this in IE, then try Turnabout:
// http://www.reifysoft.com/
//
// --------------------------------------------------------------------
//
// ==UserScript==
// @name Add Calendar to SQL Reporting Services
// @namespace http://apps.ultravioletconsulting.com/
// @description Adds Calendar pop controls to SQL Reporting Services
// @include *InjectACalDemo.html*
// ==/UserScript==
(
function()
{
var txtStartDate, newElement;
txtStartDate = document.getElementById('txtStartDate');
if (txtStartDate)
{
newElement =
document.createElement('span');
newElement.innerHTML = '<a href="BLOCKED SCRIPTvoid(0)"
onclick="if(self.gfPop)gfPop.fPopCalendar(txtStartDate);return false;"
HIDEFOCUS><img class="PopcalTrigger" align="absmiddle"
src="HelloWorld/calbtn.gif" width="34" height="22" border="0"
alt=""></a><iframe width=174 height=189
name="gToday:normal:agenda.js" id="gToday:normal:agenda.js"
src="HelloWorld/ipopeng.htm" scrolling="no" frameborder="0"
style="visibility:visible; z-index:999; position:absolute; top:-500px;
left:-500px;"></iframe>';
txtStartDate.parentNode.insertBefore(newElement,
txtStartDate.nextSibling);
}
}
) () // exec the anonymous func
Description of Code
The HTML needs no introduction. The JavaScript is a "user
script". This is becoming a popular way to post-process HTML on the
client side via the popular greasemonkey plugin for FireFox, which
features the nifty GM_xmlHttpRequest that gets around the same-origin
policy for requests, and now Turnabout for Internet Explorer. The above
script works fine for both FireFox and IE.
You must right click on the link to "sqlcal.user.js" and install it,
using greasemonkey or Turnabout. Then, the metadata will be used to
tell the browser plugin when to apply the injection. In this case, only
pages named "InjectACalDemo.html".
You must first download the PopCalendarXP lite from the other site, and then modify the "HelloWorld" sample.
I will try it for real when I get back to work to see if it works. But,
if this was coherent enough to understand, someone else try it and let
me know how it goes?