summaryrefslogtreecommitdiff
path: root/core/js/quickedit.js
blob: 307a5f3a1b2ab8ddd50c83f9aaa205f1d13f0a00 (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
54
55
56
57
58
$(document).ready(function() {
  $(".gQuickEdit").hover(show_quickedit, function() {});
});

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

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

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