source: main/trunk/greenstone3/web/interfaces/oran/js/annotator/pkg/annotator.min.js@ 24771

Last change on this file since 24771 was 24771, checked in by papitha, 13 years ago

Changes to JS

File size: 24.9 KB
Line 
1(function(){var k,g,b,c,p,j,m,d,h,f,q,a,i;var l=Array.prototype.slice,n=function(r,s){return function(){return r.apply(s,arguments)}},o=Object.prototype.hasOwnProperty,e=function(u,s){for(var r in s){if(o.call(s,r)){u[r]=s[r]}}function t(){this.constructor=u}t.prototype=s.prototype;u.prototype=new t;u.__super__=s.prototype;return u};if(!(typeof jQuery!=="undefined"&&jQuery!==null?(i=jQuery.fn)!=null?i.jquery:void 0:void 0)){console.error("Annotator requires jQuery: have you included lib/vendor/jquery.js?")}if(!(JSON&&JSON.parse&&JSON.stringify)){console.error("Annotator requires a JSON implementation: have you included lib/vendor/json2.js?")}k=jQuery.sub();k.flatten=function(s){var r;r=function(u){var v,x,w,t;x=[];for(w=0,t=u.length;w<t;w++){v=u[w];x=x.concat(v&&k.isArray(v)?r(v):v)}return x};return r(s)};k.plugin=function(s,r){return jQuery.fn[s]=function(u){var t;t=Array.prototype.slice.call(arguments,1);return this.each(function(){var v;v=k.data(this,s);if(v){return u&&v[u].apply(v,t)}else{v=new r(this,u);return k.data(this,s,v)}})}};k.fn.textNodes=function(){var r;r=function(t){var s;if(t&&t.nodeType!==3){s=[];if(t.nodeType!==8){t=t.lastChild;while(t){s.push(r(t));t=t.previousSibling}}return s.reverse()}else{return t}};return this.map(function(){return k.flatten(r(this))})};k.fn.xpath=function(r){var s;s=this.map(function(){var u,t,v;v="";u=this;while(u&&u.nodeType===1&&u!==r){t=k(u.parentNode).children(u.tagName).index(u)+1;t=t>1?"["+t+"]":"";v="/"+u.tagName.toLowerCase()+t+v;u=u.parentNode}return v});return s.get()};k.escape=function(r){return r.replace(/&(?!\w+;)/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")};k.fn.escape=function(r){if(arguments.length){return this.html(k.escape(r))}return this.html()};j=["log","debug","info","warn","exception","assert","dir","dirxml","trace","group","groupEnd","groupCollapsed","time","timeEnd","profile","profileEnd","count","clear","table","error","notifyFirebug","firebug","userObjects"];if(typeof console!=="undefined"&&console!==null){if(!(console.group!=null)){console.group=function(r){return console.log("GROUP: ",r)}}if(!(console.groupCollapsed!=null)){console.groupCollapsed=console.group}for(h=0,q=j.length;h<q;h++){p=j[h];if(!(console[p]!=null)){console[p]=function(){return console.log("Not implemented: console."+name)}}}}else{this.console={};for(f=0,a=j.length;f<a;f++){p=j[f];this.console[p]=function(){}}this.console.error=function(){var r;r=1<=arguments.length?l.call(arguments,0):[];return alert("ERROR: "+(r.join(", ")))};this.console.warn=function(){var r;r=1<=arguments.length?l.call(arguments,0):[];return alert("WARNING: "+(r.join(", ")))}}b=(function(){r.prototype.events={};r.prototype.options={};r.prototype.element=null;function r(t,s){this.options=k.extend(true,{},this.options,s);this.element=k(t);this.on=this.subscribe;this.addEvents()}r.prototype.addEvents=function(){var v,x,w,s,u,z,y,t;z=this.events;t=[];for(w in z){x=z[w];y=w.split(" "),s=2<=y.length?l.call(y,0,u=y.length-1):(u=0,[]),v=y[u++];t.push(this.addEvent(s.join(" "),v,x))}return t};r.prototype.addEvent=function(s,u,v){var w,t;w=n(function(){return this[v].apply(this,arguments)},this);t=typeof s==="string"&&s.replace(/\s+/g,"")==="";if(t){s=this.element}if(typeof s==="string"){this.element.delegate(s,u,w)}else{if(this.isCustomEvent(u)){this.subscribe(u,w)}else{k(s).bind(u,w)}}return this};r.prototype.isCustomEvent=function(t){var s;s="blur focus focusin focusout load resize scroll unload click dblclick\nmousedown mouseup mousemove mouseover mouseout mouseenter mouseleave\nchange select submit keydown keypress keyup error".split(/[^a-z]+/);t=t.split(".")[0];return k.inArray(t,s)===-1};r.prototype.publish=function(){this.element.triggerHandler.apply(this.element,arguments);return this};r.prototype.subscribe=function(s,u){var t;t=function(){return u.apply(this,[].slice.call(arguments,1))};t.guid=u.guid=(k.guid+=1);this.element.bind(s,t);return this};r.prototype.unsubscribe=function(){this.element.unbind.apply(this.element,arguments);return this};return r})();c={};c.sniff=function(s){if(s.commonAncestorContainer!=null){return new c.BrowserRange(s)}else{if(typeof s.start==="string"){return new c.SerializedRange(s)}else{if(s.start&&typeof s.start==="object"){return new c.NormalizedRange(s)}else{console.error("Couldn't not sniff range type");return false}}}};c.BrowserRange=(function(){function r(s){this.commonAncestorContainer=s.commonAncestorContainer;this.startContainer=s.startContainer;this.startOffset=s.startOffset;this.endContainer=s.endContainer;this.endOffset=s.endOffset}r.prototype.normalize=function(A){var z,v,B,y,u,t,x,s,w;if(this.tainted){console.error("You may only call normalize() once on a BrowserRange!");return false}else{this.tainted=true}t={};B={};w=["start","end"];for(x=0,s=w.length;x<s;x++){u=w[x];v=this[u+"Container"];y=this[u+"Offset"];if(v.nodeType===1){z=v.childNodes[y];v=z||v.childNodes[y-1];while(v.nodeType!==3){v=v.firstChild}y=z?0:v.nodeValue.length}t[u]=v;t[u+"Offset"]=y}B.start=t.startOffset>0?t.start.splitText(t.startOffset):t.start;if(t.start===t.end){if((t.endOffset-t.startOffset)<B.start.nodeValue.length){B.start.splitText(t.endOffset-t.startOffset)}B.end=B.start}else{if(t.endOffset<t.end.nodeValue.length){t.end.splitText(t.endOffset)}B.end=t.end}B.commonAncestor=this.commonAncestorContainer;while(B.commonAncestor.nodeType!==1){B.commonAncestor=B.commonAncestor.parentNode}return new c.NormalizedRange(B)};r.prototype.serialize=function(s,t){return this.normalize(s).serialize(s,t)};return r})();c.NormalizedRange=(function(){function r(s){this.commonAncestor=s.commonAncestor;this.start=s.start;this.end=s.end}r.prototype.normalize=function(s){return this};r.prototype.limit=function(w){var s,v,t,u,y,x;s=k.grep(this.textNodes(),function(z){return z.parentNode===w||k.contains(w,z.parentNode)});if(!s.length){return null}this.start=s[0];this.end=s[s.length-1];t=k(this.start).parents();x=k(this.end).parents();for(u=0,y=x.length;u<y;u++){v=x[u];if(t.index(v)!==-1){this.commonAncestor=v;break}}return this};r.prototype.serialize=function(u,v){var t,s,w;s=function(B,A){var z,y,D,G,F,E,C,x;if(v){G=k(B).parents(":not("+v+")").eq(0)}else{G=k(B).parent()}E=G.xpath(u)[0];F=G.textNodes();y=F.slice(0,F.index(B));D=0;for(C=0,x=y.length;C<x;C++){z=y[C];D+=z.nodeValue.length}if(A){return[E,D+B.nodeValue.length]}else{return[E,D]}};w=s(this.start);t=s(this.end,true);return new c.SerializedRange({start:w[0],end:t[0],startOffset:w[1],endOffset:t[1]})};r.prototype.text=function(){var s;return((function(){var u,w,v,t;v=this.textNodes();t=[];for(u=0,w=v.length;u<w;u++){s=v[u];t.push(s.nodeValue)}return t}).call(this)).join("")};r.prototype.textNodes=function(){var s,v,t,u;t=k(this.commonAncestor).textNodes();u=[t.index(this.start),t.index(this.end)],v=u[0],s=u[1];return k.makeArray(t.slice(v,(s+1)||9000000000))};return r})();c.SerializedRange=(function(){function r(s){this.start=s.start;this.startOffset=s.startOffset;this.end=s.end;this.endOffset=s.endOffset}r.prototype._nodeFromXPath=function(s){var x,w,t,v,u;w=function(z,y){if(y==null){y=null}return document.evaluate(z,document,y,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue};if(!k.isXMLDoc(document.documentElement)){return w(s)}else{x=document.createNSResolver(document.ownerDocument===null?document.documentElement:document.ownerDocument.documentElement);v=w(s,x);if(!v){s=((function(){var z,B,A,y;A=s.split("/");y=[];for(z=0,B=A.length;z<B;z++){u=A[z];y.push(u&&u.indexOf(":")===-1?u.replace(/^([a-z]+)/,"xhtml:$1"):u)}return y})()).join("/");t=document.lookupNamespaceURI(null);x=function(y){if(y==="xhtml"){return t}else{return document.documentElement.getAttribute("xmlns:"+y)}};v=w(s,x)}return v}};r.prototype.normalize=function(E){var I,B,A,G,y,D,F,C,z,x,t,s,J,H,w,v,u;F=k(E).xpath()[0];z=this.start.split("/");A=this.end.split("/");B=[];C={};for(G=0,w=z.length;0<=w?G<w:G>w;0<=w?G++:G--){if(z[G]===A[G]){B.push(z[G])}else{break}}I=F+B.join("/");C.commonAncestorContainer=this._nodeFromXPath(I);if(!C.commonAncestorContainer){console.error("Error deserializing range: can't find XPath '"+I+"'. Is this the right document?");return null}v=["start","end"];for(t=0,J=v.length;t<J;t++){D=v[t];y=0;u=k(this._nodeFromXPath(F+this[D])).textNodes();for(s=0,H=u.length;s<H;s++){x=u[s];if(y+x.nodeValue.length>=this[D+"Offset"]){C[D+"Container"]=x;C[D+"Offset"]=this[D+"Offset"]-y;break}else{y+=x.nodeValue.length}}}return new c.BrowserRange(C).normalize(E)};r.prototype.serialize=function(s,t){return this.normalize(s).serialize(s,t)};r.prototype.toObject=function(){return{start:this.start,startOffset:this.startOffset,end:this.end,endOffset:this.endOffset}};return r})();m={getGlobal:function(){return(function(){return this})()},mousePosition:function(r,t){var s;s=k(t).offset();return{top:r.pageY-s.top,left:r.pageX-s.left}}};d=this.Annotator;g=(function(){e(r,b);r.prototype.events={".annotator-adder button click":"onAdderClick",".annotator-adder button mousedown":"onAdderMousedown",".annotator-hl mouseover":"onHighlightMouseover",".annotator-hl mouseout":"startViewerHideTimer"};r.prototype.html={hl:'<span class="annotator-hl"></span>',adder:'<div class="annotator-adder"><button>Annotate</button></div>',wrapper:'<div class="annotator-wrapper"></div>'};r.prototype.options={};r.prototype.plugins={};r.prototype.editor=null;r.prototype.viewer=null;r.prototype.selectedRanges=null;r.prototype.mouseIsDown=false;r.prototype.ignoreMouseup=false;r.prototype.viewerHideTimer=null;function r(u,t){this.onDeleteAnnotation=n(this.onDeleteAnnotation,this);this.onEditAnnotation=n(this.onEditAnnotation,this);this.onAdderClick=n(this.onAdderClick,this);this.onAdderMousedown=n(this.onAdderMousedown,this);this.onHighlightMouseover=n(this.onHighlightMouseover,this);this.checkForEndSelection=n(this.checkForEndSelection,this);this.checkForStartSelection=n(this.checkForStartSelection,this);this.clearViewerHideTimer=n(this.clearViewerHideTimer,this);this.startViewerHideTimer=n(this.startViewerHideTimer,this);this.showViewer=n(this.showViewer,this);this.onEditorSubmit=n(this.onEditorSubmit,this);this.onEditorHide=n(this.onEditorHide,this);this.showEditor=n(this.showEditor,this);var s,v,w;r.__super__.constructor.apply(this,arguments);this.plugins={};if(!r.supported()){return this}this._setupDocumentEvents()._setupWrapper()._setupViewer()._setupEditor();w=this.html;for(s in w){v=w[s];if(s!=="wrapper"){this[s]=k(v).appendTo(this.wrapper).hide()}}}r.prototype._setupWrapper=function(){this.wrapper=k(this.html.wrapper);this.element.find("script").remove();this.element.wrapInner(this.wrapper);this.wrapper=this.element.find(".annotator-wrapper");return this};r.prototype._setupViewer=function(){this.viewer=new r.Viewer();this.viewer.hide().on("edit",this.onEditAnnotation).on("delete",this.onDeleteAnnotation).addField({load:n(function(t,s){k(t).escape(s.text||"");return this.publish("annotationViewerTextField",[t,s])},this)}).element.appendTo(this.wrapper).bind({mouseover:this.clearViewerHideTimer,mouseout:this.startViewerHideTimer});return this};r.prototype._setupEditor=function(){this.editor=new r.Editor();this.editor.hide().on("hide",this.onEditorHide).on("save",this.onEditorSubmit).addField({type:"textarea",label:"Comments\u2026",load:function(t,s){return k(t).find("textarea").val(s.text||"")},submit:function(t,s){return s.text=k(t).find("textarea").val()}});this.editor.element.appendTo(this.wrapper);return this};r.prototype._setupDocumentEvents=function(){k(document).bind({mouseup:this.checkForEndSelection,mousedown:this.checkForStartSelection});return this};r.prototype.getSelectedRanges=function(){var v,t,s,u;u=m.getGlobal().getSelection();s=[];if(!u.isCollapsed){s=(function(){var x,w;w=[];for(t=0,x=u.rangeCount;0<=x?t<x:t>x;0<=x?t++:t--){v=new c.BrowserRange(u.getRangeAt(t));w.push(v.normalize().limit(this.wrapper[0]))}return w}).call(this)}return k.grep(s,function(w){return w})};r.prototype.createAnnotation=function(){var s;s={};this.publish("beforeAnnotationCreated",[s]);return s};r.prototype.setupAnnotation=function(s,u){var t,y,x,v,w,z;if(u==null){u=true}s.ranges||(s.ranges=this.selectedRanges);y=(function(){var B,D,C,A;C=s.ranges;A=[];for(B=0,D=C.length;B<D;B++){x=C[B];v=c.sniff(x);A.push(v.normalize(this.wrapper[0]))}return A}).call(this);y=k.grep(y,function(A){return A!==null});s.quote=[];s.ranges=[];s.highlights=[];for(w=0,z=y.length;w<z;w++){t=y[w];s.quote.push(k.trim(t.text()));s.ranges.push(t.serialize(this.wrapper[0],".annotator-hl"));k.merge(s.highlights,this.highlightRange(t))}s.quote=s.quote.join(" / ");k(s.highlights).data("annotation",s);if(u){this.publish("annotationCreated",[s])}return s};r.prototype.updateAnnotation=function(s){this.publish("beforeAnnotationUpdated",[s]);this.publish("annotationUpdated",[s]);return s};r.prototype.deleteAnnotation=function(s){var u,t,w,v;v=s.highlights;for(t=0,w=v.length;t<w;t++){u=v[t];k(u).replaceWith(u.childNodes)}this.publish("annotationDeleted",[s]);return s};r.prototype.loadAnnotations=function(t){var u,s;if(t==null){t=[]}s=n(function(x){var z,v,w,y;if(x==null){x=[]}v=x.splice(0,10);for(w=0,y=v.length;w<y;w++){z=v[w];this.setupAnnotation(z,false)}if(x.length>0){return setTimeout((function(){return s(x)}),100)}else{return this.publish("annotationsLoaded",[u])}},this);u=t.slice();if(t.length){s(t)}return this};r.prototype.dumpAnnotations=function(){if(this.plugins.Store){return this.plugins.Store.dumpAnnotations()}else{return console.warn("Can't dump annotations without Store plugin.")}};r.prototype.highlightRange=function(t){var s,u,v;return s=(function(){var x,z,y,w;y=t.textNodes();w=[];for(x=0,z=y.length;x<z;x++){u=y[x];v=this.hl.clone().show();w.push(k(u).wrap(v).parent().get(0))}return w}).call(this)};r.prototype.addPlugin=function(u,t){var s,v;if(this.plugins[u]){console.error("You cannot have more than one instance of any plugin.")}else{s=r.Plugin[u];if(typeof s==="function"){this.plugins[u]=new s(this.element[0],t);this.plugins[u].annotator=this;if(typeof(v=this.plugins[u]).pluginInit==="function"){v.pluginInit()}}else{console.error("Could not load "+u+" plugin. Have you included the appropriate <script> tag?")}}return this};r.prototype.showEditor=function(s,t){this.editor.element.css(t);this.editor.load(s);return this};r.prototype.onEditorHide=function(){this.publish("annotationEditorHidden",[this.editor]);return this.ignoreMouseup=false};r.prototype.onEditorSubmit=function(s){this.publish("annotationEditorSubmit",[this.editor,s]);if(s.ranges===void 0){return this.setupAnnotation(s)}else{return this.updateAnnotation(s)}};r.prototype.showViewer=function(t,s){this.viewer.element.css(s);this.viewer.load(t);return this.publish("annotationViewerShown",[this.viewer,t])};r.prototype.startViewerHideTimer=function(){if(!this.viewerHideTimer){return this.viewerHideTimer=setTimeout(k.proxy(this.viewer.hide,this.viewer),250)}};r.prototype.clearViewerHideTimer=function(){clearTimeout(this.viewerHideTimer);return this.viewerHideTimer=false};r.prototype.checkForStartSelection=function(s){if(!(s&&this.isAnnotator(s.target))){this.startViewerHideTimer();return this.mouseIsDown=true}};r.prototype.checkForEndSelection=function(v){var s,t,u,x,w;this.mouseIsDown=false;if(this.ignoreMouseup){return}this.selectedRanges=this.getSelectedRanges();w=this.selectedRanges;for(u=0,x=w.length;u<x;u++){t=w[u];s=t.commonAncestor;if(this.isAnnotator(s)){return}}if(v&&this.selectedRanges.length){return this.adder.css(m.mousePosition(v,this.wrapper[0])).show()}else{return this.adder.hide()}};r.prototype.isAnnotator=function(s){return !!k(s).parents().andSelf().filter("[class^=annotator-]").not(this.wrapper).length};r.prototype.onHighlightMouseover=function(s){var t;this.clearViewerHideTimer();if(this.mouseIsDown||this.viewer.isShown()){return false}t=k(s.target).parents(".annotator-hl").andSelf().map(function(){return k(this).data("annotation")});return this.showViewer(k.makeArray(t),m.mousePosition(s,this.wrapper[0]))};r.prototype.onAdderMousedown=function(s){if(s!=null){s.preventDefault()}return this.ignoreMouseup=true};r.prototype.onAdderClick=function(t){var s;if(t!=null){t.preventDefault()}s=this.adder.position();this.adder.hide();return this.showEditor(this.createAnnotation(),s)};r.prototype.onEditAnnotation=function(s){var t;t=this.viewer.element.position();this.viewer.hide();return this.showEditor(s,t)};r.prototype.onDeleteAnnotation=function(s){this.viewer.hide();return this.deleteAnnotation(s)};return r})();g.Plugin=(function(){e(r,b);function r(t,s){r.__super__.constructor.apply(this,arguments)}r.prototype.pluginInit=function(){};return r})();g.$=k;g.supported=function(){return(function(){return !!this.getSelection})()};g.noConflict=function(){m.getGlobal().Annotator=d;return this};k.plugin("annotator",g);this.Annotator=g;g.Widget=(function(){e(r,b);r.prototype.classes={hide:"annotator-hide",invert:{x:"annotator-invert-x",y:"annotator-invert-y"}};function r(t,s){r.__super__.constructor.apply(this,arguments);this.classes=k.extend({},g.Widget.prototype.classes,this.classes)}r.prototype.checkOrientation=function(){var v,w,s,u,t;this.resetOrientation();t=k(m.getGlobal());u=this.element.children(":first");w=u.offset();s={top:t.scrollTop(),right:t.width()+t.scrollLeft()};v={top:w.top,right:w.left+u.width()};if((v.top-s.top)<0){this.invertY()}if((v.right-s.right)>0){this.invertX()}return this};r.prototype.resetOrientation=function(){this.element.removeClass(this.classes.invert.x).removeClass(this.classes.invert.y);return this};r.prototype.invertX=function(){this.element.addClass(this.classes.invert.x);return this};r.prototype.invertY=function(){this.element.addClass(this.classes.invert.y);return this};return r})();g.Editor=(function(){e(r,g.Widget);r.prototype.events={"form submit":"submit",".annotator-save click":"submit",".annotator-cancel click":"hide",".annotator-cancel mouseover":"onCancelButtonMouseover","textarea keydown":"processKeypress"};r.prototype.classes={hide:"annotator-hide",focus:"annotator-focus"};r.prototype.html='<div class="annotator-outer annotator-editor">\n <form class="annotator-widget">\n <ul class="annotator-listing"></ul>\n <div class="annotator-controls">\n <a href="#cancel" class="annotator-cancel">Cancel</a>\n <a href="#save" class="annotator-save annotator-focus">Save</a>\n </div>\n <span class="annotator-resize"></span>\n </form>\n</div>';r.prototype.options={};function r(s){this.onCancelButtonMouseover=n(this.onCancelButtonMouseover,this);this.processKeypress=n(this.processKeypress,this);this.submit=n(this.submit,this);this.load=n(this.load,this);this.hide=n(this.hide,this);this.show=n(this.show,this);r.__super__.constructor.call(this,k(this.html)[0],s);this.fields=[];this.annotation={};this.setupDragabbles()}r.prototype.show=function(s){if(s!=null){s.preventDefault()}this.element.removeClass(this.classes.hide);this.element.find(".annotator-save").addClass(this.classes.focus);this.element.find(":input:first").focus();return this.checkOrientation().publish("show")};r.prototype.hide=function(s){if(s!=null){s.preventDefault()}this.element.addClass(this.classes.hide);return this.publish("hide")};r.prototype.load=function(s){var u,t,w,v;this.annotation=s;this.publish("load",[this.annotation]);v=this.fields;for(t=0,w=v.length;t<w;t++){u=v[t];u.load(u.element,this.annotation)}return this.show()};r.prototype.submit=function(t){var u,s,w,v;if(t!=null){t.preventDefault()}v=this.fields;for(s=0,w=v.length;s<w;s++){u=v[s];u.submit(u.element,this.annotation)}this.publish("save",[this.annotation]);return this.hide()};r.prototype.addField=function(t){var u,v,s;v=k.extend({id:"annotator-field-"+(new Date()).getTime(),type:"input",label:"",load:function(){},submit:function(){}},t);s=null;u=k('<li class="annotator-item" />');v.element=u[0];switch(v.type){case"textarea":s=k("<textarea />");break;case"input":case"checkbox":s=k("<input />")}u.append(s);s.attr({id:v.id,placeholder:v.label});if(v.type==="checkbox"){s[0].type="checkbox";u.addClass("annotator-checkbox");u.append(k("<label />",{"for":v.id,html:v.label}))}this.element.find("ul:first").append(u);this.fields.push(v);return v.element};r.prototype.checkOrientation=function(){var s,u,t;r.__super__.checkOrientation.apply(this,arguments);t=this.element.find("ul");s=this.element.find(".annotator-controls");u=function(){return t.children().each(function(){return k(this).parent().prepend(this)})};if(this.element.hasClass(this.classes.invert.y)&&t.is(":first-child")){s.insertBefore(t);u()}else{if(s.is(":first-child")){s.insertAfter(t);u()}}return this};r.prototype.processKeypress=function(s){if(s.keyCode===27){return this.hide()}else{if(s.keyCode===13&&!s.shiftKey){return this.submit()}}};r.prototype.onCancelButtonMouseover=function(){return this.element.find("."+this.classes.focus).removeClass(this.classes.focus)};r.prototype.setupDragabbles=function(){var u,B,x,s,w,z,v,t,y,A;s=null;u=this.classes;x=this.element;y=null;t=x.find(".annotator-resize");B=x.find(".annotator-controls");A=false;w=function(C){if(C.target===this){s={element:this,top:C.pageY,left:C.pageX};y=x.find("textarea:first");k(window).bind({"mouseup.annotator-editor-resize":v,"mousemove.annotator-editor-resize":z});return C.preventDefault()}};v=function(){s=null;return k(window).unbind(".annotator-editor-resize")};z=n(function(G){var H,E,D,C,F;if(s&&A===false){H={top:G.pageY-s.top,left:G.pageX-s.left};if(s.element===t[0]){C=y.outerHeight();F=y.outerWidth();E=x.hasClass(u.invert.x)?-1:1;D=x.hasClass(u.invert.y)?1:-1;y.height(C+(H.top*D));y.width(F+(H.left*E));if(y.outerHeight()!==C){s.top=G.pageY}if(y.outerWidth()!==F){s.left=G.pageX}}else{if(s.element===B[0]){x.css({top:parseInt(x.css("top"),10)+H.top,left:parseInt(x.css("left"),10)+H.left});s.top=G.pageY;s.left=G.pageX}}A=true;return setTimeout(function(){return A=false},1000/60)}},this);t.bind("mousedown",w);return B.bind("mousedown",w)};return r})();g.Viewer=(function(){e(r,g.Widget);r.prototype.events={".annotator-edit click":"onEditClick",".annotator-delete click":"onDeleteClick"};r.prototype.classes={hide:"annotator-hide",showControls:"annotator-visible"};r.prototype.html={element:'<div class="annotator-outer annotator-viewer">\n <ul class="annotator-widget annotator-listing"></ul>\n</div>',item:'<li class="annotator-annotation annotator-item">\n <span class="annotator-controls">\n <button class="annotator-edit">Edit</button>\n <button class="annotator-delete">Delete</button>\n </span>\n</li>'};function r(s){this.onDeleteClick=n(this.onDeleteClick,this);this.onEditClick=n(this.onEditClick,this);this.load=n(this.load,this);this.hide=n(this.hide,this);this.show=n(this.show,this);r.__super__.constructor.call(this,k(this.html.element)[0],s);this.item=k(this.html.item)[0];this.fields=[];this.annotations=[]}r.prototype.show=function(t){var s;if(t!=null){t.preventDefault()}s=this.element.find(".annotator-controls").addClass(this.classes.showControls);setTimeout((n(function(){return s.removeClass(this.classes.showControls)},this)),500);this.element.removeClass(this.classes.hide);return this.checkOrientation().publish("show")};r.prototype.isShown=function(){return !this.element.hasClass(this.classes.hide)};r.prototype.hide=function(s){if(s!=null){s.preventDefault()}this.element.addClass(this.classes.hide);return this.publish("hide")};r.prototype.load=function(A){var x,z,E,F,D,y,C,G,B,w,u,s,H,v,t;this.annotations=A||[];B=this.element.find("ul:first").empty();v=this.annotations;for(w=0,s=v.length;w<s;w++){x=v[w];G=k(this.item).clone().appendTo(B).data("annotation",x);E=G.find(".annotator-controls");D=E.find(".annotator-edit");F=E.find(".annotator-delete");z={showEdit:function(){return D.removeAttr("disabled")},hideEdit:function(){return D.attr("disabled","disabled")},showDelete:function(){return F.removeAttr("disabled")},hideDelete:function(){return F.attr("disabled","disabled")}};t=this.fields;for(u=0,H=t.length;u<H;u++){C=t[u];y=k(C.element).clone().appendTo(G)[0];C.load(y,x,z)}}this.publish("load",[this.annotations]);return this.show()};r.prototype.addField=function(s){var t;t=k.extend({load:function(){}},s);t.element=k("<div />")[0];this.fields.push(t);t.element;return this};r.prototype.onEditClick=function(s){return this.onButtonClick(s,"edit")};r.prototype.onDeleteClick=function(s){return this.onButtonClick(s,"delete")};r.prototype.onButtonClick=function(u,s){var t;t=k(u.target).parents(".annotator-annotation");return this.publish(s,[t.data("annotation")])};return r})();g=g||{};g.Notification=(function(){e(r,b);r.prototype.events={click:"hide"};r.prototype.options={html:"<div class='annotator-notice'></div>",classes:{show:"annotator-notice-show",info:"annotator-notice-info",success:"annotator-notice-success",error:"annotator-notice-error"}};function r(s){this.hide=n(this.hide,this);this.show=n(this.show,this);r.__super__.constructor.call(this,k(this.options.html).appendTo(document.body)[0],s)}r.prototype.show=function(t,s){if(s==null){s=g.Notification.INFO}k(this.element).addClass(this.options.classes.show).addClass(this.options.classes[s]).escape(t||"");setTimeout(this.hide,5000);return this};r.prototype.hide=function(){k(this.element).removeClass(this.options.classes.show);return this};return r})();g.Notification.INFO="show";g.Notification.SUCCESS="success";g.Notification.ERROR="error";k(function(){var r;r=new g.Notification;g.showNotification=r.show;return g.hideNotification=r.hide})}).call(this);
Note: See TracBrowser for help on using the repository browser.