PageRenderTime 29ms CodeModel.GetById 11ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 0ms

/htmllib/luainspect.js

http://github.com/davidm/lua-inspect
JavaScript | 66 lines | 55 code | 7 blank | 4 comment | 6 complexity | de91210b822aed2c635d8c6e3bb383fa MD5 | raw file
 1// LuaInspect (c) 2010 David Manura, MIT License.
 2
 3function get_line_of_domobject(obj) {
 4  var line = $(obj).text().match(/used-line:(\d+)/);
 5  if (line) { line = line[1]; }
 6  return line;
 7}
 8
 9function get_linerange_of_objects(jobject) {
10  var maxlinenum; var minlinenum;
11  jobject.next().each(function() {
12    var linenum = get_line_of_domobject(this);
13    if (linenum) {
14      minlinenum = (minlinenum==null) ? linenum : Math.min(minlinenum, linenum);
15      maxlinenum = (maxlinenum==null) ? linenum : Math.max(maxlinenum, linenum);
16    }
17  });
18  return [minlinenum, maxlinenum];
19}
20
21function highlight_id(aclass, enable) {
22  var methname = enable ? "addClass" : "removeClass";
23  $("." + aclass)[methname]("highlight");
24  var linenums = get_linerange_of_objects($("." + aclass));
25  if (linenums) { for (var i=linenums[0]; i <= linenums[1]; i++) {
26    $('#L'+i)[methname]("highlight");
27  }}
28}
29
30function highlightSameClass(obj, enable) {
31  var classes = obj.attr('class').split(' ');
32  for (var i in classes) {
33    var aclass = classes[i];
34    if (aclass.match(/^id\w*\d+/)) {
35      highlight_id(aclass, enable);
36    }
37  }
38}
39
40$(document).ready(function() {
41  $(".id").hover(
42    function() {
43      var tip = $(this).next('span');
44      tip.stop(true, true).animate({opacity: "show"}, "slow");
45
46      highlightSameClass($(this), true);
47    },
48    function() {
49      var tip = $(this).next('span');
50      tip.animate({opacity: "hide"}, "fast");
51      highlightSameClass($(this), false);
52    }
53  );
54  $(".keyword").hover(
55    function() {
56      highlightSameClass($(this), true);
57    },
58    function() {
59      highlightSameClass($(this), false);
60    }
61  );
62});
63
64//.mousemove(function(kmouse) {
65//        $tip.css({left:kmouse.pageX+15, top:kmouse.pageY+100});
66//      })