inspect_format + meta

by ihope

HTML

<script src="http://sprintf.googlecode.com/files/sprintf-0.7-beta1.js"></script>
<p id="fun" class="cls2 cls3 cls4"></p>

JavaScript

var s = "";
var F_ = {
    tag: "tagname-def",
    punct: "punc-def",
    condition: "condition-def",
    string: "string-def",
    attribute: "attribute-def",
    formatPatt: "<span class=\"xpath FormatType \">value</span>"
}
var DEFAULT_FORMAT;
/*
    @param o  input format Array
    @param f  input format rule 
*/

function $F(lookup) {
/*if (!(f || DEFAULT_FORMAT)) {
        return
    }
    if (f) {
        DEFAULT_FORMAT = f;
    }*/
    var ret = DEFAULT_FORMAT.formatPatt;
    var cb = function(match) {
        if (lookup[match]) return lookup[match];
        else return match;
    }
    for (i in lookup) {
        ret = ret.replace(new RegExp("("+i+")",/i/), cb);

    }

    return ret;
}
//===================================
/*DEFAULT_FORMAT = F_;
alert($F(["jhjh", "jjj"], F_.attribute));*/
//===================================
DEFAULT_FORMAT = F_;

$$('#fun').each(function(v, i) {
    
    if (v.id) {
        alert($F({'FormatType': F_.attribute,'value': v.id}                ));
    }
});

for(i in Element) {s+=(i)+ "=<pre>" + Element + "</pre><br/>"}
document.write((s));