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