❯~/pixelastic

Rendering bug with generated content on form fields in Opera

If you try the following code in Opera 10.51, you'll have some weird rendering bug:

<style>
  .test:after {
    content:"This should be on red background";
    background:red;
  }
 </style>
 Text input: <input type="text" value="I'm unstyled" class="test" />

The generated content is added to the page, but the background color isn't rendered. Worse, the input lose all styling, it does not have a background color nor borders anymore.

The same effect also apply to every input(radio, checkbox and password).

On a select tag, the generated content correctly have it's background color, but still lose all styling.

On a textarea, the styling is gone too, and the background color is here. Well, sort of, it is actually cropped after a while and the end of the text is on transparent background.

I sent a bug report to Opera about that.

Opening a new tab using Ctrl+Click on Opera

One thing that bugs me everytime I use Opera are the weird keyboard shortcuts. You open link in a new tab by using the middle mouse button (classic) or Shift+click (less classic, we are accustomed to use the Ctrl+Click, Shift+Click being used to open in a new window).

Today it was bugging me one too many times, so I decided to use the power of AutoHotKey to help fix this.

Here is the little snippet I added to my default AutoHotKey script:

;        Open page in new tab in Opera using Ctrl + Click
#ifWinActive, ahk_class OpWindow
^LButton::Send +{LButton}
#IfWinActive

It basically catch every Shift+Click in Opera and return a Ctrl+Click instead, allowing me to finally open tabs the way I'm used to.

Knowing if an element is in the DOM using jQuery

If you ever need to know if the element you have a reference to is really in your page (or if it is an old reference to an element you've already replaced), you can use the $.contains(container, contained) method.

I was just working on an AJAX paginated list of elements and I kept references to my table in vars to avoid re-querying it each time. But this reference where still 'correct' (ie. not null) even after having replaced the element with a new one (using .replaceWith() and even .empty() and .remove())

I added a check to see if the element was really in the DOM before using it, and if not requerying it and re-saving it in var

missing data in jQuery Ajax event ajaxSuccess

jQuery provides a nifty set of Ajax events that one could define to fire methods whenever an ajax request starts, stop, failed or succeed. It is quite useful actually, to display visual indicator once and for all without having to define the various callback on each ajax call.

But it has one flaw. The ajaxSuccess callback only give access to the event, XMLHttpRequest object and the option object. There is no direct way to get the return data from the call.

Well, you can still access it from the XMLHttpRequest responseText attribute but it is then your job to parse it according to its type, duplicating some of the code already called in the jQuery core.

You can use the $.httpData to directly parse it, giving the XHR as first argument and the data type as the second one.

$('#ajaxIndicator').bind('ajaxSuccess', function(event, xhr, options) {
  var data = $.httpData(xhr, options.dataType);
}

CSS rule to target only Firefox

I just found (via [enure.net](http://enure.net/post/article/serve-css-to-only- firefox)) a CSS rule using proprietary Mozilla filter that would allow one to specifically target Mozilla.

I'm not a huge fan of CSS hacks like that, I usually restrain them to the bare minimum of IE conditional comments. But in some edge cases, it is sometimes useful, if you really don't have other options.

I'd like to find the equivalent rules (using proprietary rules, no parser bug) for Safari, Chrome and Opera

@-moz-document url-prefix() {
  p { color: red; }
}