integration/js/taghome.js
changeset 64 458cc4576415
parent 50 9cc1b66d0880
child 73 fb4d0566ab19
equal deleted inserted replaced
60:f4a03f8bc37a 64:458cc4576415
     3         tagsInner = $(".taglist_container table"),
     3         tagsInner = $(".taglist_container table"),
     4         acInput = $("#form_tag input[type=search]"),
     4         acInput = $("#form_tag input[type=search]"),
     5         acdata = [],
     5         acdata = [],
     6         labels = {
     6         labels = {
     7             content: "Séquence",
     7             content: "Séquence",
     8             tag: "Tag"
     8             tag: "Mot-clé"
     9         };
     9         },
       
    10         replacerx;
    10     
    11     
    11     acInput.autocomplete({
    12     acInput.autocomplete({
    12         source: function( request, response ) {
    13         source: function( request, response ) {
    13             response($.ui.autocomplete.filter(acdata, request.term));
    14             var charsub = [ '[aáàâä]', '[cç]', '[eéèêë]', '[iíìîï]', '[oóòôö]' ],
       
    15                 terms = request.term.split(/[\s,]/),
       
    16                 escterms = terms.map(function(term) {
       
    17                     var t = term.replace(/([\\\*\+\?\|\{\[\}\]\(\)\^\$\.\#\/])/gm, '\\$1');
       
    18                     _(charsub).each(function(chars) {
       
    19                         var tmprx = new RegExp(chars,"gim");
       
    20                         t = t.replace(tmprx, chars);
       
    21                     });
       
    22                     return t;
       
    23                 }).filter(_.identity);
       
    24                 var searchrxs = _(escterms).map(function(term) {
       
    25                     return new RegExp("(^|\\s)" + term, "i")
       
    26                 });
       
    27             replacerx = new RegExp("(^|\\s)(" + escterms.join("|") + ")", "gi");
       
    28             var filtered = acdata
       
    29                     .filter(function(d) {
       
    30                         return _(searchrxs).reduce(function(memo, rx) {
       
    31                             return memo && rx.test(d.label);
       
    32                         }, true);
       
    33                     })
       
    34                     .sort(function(a, b) {
       
    35                         if (a.type === b.type) {
       
    36                             return (a.label > b.label ? 1 : (a.label < b.label ? -1 : 0));
       
    37                         } else {
       
    38                             return (a.type === "content" ? -1 : 1);
       
    39                         }
       
    40                     });
       
    41             response(filtered);
    14         },
    42         },
    15         select: function(event, ui) {
    43         select: function(event, ui) {
    16             document.location.href = ui.item.href;
    44             document.location.href = ui.item.href;
    17         }
    45         }
    18     }).data("autocomplete")._renderItem = function(ul, item) {
    46     }).data("autocomplete")._renderItem = function(ul, item) {
    19         return $( "<li>" )
    47         return $( "<li>" )
    20             .data( "item.autocomplete", item )
    48             .data( "item.autocomplete", item )
    21             .append( "<a href='" + item.href + "'>" + labels[item.type] + " : " + item.label + "</a>" )
    49             .append( "<a href='" + item.href + "'>" + labels[item.type] + " : " + item.label.replace(replacerx, '$1<b>$2</b>') + "</a>" )
    22             .appendTo( ul );
    50             .appendTo( ul );
    23     };
    51     };
       
    52     acInput.on("keyup input paste", function() {
       
    53         acInput.val(acInput.val().toUpperCase());
       
    54     });
    24     
    55     
    25     $("#form_tag").submit(function() {
    56     $("#form_tag").submit(function() {
    26         return false;
    57         return false;
    27     });
    58     });
    28         
    59         
    29     tagsInner.draggable();
    60     tagsInner.draggable();
       
    61     
       
    62     var dragtimeout;
       
    63     
       
    64     $(".arrow_left").data({xdelta: 6, ydelta: 0});
       
    65     $(".arrow_right").data({xdelta: -6, ydelta: 0});
       
    66     $(".arrow_top").data({xdelta: 0, ydelta: 6});
       
    67     $(".arrow_bottom").data({xdelta: 0, ydelta: -6});
       
    68     
       
    69     $(".arrow")
       
    70         .mousedown(function() {
       
    71             var deltas = $(this).data(),
       
    72                 move = function() {
       
    73                     tagsInner.css({
       
    74                         "left": deltas.xdelta + parseInt(tagsInner.css("left")),
       
    75                         "top": deltas.ydelta + parseInt(tagsInner.css("top"))
       
    76                     });
       
    77                 }
       
    78             window.clearInterval(dragtimeout);
       
    79             dragtimeout = window.setInterval(move, 20);
       
    80             move();
       
    81         })
       
    82         .on(
       
    83             "mouseout mouseup",
       
    84             function() {
       
    85                 window.clearInterval(dragtimeout);
       
    86             }
       
    87         );
    30     
    88     
    31     function resizeTags() {
    89     function resizeTags() {
    32         tagsInner.css({
    90         tagsInner.css({
    33             "margin-left": - Math.floor(tagsInner.width()/2) + "px",
    91             "margin-left": - Math.floor(tagsInner.width()/2) + "px",
    34             "margin-top": - Math.floor(tagsInner.height()/2) + "px",
    92             "margin-top": - Math.floor(tagsInner.height()/2) + "px",
    45             limit: 0,
   103             limit: 0,
    46             format: "jsonp"
   104             format: "jsonp"
    47         },
   105         },
    48         success: function(data) {
   106         success: function(data) {
    49             _(data.objects).each(function(content) {
   107             _(data.objects).each(function(content) {
    50                 var fpmatch = content.front_project.match(/projects\/([0-9a-f\-]+)/),
   108                 var fpmatch = (content.front_project || "").match(/projects\/([0-9a-f\-]+)/),
    51                     fproj = fpmatch ? fpmatch[1] : "";
   109                     fproj = fpmatch ? fpmatch[1] : "";
    52                 acdata.push({
   110                 acdata.push({
    53                     label: content.title,
   111                     label: content.title,
    54                     type: "content",
   112                     type: "content",
    55                     href: endpoints.content_page.replace("__CONTENT_ID__", content.iri_id).replace("__FRONT_PROJECT_ID__", fproj)
   113                     href: endpoints.content_page.replace("__CONTENT_ID__", content.iri_id).replace("__FRONT_PROJECT_ID__", fproj)
    94                 })
   152                 })
    95                 .value();
   153                 .value();
    96             var l = ordered.length,
   154             var l = ordered.length,
    97                 max = ordered[0].weight,
   155                 max = ordered[0].weight,
    98                 min = Math.min(max - 1, ordered[l - 1].weight),
   156                 min = Math.min(max - 1, ordered[l - 1].weight),
    99                 colorscale = 128 / (max - min),
   157                 colorscale = 160 / (max - min),
   100                 ncols = Math.floor(.65*Math.sqrt(l)),
   158                 ncols = Math.floor(.65*Math.sqrt(l)),
   101                 nlines = Math.ceil(l/ncols);
   159                 nlines = Math.ceil(l/ncols);
   102             var cells = _(nlines * ncols)
   160             var cells = _(nlines * ncols)
   103                 .chain()
   161                 .chain()
   104                 .range()
   162                 .range()
   128                 if (c.x === 0) {
   186                 if (c.x === 0) {
   129                     _html += "<tr>";
   187                     _html += "<tr>";
   130                 }
   188                 }
   131                 _html += "<td>";
   189                 _html += "<td>";
   132                 if (c.tag) {
   190                 if (c.tag) {
   133                     var color = Math.floor( 127 + (c.tag.weight - min) * colorscale );
   191                     var color = Math.floor( 95 + (c.tag.weight - min) * colorscale );
   134                     _html += '<a href="'
   192                     _html += '<a href="'
   135                         + endpoints.tag_page.replace("__TAG__",encodeURIComponent(c.tag.label))
   193                         + endpoints.tag_page.replace("__TAG__",encodeURIComponent(c.tag.label))
   136                         + '" style="color: rgb('
   194                         + '" style="color: rgb('
   137                         + [color,color,color].join(",")
   195                         + [color,color,color].join(",")
   138                         + ')">'
   196                         + ')">'