Alles in einem

Enumerator

Mitglied Kamel
Abend!

Ich wollte nur mal eben ein kurzes Skript posten und Euch nach Eurer Meinung fragen. Im wesentlichen habe ich einfach nur nützliche Funktionen zusammengestellt, die diverse, immer widerkehrende Aufgaben browserunabhängig und unkompliziert lösen sollen...
Code:
var Tool = new function()
{
    this.Bless = function(ref) { return ((typeof(ref.tagName) == 'string') || (document.getElementById && (ref = document.getElementById(ref))) || (document.all && (ref = document.all[ref])))? ref: null; }
    this.P4css = function(ref) { return ((typeof(ref.float)   == 'string') || ((ref = this.Bless(ref)) && (ref = ref.style)))? ref: null; }

    this.SnapHeight = function(ref) { return (ref = this.Bless(ref))? (typeof(ref.offsetHeight) != 'undefined')? ref.offsetHeight: (typeof(ref.height) != 'undefined')? ref.height: null: null; }
    this.SnapWidth  = function(ref) { return (ref = this.Bless(ref))? (typeof(ref.offsetWidth)  != 'undefined')? ref.offsetWidth:  (typeof(ref.width)  != 'undefined')? ref.width:  null: null; }

    this.SnapLeft = function(ref) { return (ref = this.Bless(ref))? SnapX(ref): null; }
    this.SnapTop  = function(ref) { return (ref = this.Bless(ref))? SnapY(ref): null; }

    this.SnapContainer = function(ref) { return (ref = this.Bless(ref))? SnapC(ref): null; }

    this.SnapAbsLeft = function(ref) { if(!(ref = this.Bless(ref))) return null; var value = 0; do value += SnapX(ref); while(ref = SnapC(ref)); return value; }
    this.SnapAbsTop  = function(ref) { if(!(ref = this.Bless(ref))) return null; var value = 0; do value += SnapY(ref); while(ref = SnapC(ref)); return value; }

    this.SnapAvaHeight = function(ref) { return window.innerHeight? window.innerHeight: (document.body && document.body.clientHeight)? document.body.clientHeight: null; }
    this.SnapAvaWidth  = function(ref) { return window.innerWidth?  window.innerWidth:  (document.body && document.body.clientWidth)?  document.body.clientWidth:  null; }

    this.SnapName = function(ref) { return (ref = this.Bless(ref))? (typeof(ref.name) == 'string')? ref.name: (ref.getAttribute)? ref.getAttribute('name'): null: null; }
    this.SnapId   = function(ref) { return (ref = this.Bless(ref))? (typeof(ref.id)   == 'string')? ref.id:   (ref.getAttribute)? ref.getAttribute('id'):   null: null; }

    this.PlImg = function(src) { this.Registry.Images[(this.Registry.Images.push(new Image()) -1)].src = src.toString(); }

    function SnapC(ref) { return (typeof(ref.offsetParent) != 'undefined')? ref.offsetParent: null; }
    function SnapX(ref) { return (typeof(ref.offsetLeft)   != 'undefined')? ref.offsetLeft:   null; }
    function SnapY(ref) { return (typeof(ref.offsetTop)    != 'undefined')? ref.offsetTop:    null; }

    this.Registry = new function()
    {
        this.Images = new Array();
        this.Strings = new Array();
    }
}
Was fällt Euch dazu ein? Was ist überflüssig, was sollte man ändern oder ergänzen?

Gruß
Enum
 
Erläutere doch mal, wie und wozu du diese Funktionen einsetzt
Eigentlich dachte ich, das wäre offensichtlich... :rolleyes:|;-) ... ausserdem hatte ich das ja bereits grob beschrieben.

Man kann ganz einfach ein eine vernünftiges Objekt/ eine 'Referenz' gelangen, unabhängig von der Art und Weise, wie Objekte im HTML-Code identifiziert wurden (id||name-Attribut). Ausserdem nützlich, wenn man in einer Funktion die Argumenttypen flexibel halten möchte.
Code:
[null|object] = Tool.Bless ([id|name|object]);
[null|objcss] = Tool.P4css ([id|name|object|objcss]);
Vorgeführt wird das gleich hier, bei den Funktionen zum Ermitteln von Position und Größe eines Elementes...
Code:
[null|int] = Tool.SnapLeft   ([id|name|object]);
[null|int] = Tool.SnapTop    ([id|name|object]);
[null|int] = Tool.SnapWidth  ([id|name|object]);
[null|int] = Tool.SnapHeight ([id|name|object]);
Wenn verschachtelte Elemente mit der CSS-Eigenschaft 'position: absolute' versehen wurden möchte man hin und wieder wissen, auf welches Element sich die Angaben zur Position beziehen:
Code:
[null|object] = Tool.SnapContainer ([id|name|object]);
Zum Beispiel dann, wenn man die Angaben relativ zum Browserfenster braucht...
Code:
[null|int] = Tool.SnapAbsLeft ([id|name|object]);
[null|int] = Tool.SnapAbsTop  ([id|name|object]);
Auch die zur Verfügung stehenden Maße für das Dokument sind nicht uninteressant.
Code:
[null|int] = Tool.SnapAvaHeight ();
[null|int] = Tool.SnapAvaWidth  ();
Manchmal kommt's ganz doof - man hat/erwartet ein Objekt und braucht dringend auch den Namen/die ID...
Code:
[null|string] = Tool.SnapName ([id|name|object]);
[null|string] = Tool.SnapId   ([id|name|object]);
PlImg steht für 'Preload Image' und ist wohl selbsterklärend. Dann folgen noch ein paar Interna und schließlich mündet das Ganze in einem Objekt, das sich großkotzig Registry schimpft, aber hin und wieder ganz sinnvoll ist...

Soo, zurück zur eigentlichen Frage: Anmerkungen? :confused:|
:)

GREETZ
ENUM
 
Eigentlich dachte ich, das wäre offensichtlich... | ... ausserdem hatte ich das ja bereits grob beschrieben.

Nur weiss die Forensuche nicht, was du denkst...ein paar sinnvolle Schlüsselwörter sind da hilfreicher, wenn du nicht willst, dass das Thema in 2 Tagen im Nirvana verschwindet ;)
 

Neue Beiträge

Zurück