summaryrefslogtreecommitdiff
path: root/core/js/quickedit.js
blob: fac227ba161531f36948aa84ffb5c14487988e6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
$(document).ready(function() {
  $("div.gQuickEdit").hover(show_quickedit, function() { });
});

var show_quickedit = function() {
  $("#gQuickEditPane").remove();
  $(this).append("<div id=\"gQuickEditPane\"></div>");
  var img = $(this).find("img");
  var pos = img.position();
  $("#gQuickEditPane").css({
    "position": "absolute",
    "top": pos.top,
    "left": pos.left,
    "width": img.innerWidth() + 1,
    "height": 32
  });
  $(this).hover(function() { }, hide_quickedit);
  $.get(
    $(this).attr("quickedit_link"),
    {},
    function(data, textStatus) {
      $("#gQuickEditPane").html(data);
      $("#gQuickEditPane div").click(function() {
	quickedit($(this).attr("quickedit_link"), img);
      });
    }
  );
};

var quickedit = function(url, img) {
  $.ajax({
    type: "GET",
    url: url,
    dataType: "json",
    success: function(data) {
      img.attr("width", data.width);
      img.attr("height", data.height);
      img.attr("src", data.src);
      var pos = img.position();
      $("#gQuickEditPane").css({
	"position": "absolute",
	"top": pos.top,
	"left": pos.left,
	"width": img.innerWidth() + 1,
	"height": 32
      });
    }
  });
};

var hide_quickedit = function() {
  $("#gQuickEditPane").remove();
};