/* (c) Copyright by authors of the Tiki Wiki CMS Groupware Project * * All Rights Reserved. See copyright.txt for details and a complete list of authors. * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details. * * $Id$ * * Include file for wikiplugin_annotation.php * */ (function ($) { $.fn.imageAnnotation = function (toCreate, showLinks) { var $container = this, containerId = $container.attr("id"), $editor = $container.find(".editor"), $list = $container.parent().find(".list-box"), editable = $editor.length > 0 && toCreate.length === 0, // default to not edit if there are existing annotations containerOffset = $container.offset(), dirty = false; $(".minimize", $editor).click(function () { endEdit(false); return false; }); $(".delete", $editor).click(function (event) { handleDelete(); event.preventDefault(); return false; }); $("#" + containerId + "-editable").change(function () { editable = $(this).prop("checked"); return false; }).prop("checked", editable); // events for the container, click and mousemove $container.click(function (event) { if (editable) { if (selected[containerId]) { if (event.target.id == containerId) endEdit(false); return; } containerOffset = $(this).offset(); // reset the offset each time in case the DOM has changed if (!active) { active = { obj: null, link: null, x1: event.pageX - containerOffset.left, x2: event.pageX - containerOffset.left, y1: event.pageY - containerOffset.top, y2: event.pageY - containerOffset.top, value: 'New annotation', target: '' }; initAnnotation(active); positionize(active); dirty = true; } else { active.y2 = event.pageY - containerOffset.top; active.x2 = event.pageX - containerOffset.left; positionize(active); activateAnnotation(active); beginEdit(event, active); active = null; serializeAnnotations(annotations); } } else { } }).mousemove(function (event) { if (active == null) return; containerOffset = $(this).offset(); active.x2 = event.pageX - containerOffset.left; active.y2 = event.pageY - containerOffset.top; positionize(active); }); // set up events on the popup form $("form", $editor).submit(function () { endEdit(true); return false; }).find("input, textarea").keyup(function (event) { if (event.keyCode == 27) { // escape key endEdit(false); } }); // submit event on the save form $("form.save-annotations", $container.parent()).submit(function () { if (selected[containerId]) { endEdit(true); } // saving dirty = false; }); // helper functions // ////////////////////// var active = null; var selected = {}; var annotations = {}; var nextid = 0; var initAnnotation = function (o) { o.obj = $("
").addClass("annotation")[0]; $container.prepend(o.obj); }, activateAnnotation = function (o) { var newone = false; if (!o.obj.id) { o.id = o.obj.id = "annotation-" + nextid++; annotations[o.id] = o; o.cid = containerId; newone = true; } var $obj = $(o.obj); var x1 = o.x1; var x2 = o.x2; var y1 = o.y1; var y2 = o.y2; o.x1 = Math.min(x1, x2); o.x2 = Math.max(x1, x2); o.y1 = Math.min(y1, y2); o.y2 = Math.max(y1, y2); var content = "

" + o.value.replace(/%%%/g, "
") + "

"; if (showLinks && o.target) { content += "" + o.target + ""; } //$obj.popover('destroy'); $obj.popover({ content: content, trigger: "hover", html: true, delay: { "show": 0, "hide": 100 } // need a small delay so you can roll over the popover }); if ($list.length && newone) { var $div = $("