- From: Michael Smith via cvs-syncmail <cvsmail@w3.org>
- Date: Wed, 14 Dec 2011 07:32:54 +0000
- To: public-dap-commits@w3.org
Update of /sources/public/2009/dap/ReSpec.js/ReSpec.js/js In directory hutz:/tmp/cvs-serv23747/ReSpec.js/js Added Files: respec.js sh_main.min.js shortcut.js simple-node.js Log Message: new --- NEW FILE: respec.js --- // ------------------------------------------------------------------------------------------ // // ReSpec.js -- a specification-writing tool // Robin Berjon, http://berjon.com/ // ----------------------------------------------------------------------------------------- // // Documentation: http://dev.w3.org/2009/dap/ReSpec.js/documentation.html // License: http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231 // ------------------------------------------------------------------------------------------ // // SUPPORT // The official support channel for ReSpec is spec-prod@w3.org. // The archives are available at http://lists.w3.org/Archives/Public/spec-prod/ // You can subscribe by sending email to spec-prod-request@w3.org with "subscribe" as the // subject line. // Please use that instead of emailing me (Robin) directly as the chances are that questions // or enhancement ideas will be shared by others. Thanks! // XXX TODO // - move to the top of dev. hierarchy [...2448 lines suppressed...] return str.split(/\s+/).join(" "); }, _id: function (id) { return id.replace(/[^a-zA-Z_-]/g, ""); } }; // hackish, but who cares? window.onload = function () { // (new berjon.respec()).run(); (new berjon.respec()).loadAndRun(); }; function dbg (obj) { var str = ""; for (var k in obj) str += k + "=" + obj[k] + "\n"; alert("DUMP\n" + str); } })(); --- NEW FILE: shortcut.js --- /** * http://www.openjs.com/scripts/events/keyboard_shortcuts/ * Version : 2.01.B * By Binny V A * License : BSD */ shortcut = { 'all_shortcuts':{},//All the shortcuts are stored in this array 'add': function(shortcut_combination,callback,opt) { //Provide a set of default options var default_options = { 'type':'keydown', 'propagate':false, 'disable_in_input':false, 'target':document, 'keycode':false } if(!opt) opt = default_options; else { for(var dfo in default_options) { if(typeof opt[dfo] == 'undefined') opt[dfo] = default_options[dfo]; } } var ele = opt.target; if(typeof opt.target == 'string') ele = document.getElementById(opt.target); var ths = this; shortcut_combination = shortcut_combination.toLowerCase(); //The function to be called at keypress var func = function(e) { e = e || window.event; if(opt['disable_in_input']) { //Don't enable shortcut keys in Input, Textarea fields var element; if(e.target) element=e.target; else if(e.srcElement) element=e.srcElement; if(element.nodeType==3) element=element.parentNode; if(element.tagName == 'INPUT' || element.tagName == 'TEXTAREA') return; } //Find Which key is pressed if (e.keyCode) code = e.keyCode; else if (e.which) code = e.which; var character = String.fromCharCode(code).toLowerCase(); if(code == 188) character=","; //If the user presses , when the type is onkeydown if(code == 190) character="."; //If the user presses , when the type is onkeydown var keys = shortcut_combination.split("+"); //Key Pressed - counts the number of valid keypresses - if it is same as the number of keys, the shortcut function is invoked var kp = 0; //Work around for stupid Shift key bug created by using lowercase - as a result the shift+num combination was broken var shift_nums = { "`":"~", "1":"!", "2":"@", "3":"#", "4":"$", "5":"%", "6":"^", "7":"&", "8":"*", "9":"(", "0":")", "-":"_", "=":"+", ";":":", "'":"\"", ",":"<", ".":">", "/":"?", "\\":"|" } //Special Keys - and their codes var special_keys = { 'esc':27, 'escape':27, 'tab':9, 'space':32, 'return':13, 'enter':13, 'backspace':8, 'scrolllock':145, 'scroll_lock':145, 'scroll':145, 'capslock':20, 'caps_lock':20, 'caps':20, 'numlock':144, 'num_lock':144, 'num':144, 'pause':19, 'break':19, 'insert':45, 'home':36, 'delete':46, 'end':35, 'pageup':33, 'page_up':33, 'pu':33, 'pagedown':34, 'page_down':34, 'pd':34, 'left':37, 'up':38, 'right':39, 'down':40, 'f1':112, 'f2':113, 'f3':114, 'f4':115, 'f5':116, 'f6':117, 'f7':118, 'f8':119, 'f9':120, 'f10':121, 'f11':122, 'f12':123 } var modifiers = { shift: { wanted:false, pressed:false}, ctrl : { wanted:false, pressed:false}, alt : { wanted:false, pressed:false}, meta : { wanted:false, pressed:false} //Meta is Mac specific }; if(e.ctrlKey) modifiers.ctrl.pressed = true; if(e.shiftKey) modifiers.shift.pressed = true; if(e.altKey) modifiers.alt.pressed = true; if(e.metaKey) modifiers.meta.pressed = true; for(var i=0; k=keys[i],i<keys.length; i++) { //Modifiers if(k == 'ctrl' || k == 'control') { kp++; modifiers.ctrl.wanted = true; } else if(k == 'shift') { kp++; modifiers.shift.wanted = true; } else if(k == 'alt') { kp++; modifiers.alt.wanted = true; } else if(k == 'meta') { kp++; modifiers.meta.wanted = true; } else if(k.length > 1) { //If it is a special key if(special_keys[k] == code) kp++; } else if(opt['keycode']) { if(opt['keycode'] == code) kp++; } else { //The special keys did not match if(character == k) kp++; else { if(shift_nums[character] && e.shiftKey) { //Stupid Shift key bug created by using lowercase character = shift_nums[character]; if(character == k) kp++; } } } } if(kp == keys.length && modifiers.ctrl.pressed == modifiers.ctrl.wanted && modifiers.shift.pressed == modifiers.shift.wanted && modifiers.alt.pressed == modifiers.alt.wanted && modifiers.meta.pressed == modifiers.meta.wanted) { callback(e); if(!opt['propagate']) { //Stop the event //e.cancelBubble is supported by IE - this will kill the bubbling process. e.cancelBubble = true; e.returnValue = false; //e.stopPropagation works in Firefox. if (e.stopPropagation) { e.stopPropagation(); e.preventDefault(); } return false; } } } this.all_shortcuts[shortcut_combination] = { 'callback':func, 'target':ele, 'event': opt['type'] }; //Attach the function with the event if(ele.addEventListener) ele.addEventListener(opt['type'], func, false); else if(ele.attachEvent) ele.attachEvent('on'+opt['type'], func); else ele['on'+opt['type']] = func; }, //Remove the shortcut - just specify the shortcut and I will remove the binding 'remove':function(shortcut_combination) { shortcut_combination = shortcut_combination.toLowerCase(); var binding = this.all_shortcuts[shortcut_combination]; delete(this.all_shortcuts[shortcut_combination]) if(!binding) return; var type = binding['event']; var ele = binding['target']; var callback = binding['callback']; if(ele.detachEvent) ele.detachEvent('on'+type, callback); else if(ele.removeEventListener) ele.removeEventListener(type, callback, false); else ele['on'+type] = false; } } --- NEW FILE: simple-node.js --- // ------------------------------------------------------------------------------------------ // // simple-node.js -- simplified elements creations (based on XML::SimpleNode) // Robin Berjon, <robin at berjon dot org> // v0.01 - 2009-07-29 // ------------------------------------------------------------------------------------------ // if (typeof(berjon) == "undefined") berjon = {}; berjon.simpleNode = function (ns, doc) { // XXX need to default the xml prefix if (!ns) ns = {}; if (!doc) doc = document; this.ns = ns; this.doc = doc; }; berjon.calls = {}; berjon.simpleNode.prototype = { // --- NODE CREATION --- element: function (name, attr, parent, content) { if (!attr) attr = {}; var nmSt = this._nameToQName(name, false); var el = this.doc.createElementNS(nmSt.ns, name); for (var k in attr) this._setAttr(el, k, attr[k]); if (parent) parent.appendChild(el); if (content) { if (content instanceof Array) for (var i = 0; i < content.length; i++) el.appendChild(content[i]); else this.text(content, el); } return el; }, text: function (txt, parent) { var tn = this.doc.createTextNode(txt); if (parent) parent.appendChild(tn); return tn; }, comment: function (txt, parent) { var cmt = this.doc.createComment(txt); if (parent) parent.appendChild(cmt); return cmt; }, pi: function (target, data, parent) { var pi = this.doc.createProcessingInstruction(target, data); if (parent) parent.appendChild(pi); return pi; }, documentFragment: function (parent, content) { var df = this.doc.createDocumentFragment(); if (content) { if (content instanceof Array) for (var i = 0; i < content.length; i++) df.appendChild(content[i]); else this.text(content, df); } if (parent) parent.appendChild(df); return df; }, // --- FINDING STUFF --- findNodes: function (xpath, context) { if (!context) context = this.doc; var ns = this.ns; var snap = this.doc.evaluate(xpath, context, function (pfx) { return ns[pfx] || null; }, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); var res = []; for (var i = 0; i < snap.snapshotLength; i++) res.push(snap.snapshotItem(i)); return res; }, // --- MANIPULATION --- copyChildren: function (from, to) { while (from.childNodes.length) to.appendChild(from.firstChild); }, copyAttr: function (from, to) { for (var i = 0; i < from.attributes.length; i++) { var at = from.attributes[i]; to.setAttributeNS(at.namespaceURI, at.name, at.value); } }, renameEl: function (el, name) { // we remove, copy, then insert instead of just replacing because it's a *lot* // faster if the copyChildren operation is done while the node is not being displayed var folSib = el.nextSibling; var par = el.parentNode; if (par) par.removeChild(el); var newEl = this.element(name); this.copyAttr(el, newEl); this.copyChildren(el, newEl); // if (el.parentNode) el.parentNode.replaceChild(newEl, el); if (par) par.insertBefore(newEl, folSib); return newEl; }, // --- ID MANAGEMENT --- makeID: function (el, pfx, txt) { if (el.hasAttribute("id")) return el.getAttribute("id"); var id = ""; if (!txt) { if (el.hasAttribute("title")) txt = el.getAttribute("title"); else txt = el.textContent; } txt = txt.replace(/^\s+/, ""); txt = txt.replace(/\s+$/, ""); id += txt; id = id.toLowerCase(); if (id.length == 0) id = "generatedID"; id = this.sanitiseID(id); if (pfx) id = pfx + "-" + id; id = this.idThatDoesNotExist(id); el.setAttribute("id", id); return id; }, sanitiseID: function (id) { id = id.split(/[^-.0-9a-zA-Z_]/).join("-"); id = id.replace(/^-+/g, ""); id = id.replace(/-+$/, ""); if (id.length > 0 && /^[^a-z]/.test(id)) id = "x" + id; if (id.length == 0) id = "generatedID"; return id; }, idCache: {}, idThatDoesNotExist: function (id) { var inc = 1; if (this.doc.getElementById(id) || this.idCache[id]) { while (this.doc.getElementById(id + "-" + inc) || this.idCache[id + "-" + inc]) inc++; id = id + "-" + inc; } // XXX disable caching for now // this.idCache[id] = true; return id; }, // --- CLASS HANDLING --- hasClass: function (el, cl) { return this.listClasses(el).indexOf(cl) >= 0; }, addClass: function (el, cl) { var ls = this.listClasses(el); if (ls.indexOf(cl) >= 0) return; ls.push(cl); this.setClassList(el, ls); }, removeClass: function (el, cl) { var ls = this.listClasses(el); var idx = ls.indexOf(cl); if (idx < 0) return; ls.splice(idx, 1); this.setClassList(el, ls); }, listClasses: function (el) { if (el.hasAttribute("class")) { return el.getAttribute("class").split(/\s+/); } else return []; }, setClassList: function (el, ls) { el.setAttribute("class", ls.join(" ")); }, // --- HELPERS --- _nameToQName: function (name, isAttr) { var matches = /^(.+):(.+)$/.exec(name); var pfx, ns, ln; if (matches) { pfx = matches[1]; ln = matches[2]; if (!this.ns[pfx]) throw "No namespace declared for prefix '" + pfx + "'"; ns = this.ns[pfx]; } else { if (isAttr) ns = null; else ns = this.ns[""]; ln = name; } return { ns: ns, ln: ln }; }, _setAttr: function (el, name, value) { var nmSt = this._nameToQName(name, true); el.setAttributeNS(nmSt.ns, nmSt.ln, value); } }; --- NEW FILE: sh_main.min.js --- /* Copyright (C) 2007, 2008 gnombat@users.sourceforge.net */ /* License: http://shjs.sourceforge.net/doc/gplv3.html */ if(!this.sh_languages){this.sh_languages={}}var sh_requests={};function sh_isEmailAddress(a){if(/^mailto:/.test(a)){return false}return a.indexOf("@")!==-1}function sh_setHref(b,c,d){var a=d.substring(b[c-2].pos,b[c-1].pos);if(a.length>=2&&a.charAt(0)==="<"&&a.charAt(a.length-1)===">"){a=a.substr(1,a.length-2)}if(sh_isEmailAddress(a)){a="mailto:"+a}b[c-2].node.href=a}function sh_konquerorExec(b){var a=[""];a.index=b.length;a.input=b;return a}function sh_highlightString(B,o){if(/Konqueror/.test(navigator.userAgent)){if(!o.konquered){for(var F=0;F<o.length;F++){for(var H=0;H<o[F].length;H++){var G=o[F][H][0];if(G.source==="$"){G.exec=sh_konquerorExec}}}o.konquered=true}}var N=document.createElement("a");var q=document.createElement("span");var A=[];var j=0;var n=[];var C=0;var k=null;var x=function(i,a){var p=i.length;if(p===0){return}if(!a){var Q=n.length;if(Q!==0){var r=n[Q-1];if(!r[3]){a=r[1]}}}if(k!==a){if(k){A[j++]={pos:C};if(false && k==="sh_url"){sh_setHref(A,j,B)}}if(a){var P;if(false && a==="sh_url")P=N.cloneNode(false)}else{P=q.cloneNode(false)}P.className=a;A[j++]={node:P,pos:C}}}C+=p;k=a};var t=/\r\n|\r|\n/g;t.lastIndex=0;var d=B.length;while(C<d){var v=C;var l;var w;var h=t.exec(B);if(h===null){l=d;w=d}else{l=h.index;w=t.lastIndex}var g=B.substring(v,l);var M=[];for(;;){var I=C-v;var D;var y=n.length;if(y===0){D=0}else{D=n[y-1][2]}var O=o[D];var z=O.length;var m=M[D];if(!m){m=M[D]=[]}var E=null;var u=-1;for(var K=0;K<z;K++){var f;if(K<m.length&&(m[K]===null||I<=m[K].index)){f=m[K]}else{var c=O[K][0];c.lastIndex=I;f=c.exec(g);m[K]=f}if(f!==null&&(E===null||f.index<E.index)){E=f;u=K;if(f.index===I){break}}}if(E===null){x(g.substring(I),null);break}else{if(E.index>I){x(g.substring(I,E.index),null)}var e=O[u];var J=e[1];var b;if(J instanceof Array){for(var L=0;L<J.length;L++){b=E[L+1];x(b,J[L])}}else{b=E[0];x(b,J)}switch(e[2]){case -1:break;case -2:n.pop();break;case -3:n.length=0;break;default:n.push(e);break}}}if(k){A[j++]={pos:C};if(false && k==="sh_url"){sh_setHref(A,j,B)}k=null}C=w}return A}functin sh_getClasses(d){var a=[];var b=d.className;if(b&&b.length>0){var e=b.split(" ");for(var c=0;c<e.length;c++){if(e[c].length>0){a.push(e[c])}}}return a}function sh_addClass(c,a){var d=sh_getClasses(c);for(var b=0;b<d.length;b++){if(a.toLowerCase()===d[b].toLowerCase()){return}}d.push(a);c.className=d.join(" ")}function sh_extractTagsFromNodeList(c,a){var f=c.length;for(var d=0;d<f;d++){var e=c.item(d);switch(e.nodeType){case 1:if(e.nodeName.toLowerCase()==="br"){var b;if(/MSIE/.test(navigator.userAgent)){b="\r"}else{b="\n"}a.text.push(b);a.pos++}else{a.tags.push({node:e.cloneNode(false),pos:a.pos});sh_extractTagsFromNodeList(e.childNodes,a);a.tags.push({pos:a.pos})}break;case 3:case 4:a.text.push(e.data);a.pos+=e.length;break}}}function sh_extractTags(c,b){var a={};a.text=[];a.tags=b;a.pos=0;sh_extractTagsFromNodeList(c.childNodes,a);return a.text.join("")}function sh_mergeTags(d,f){var a=d.length;if(a===0){return f}var c=f.length;if(c===0){return d}var i=[];var e=0;var b=0;while(e<a&&b<c){var h=d[e];var gf[b];if(h.pos<=g.pos){i.push(h);e++}else{i.push(g);if(f[b+1].pos<=h.pos){b++;i.push(f[b]);b++}else{i.push({pos:h.pos});f[b]={node:g.node.cloneNode(false),pos:h.pos}}}}while(e<a){i.push(d[e]);e++}while(b<c){i.push(f[b]);b++}return i}function sh_insertTags(k,h){var g=document;var l=document.createDocumentFragment();var e=0;var d=k.length;var b=0;var j=h.length;var c=l;while(b<j||e<d){var i;var a;if(e<d){i=k[e];a=i.pos}else{a=j}if(a<=b){if(i.node){var f=i.node;c.appendChild(f);c=f}else{c=c.parentNode}e++}else{c.appendChild(g.createTextNode(h.substring(b,a)));b=a}}return l}function sh_highlightElement(d,g){sh_addClass(d,"sh_sourceCode");var c=[];var e=sh_extractTags(d,c);var f=sh_highlightString(e,g);var b=sh_mergeTags(c,f);var a=sh_insertTags(b,e);while(d.hasChildNodes()){d.removeChild(d.firstChild)}d.appendChild(a)}function sh_getXMLHttpRequest(){if(window.ActiveXObject){return new ActiveXObject("Msxml2.XMLHTTP")}else{if(window.XMLHttpRequest){return new XMLHttpRequest()}}throw"No XMLHttpRequest implementatio available"}function sh_load(language,element,prefix,suffix){if(language in sh_requests){sh_requests[language].push(element);return}sh_requests[language]=[element];var request=sh_getXMLHttpRequest();var url=prefix+"sh_"+language+suffix;request.open("GET",url,true);request.onreadystatechange=function(){if(request.readyState===4){try{if(!request.status||request.status===200){eval(request.responseText);var elements=sh_requests[language];for(var i=0;i<elements.length;i++){sh_highlightElement(elements[i],sh_languages[language])}}else{throw"HTTP error: status "+request.status}}finally{request=null}}};request.send(null)}function sh_highlightDocument(g,k){var b=document.getElementsByTagName("pre");for(var e=0;e<b.length;e++){var f=b.item(e);var a=sh_getClasses(f);for(var c=0;c<a.length;c++){var h=a[c].toLowerCase();if(h==="sh_sourcecode"){continue}if(h.substr(0,3)==="sh_"){var d=h.substring(3);if(d in sh_languages){sh_highlightElement(f,sh_languages[d])}else{if(typeof(g)==="string"&&typeof(k)==="string"){sh_load(d,,g,k)}else{throw'Found <pre> element with class="'+h+'", but no such language exists'}}break}}}};
Received on Wednesday, 14 December 2011 07:32:59 UTC