Posted By

elightbo on 09/29/09


Tagged

textmate jquery pseudo


Versions (?)

jquery pseudo selectors


 / Published in: Other
 

  1. (function($){
  2.  
  3. var patterns = {
  4. text: /^['"]?(.+?)["']?$/,
  5. url: /^url(["']?(.+?)['"]?)$/
  6. };
  7.  
  8. function clean(content) {
  9. if(content && content.length) {
  10. var text = content.match(patterns.text)[1],
  11. url = text.match(patterns.url);
  12. return url ? '<img src="' + url[1] + '" />': text;
  13. }
  14. }
  15.  
  16. function inject(prop, elem, content) {
  17. if(prop != 'after') prop = 'before';
  18. if(content = clean(elem.currentStyle[prop])) {
  19. $(elem)[prop == 'before' ? 'prepend' : 'append'](
  20. $(document.createElement('span')).addClass(prop).html(content)
  21. );
  22. }
  23. }
  24.  
  25. $.pseudo = function(elem) {
  26. inject('before', elem);
  27. inject('after', elem);
  28. elem.runtimeStyle.behavior = null;
  29. };
  30.  
  31. if(document.createStyleSheet) {
  32. var o = document.createStyleSheet(null, 0);
  33. o.addRule('.dummy','display: static;');
  34. o.cssText = 'html, head, head *, body, *.before, *.after, *.before *, *.after * { behavior: none; } * { behavior: expression($.pseudo(this)); }';
  35. }
  36.  
  37. })(jQuery);

Report this snippet  

You need to login to post a comment.