Otaqui.Com

Pete Otaqui’s blog about web development and everything else

Archive for the ‘Professional’ Category

Getting a reference to an unselected radiobutton (using jQuery)

leave a comment

The “change” event on a radiobutton input only fires when it becomes selected. If you want to trigger some behaviour on an unselected radiobutton, then you have to bind to the change event of the radiogroup, which you can do like so:

<ul>
  <li>
    <input id="r1" name="something" type="radio" value="basic" />
    <label for="r1">Basic</label>
  </li>
  <li>
    <input id="r2" name="something" type="radio" value="standard" />
    <label for="r2">Standard</label>
  </li>
  <li>
    <input id="r3" name="something" type="radio" value="advanced" />
    <label for="r3">Advanced</label>
  </li>
</ul>

<script>
$("input[name='inputName']").change(function(ev) {

});
</script>

Written by pete

August 2nd, 2011 at 7:59 pm

Posted in Professional

Tagged with

RTL Input text with large text-indent value “magically scrolls” in Opera

leave a comment

This is a pretty weird browser bug.

Opera RTL Scrolly Text Indent Bug.

If your content is RTL and you are using the large text-indent CSS property on an input tag (so that you can use a background image, while keeping the text invisible to most users but still available to screen readers) you get a couple of odd behaviours in Opera:

  1. The text is not indented. Well ok, that’s at least a “normal” kind of bug.
  2. If you right-click on the button, and leave the menu open for a few seconds, the text magically starts scrolling out of the way.

I’ve submitted a bug report to Opera. I’d be interested if anyone else is seeing the same behaviour, or any related RTL weirdness.

Written by pete

January 26th, 2011 at 12:32 am

Posted in Professional

Tagged with

Javascript EventEmitter Redux, now on github

leave a comment

I’ve added some more features to the EventEmitter mixin (like actually working listener removal) and posted it to github:

EventEmitter on github

It’s fairly simple to use … something like this:

var MyKlass = function() {};
EventEmitter.augment(MyKlass.prototype);

/**
 * Show me
 *
 * @fires shown
 */
MyKlass.prototype.showMe = function() {
  this.trigger('shown', {'visible':true});
}

var myInstance = new MyKlass();
myInstance.on('shown', function(e) {
  console.log(e.visible);
}
myInstance.showMe();

Written by pete

January 11th, 2011 at 10:37 pm

Posted in Professional

Tagged with

Adding Vertical Split support to GNU Screen in Mac OS X Snow Leopard

leave a comment

Evan Meagher supplies a great patch to the source of GNU Screen which adds vertical split support on OS X.

This is really useful, since so many displays are widescreen these days, and it also means you can create a reasonable dashboard with screen. The patch has worked without a hitch for me so far.

Thanks Evan!

Written by pete

January 6th, 2011 at 5:27 pm

Posted in Professional

Tagged with

Javascript EventEmitter Mixin

leave a comment

/**
 * EventEmitter Mixin
 *
 * Designed to be used in conjunction with a mixin "augment" function,
 * such as http://chamnapchhorn.blogspot.com/2009/05/javascript-mixins.html
 *
 * @usage augment(MyClass, EventEmitter);
 * my_inst = new MyClass();
 * my_inst.on('someEvent', function(e){ console.dir(e); });
 * my_inst.trigger('someEvent', {eventProp:'value'});
 */
var EventEmitter = function() {};
EventEmitter.prototype.on = function(name, callback, context) {
  if ( !context ) context = this;
  if ( !this._listeners ) this._listeners = {};
  if ( !this._listeners[name] ) this._listeners[name] = [];
  var f = function(e) { callback.apply(context, [e]); };
  this._listeners[name].push(f);
};
EventEmitter.prototype.trigger = function(name, event) {
  if ( !this._listeners ) this._listeners = {};
  if ( !this._listeners[name] ) return;
  var i = this._listeners[name].length;
  while ( i-- ) this._listeners[name][i](event);
};
EventEmitter.prototype.removeListener = function(name, callback) {
  if ( !this._listeners ) this._listeners = {};
  if ( !this._listeners[name] ) return;
  var i = this._listeners[name].length;
  while ( i-- ) {
    if ( this._listeners[name][i] === callback ) {
      this._listeners[name].splice(i, 1);
    }
  }
};

Written by pete

November 16th, 2010 at 5:18 am

Posted in Professional