Saturday, October 15, 2005

Mystical Programming

Touching on the Truth. Developer as medium (!?). I've always felt that this sense of beauty is what separates good developers from the rest. This also applies to artists, musicians, politicians, sports.......etc....etc. Reminds me of how, like painting a picture, when you're developing a program, you sometimes know you have the correct solution, but you don't really understand why until you've actually finished it, stand back and take a look. At that point, it won't be perfect, but the code will now be telling you what needs doing.

Thursday, October 13, 2005

Easy Confirm Delete in ASP.NET. No code required!

I got fed up of recreating the wheel all the time and of the messy bodge of attaching confirmation JavaScript as an attribute to Delete buttons during data binding. So...

I created this ickle JavaScript file (tested IE6 and Firefox) using non-intrusive, DHTML. As well as being simpler, you'll also get rid of all that old-style, heavy, spaghetti JavaScript that ASP.NET spits out all over your tidy HTML!

Instructions:

1. Paste the code below into a file called comdel.js

2. Add a link to it in your <head>

<script src="comdel.js" type=text/javascript></script>

3. Set CssClass="comdel" on any <asp:Button> or <asp:LinkButton> for which you require confirmation.

4. That's it! Never get bogged down in JavaScript attributes again.

function xPreventDefault(e) {
 if (e && e.preventDefault) {
  e.preventDefault();
 }
 else if (window.event) {
  window.event.returnValue=false;
 }
}


function xAddEventListener(el, evType, fn, useCapture) {
 if (el.addEventListener) {
  el.addEventListener(evType, fn, useCapture);
  return true;
 } else if (el.attachEvent) {
  var r = el.attachEvent('on'+evType,fn);
  return r;
 } else {
  el['on'+evType]=fn;
 }
}


function xEventTarget(e) {
 if (e && e.target) {
  return e.target
 }
 else if (window.event && window.event.srcElement) {
  return window.event.srcElement
 }
 else {
  return null
 }
}


function comdel(e) {
 var el=xEventTarget(e);
 if (!el) return;
 
 if (!confirm('Delete this record?')) {
  xPreventDefault(e);
  return false;
 }
}


function onLoad() {
 if (!document.getElementsByTagName) return;
 
 // Add event listener to all <a> where className includes "comdel"...
 var all_a = document.getElementsByTagName('a');
 for (var i=all_a.length-1;i>=0;i--) {
  if (all_a[i].className.search(/\b ?comdel\b/) != -1) xAddEventListener(all_a[i],'click',comdel,false);
 }
 
 // Add event listener to all <input> where type='button'...
 var all_input = document.getElementsByTagName('input');
 for (var i=all_input.length-1;i>=0;i--) {
  if (all_input[i].className.search(/\b ?comdel\b/) != -1) xAddEventListener(all_input[i],'click',comdel,false);
 }
}


xAddEventListener(window,'load',onLoad,false);

Monday, October 10, 2005

window.onload - Fix so works ASAP after DOM loaded

Solution here.

Sunday, October 09, 2005

Lisa Bassinder

Lisa Bassinder of Ecclesfield, Sheffield - where ARE you now?

Monday, August 01, 2005

Witchery


The Secret Garden
Originally uploaded by PapillonUK.

Spent last night in the "Guard Room" at The Witchery in Edinburgh. This has gotta be Scotland's (if not the UK's) most superb hotel. When the receptionist told us "to follow that woman" to our room - we weren't prepared for the trek across the street, though a secret passageway and up a flight of Harry Potteresque spiral stairs that ensued! Sumptuous is too shallow a word for this place. Forgot my digital camera - but we bought a cheapy disposable, will upload some photos later - if any turned out! Have stuck one in of "The Secret Garden" where we had the most gorgeous food ever for now. Thanks to Lesley who surprised me with this for my birthday. Helped soften the blow!

Tuesday, June 21, 2005

Cove Boutique

Fantastic fashion store in Kilmarnock, Scotland with an incredible website ;-)
Cove Boutique

Monday, January 17, 2005

Simple Character Entity Reference