DBJ Q

by dbjdbj

HTML

<script>
(function(){var cache=[];function cached_selections(cont){return cache[cont]||(cache[cont]={"_container_":cont})}function cached_result(ss,sel){return ss[sel]=ss[sel]||(ss[sel]=ss._container_.querySelectorAll(sel))}Q=function(selector,container){var list=[];if("string"!==typeof selector)return list;if("object"!==typeof(container||document))return list;list=cached_result(cached_selections(container||document),selector);return list.length>0?list:null};Q.FLUSH=function(container,selector){if(container)if(!selector){cache[container]=
null;delete cache[container]}else delete cache[container][selector];else cache=[]};Q.ID=function(id_string){var list=Q("#"+id_string,document);return list.length>0?list[0]:null};Q.CLASS=function(class_name){var list=Q("."+id_string,document);return list.length>0?list[0]:null};Q.NULL=function(selector,container){return Q(selector,container).length>0};Q.EACH=function(method,selector,container){if("function"!==typeof method)return;var list=Q(selector,container),j=0;if(list)for(;j<list.length;j++)method(list[j])};
var _q_label_="_q_label_"+ +new Date;Q.LABEL=function(label_,selector_,container_){try{if("object"===typeof label_)return label_.getAttribute(_q_label_);Q.EACH(function(E){E.setAttribute(_q_label_,label_)},selector_,container_)}catch(x){Q.LOG("Q.LABEL(),"+x)}};var logbuf_=[],loglock_=false,logtid_=setInterval(function(){if(logbuf_.length<1)return;var logcopy=logbuf_;if("undefined"!==typeof console)console.log(logcopy.join("\n"));else alert(logcopy.join("\n"));logbuf_=[]},1E3);var q_log_msg_=null;
Q.LOG=function(msg_){q_log_msg_=q_log_msg_||(q_log_msg_=Q.msg("log"));var tid=setTimeout(function(){clearTimeout(tid);delete tid;logbuf_.unshift(q_log_msg_.format((new Date).toLocaleTimeString())+msg_)},0)}})();(function(){var en={log:"Q log [{0}] ",q_msg_err:"Q.msg ({0}), failed."};Q.msg=function(mid_){try{var a=Array.prototype.slice.call(arguments);a.shift();return...

CSS

* { font:12px/1.2 sans-serif;}

div {  max-width:650px; height:auto;padding:2%; margin:2%; float:left;}
.zadatak {
  background:orange; 
}
.resenje {
  background:silver;
}
button {
  margin:15px; background:tomato;
}

JavaScript

try {
// for every 'th' inside every table which has a border=2
// select it, if it contains letters A, B or C
// if it does put the result in an list to be returned
// hit CTRL+ENTER to evaluate
var a = Q.T.M(/A|BA|C/,"table[border='2'] th");

var s = ["For 'Quick Text Match' query",
"Q.T.M(/A|B|C/,\"table[border='2'] th\")",
"Result is, array of { node, [match] } objects:"] ;
for ( var j = 0; j < a.length; j++ )
s.push(
   "{ node: {0} , match: {1} }".format( a[j].node.nodeName,a[j].match)
) ;

s.push("JSON.stringify() format: "); s.push(JSON.stringify(a));
   
   $(".resenje").html(s.join("<br/>"));

} catch (x) {
   alert("ERROR:\n\n"+x)
}