annotate annotator_files/lib/extensions.js @ 3:6356e78ccf5c

new version contains Annotator JS files to be used with FilesystemSite.
author casties
date Thu, 05 Apr 2012 19:37:27 +0200
parents
children 6979313586cf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
1 var $, gettext, _gettext, _ref, _t;
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
2
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
3 gettext = null;
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
4
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
5 if (typeof Gettext !== "undefined" && Gettext !== null) {
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
6 _gettext = new Gettext({
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
7 domain: "annotator"
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
8 });
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
9 gettext = function(msgid) {
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
10 return _gettext.gettext(msgid);
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
11 };
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
12 } else {
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
13 gettext = function(msgid) {
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
14 return msgid;
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
15 };
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
16 }
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
17
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
18 _t = function(msgid) {
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
19 return gettext(msgid);
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
20 };
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
21
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
22 if (!(typeof jQuery !== "undefined" && jQuery !== null ? (_ref = jQuery.fn) != null ? _ref.jquery : void 0 : void 0)) {
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
23 console.error(_t("Annotator requires jQuery: have you included lib/vendor/jquery.js?"));
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
24 }
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
25
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
26 if (!(JSON && JSON.parse && JSON.stringify)) {
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
27 console.error(_t("Annotator requires a JSON implementation: have you included lib/vendor/json2.js?"));
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
28 }
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
29
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
30 $ = jQuery.sub();
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
31
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
32 $.flatten = function(array) {
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
33 var flatten;
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
34 flatten = function(ary) {
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
35 var el, flat, _i, _len;
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
36 flat = [];
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
37 for (_i = 0, _len = ary.length; _i < _len; _i++) {
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
38 el = ary[_i];
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
39 flat = flat.concat(el && $.isArray(el) ? flatten(el) : el);
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
40 }
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
41 return flat;
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
42 };
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
43 return flatten(array);
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
44 };
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
45
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
46 $.plugin = function(name, object) {
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
47 return jQuery.fn[name] = function(options) {
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
48 var args;
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
49 args = Array.prototype.slice.call(arguments, 1);
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
50 return this.each(function() {
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
51 var instance;
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
52 instance = $.data(this, name);
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
53 if (instance) {
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
54 return options && instance[options].apply(instance, args);
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
55 } else {
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
56 instance = new object(this, options);
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
57 return $.data(this, name, instance);
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
58 }
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
59 });
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
60 };
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
61 };
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
62
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
63 $.fn.textNodes = function() {
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
64 var getTextNodes;
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
65 getTextNodes = function(node) {
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
66 var nodes;
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
67 if (node && node.nodeType !== 3) {
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
68 nodes = [];
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
69 if (node.nodeType !== 8) {
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
70 node = node.lastChild;
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
71 while (node) {
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
72 nodes.push(getTextNodes(node));
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
73 node = node.previousSibling;
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
74 }
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
75 }
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
76 return nodes.reverse();
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
77 } else {
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
78 return node;
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
79 }
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
80 };
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
81 return this.map(function() {
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
82 return $.flatten(getTextNodes(this));
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
83 });
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
84 };
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
85
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
86 $.fn.xpath = function(relativeRoot) {
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
87 var jq;
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
88 jq = this.map(function() {
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
89 var elem, idx, path;
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
90 path = '';
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
91 elem = this;
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
92 while (elem && elem.nodeType === 1 && elem !== relativeRoot) {
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
93 idx = $(elem.parentNode).children(elem.tagName).index(elem) + 1;
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
94 idx = idx > 1 ? "[" + idx + "]" : "";
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
95 path = "/" + elem.tagName.toLowerCase() + idx + path;
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
96 elem = elem.parentNode;
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
97 }
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
98 return path;
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
99 });
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
100 return jq.get();
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
101 };
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
102
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
103 $.escape = function(html) {
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
104 return html.replace(/&(?!\w+;)/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
105 };
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
106
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
107 $.fn.escape = function(html) {
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
108 if (arguments.length) return this.html($.escape(html));
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
109 return this.html();
6356e78ccf5c new version contains Annotator JS files to be used with FilesystemSite.
casties
parents:
diff changeset
110 };