kneath (owner)

Revisions

gist: 18175 Download_button fork
public
Public Clone URL: git://gist.github.com/18175.git
Embed All Files: show embed
Prototype-like extentions for MooTools 1.2.js #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
Element.implement({
  getDimensions: function() {
    return {width: this.getStyle('width', true), height: this.getStyle('height', true)};
  },
  visible: function() {
    return this.getStyle('display') != 'none';
  },
  toggle: function() {
    return this[this.visible() ? 'hide' : 'show']();
  },
  hide: function() {
    this.originalDisplay = this.style.display;
    this.style.display = 'none';
    return this;
  },
  show: function(display) {
    this.style.display = display || this.originalDisplay || 'block';
    return this;
  },
  cleanWhitespace: function() {
    $A(this.childNodes).each(function(node){
      if (node.nodeType == 3 && !/\S/.test(node.nodeValue)) node.parentNode.removeChild(node);
    });
  },
  find: function(what) {
    var el = this;
    while (el.nodeType != 1) el = el[what];
    return el;
  },
  replace: function(html) {
    if (this.outerHTML) {
      this.outerHTML = html.stripScripts();
    } else {
      var range = this.ownerDocument.createRange();
      range.selectNodeContents(this);
      this.parentNode.replaceChild(range.createContextualFragment(html.stripScripts()), this);
    }
    setTimeout(function() {html.evalScripts()}, 10);
  },
  empty: function() {
    return this.innerHTML.match(/^\s*$/);
  },
  getOffsetHeight: function(){ return this.getStyle('height'); },
  getOffsetWidth: function(){ return this.getStyle('width'); }
});