<commit_before>/* This file is part of Indico.
 * Copyright (C) 2002 - 2012 European Organization for Nuclear Research (CERN).
 *
 * Indico is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * Indico is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Indico; if not, see <http://www.gnu.org/licenses/>.
 */

type("ChainedPopupWidget", ["PopupWidget"],
     {
         clickTriggersClose: function(target) {

             var result = true;

             // check chain
             each(this.chainElements,
                  function(element) {
                      // since usually the first element of the chain is an Html.a...
                      element = element.ChainedPopupWidget?element.canvas:element;
                      result = result && !element.ancestorOf(target);
                  });

             return result && !this.canvas.ancestorOf(target);
         },

         open: function(x, y) {
             var self = this;
             if (this.active) {
                 // don't let the popup open twice [** Update: It's not working ! **]
                 return;
             } else {
                 this.active = true;
             }

             this.PopupWidget.prototype.open.call(this, x, y);

             // define a handler for onclick events
             $('html').on('click.chained_menu', function(event) {
                 if (self.clickTriggersClose($E(eventTarget(event)))) {
                     // if the click should be followed by a
                     // closing action (out of the chain)
                     self.close();

                     // call close() over the whole chain
                     each(self.chainElements, function(element) {
                         if (element.ChainedPopupWidget) {
                             element.close();
                         }
                     });
                 }
             });
         },

         postDraw: function () {

             this.PopupWidget.prototype.postDraw.call(this);

             if (this.alignRight) {
                 // Hide it to avoid flickering
                 this.canvas.dom.style.visibility = 'hidden';

                 // Place it to the left in order to measure the width
                 // if placed to the right it might be to wide for the page
                 this.canvas.dom.style.left = 0;

                 // Align right side of the canvas to the x position given
                 this.canvas.dom.style.left = pixels(this.x - this.canvas.dom.offsetWidth);

                 this.canvas.dom.style.visibility = 'visible';
             }
         },

         close: function() {
             // close() cleans up the onclick handler too
             this.active = false;
             $('html').off('click.chained_menu');
             this.PopupWidget.prototype.close.call(this);
         }
     },
     function(chainElements, alignRight) {
         this.PopupWidget();
         this.chainElements = chainElements;
         this.active = false;
         this.alignRight = any(alignRight, false);
     });

type("PopupMenu", ["ChainedPopupWidget"],
     {
        _processItem: function(pair) {
            var self = this;
            var value = pair.get();
            var link = Html.a('fakeLink', value.display);<commit_msg>[FIX] Remove only own handler in call to off()<commit_after>/* This file is part of Indico.
 * Copyright (C) 2002 - 2012 European Organization for Nuclear Research (CERN).
 *
 * Indico is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * Indico is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Indico; if not, see <http://www.gnu.org/licenses/>.
 */

type("ChainedPopupWidget", ["PopupWidget"],
     {
         clickTriggersClose: function(target) {

             var result = true;

             // check chain
             each(this.chainElements,
                  function(element) {
                      // since usually the first element of the chain is an Html.a...
                      element = element.ChainedPopupWidget?element.canvas:element;
                      result = result && !element.ancestorOf(target);
                  });

             return result && !this.canvas.ancestorOf(target);
         },

         open: function(x, y) {
             var self = this;
             if (this.active) {
                 // don't let the popup open twice [** Update: It's not working ! **]
                 return;
             } else {
                 this.active = true;
             }

             this.PopupWidget.prototype.open.call(this, x, y);

             var handler = function(event) {
                 if (self.clickTriggersClose($E(eventTarget(event)))) {
                     // if the click should be followed by a
                     // closing action (out of the chain)
                     self.close();

                     // call close() over the whole chain
                     each(self.chainElements, function(element) {
                         if (element.ChainedPopupWidget) {
                             element.close();
                         }
                     });
                 }
             };

             // define a handler for onclick events
             $('html').on('click.chained_menu', handler);
             this.handler = handler;
         },

         postDraw: function () {

             this.PopupWidget.prototype.postDraw.call(this);

             if (this.alignRight) {
                 // Hide it to avoid flickering
                 this.canvas.dom.style.visibility = 'hidden';

                 // Place it to the left in order to measure the width
                 // if placed to the right it might be to wide for the page
                 this.canvas.dom.style.left = 0;

                 // Align right side of the canvas to the x position given
                 this.canvas.dom.style.left = pixels(this.x - this.canvas.dom.offsetWidth);

                 this.canvas.dom.style.visibility = 'visible';
             }
         },

         close: function() {
             // close() cleans up the onclick handler too
             this.active = false;
             $('html').off('click.chained_menu', this.handler);
             this.PopupWidget.prototype.close.call(this);
         }
     },
     function(chainElements, alignRight) {
         this.PopupWidget();
         this.chainElements = chainElements;
         this.active = false;
         this.alignRight = any(alignRight, false);
     });

type("PopupMenu", ["ChainedPopupWidget"],
     {
        _processItem: function(pair) {
            var self = this;
            var value = pair.get();
            var link = Html.a('fakeLink', value.display);
{'fraction_non_alphanumeric': 0.09608540925266904, 'fraction_numerical': 0.0026360880453407142, 'mean_word_length': 1.554882154882155, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7477231', 'n_tokens_mistral': 1882, 'n_tokens_neox': 1807, 'n_words': 603}