<commit_before>var $ = require('wetfish-basic');
var helper = require('../app/helper');
var storage = require('../app/storage');
var tools = require('../app/tools');
var transform = require('../plugins/transform');
var explode = require('../plugins/explode');

// Module which controls the menus that appear when hovering over content
var hover =
{
    tool: 'move',
    element: false,

    init: function()
    {
        // Create a clone of the hover menu html template
        var baseTemplate = $('.hover-menu.hidden').clone();
        $(baseTemplate).removeClass('hidden').addClass('active');

        // Save it for later
        hover.baseTemplate = baseTemplate;

        // Loop through any existing workspace content
        $('.workspace .content').each(function()
        {
            $(this).on('mouseenter', function(event)
            {
                hover.start(event.target);
            });
        });

        // Bind to the creation of new content
        $('.workspace').on('content-created', function(event)
        {
            $(event.detail).on('mouseenter', function(event)
            {
                hover.start(event.target);
            });
        });

        $('.workspace').on('click', '.hover-menu .icon, .hover-menu .icon *', function()
        {
            var element = this;

            // If the user clicks on the font icon instead of the wrapper element
            if(!$(this).hasClass('icon'))
            {
                element = $(this).parents('.icon').el[0];
            }

            // Update the menu currently on the page
            $('.hover-menu .icon.active').removeClass('active');
            $(element).addClass('active');

            hover.tool = $(element).data('tool');

            // Update the saved menu template
            $(hover.baseTemplate).find('.icon.active').removeClass('active');
            $(hover.baseTemplate).find('.icon[data-tool="'+hover.tool+'"]').addClass('active');

            hover.initTools();
            hover.showControls();
        });

        $('.workspace').on('click', '.hover-menu .play, .hover-menu .play *', function()
        {
            $(hover.element).find('audio, video').el[0].play();
        });

        $('.workspace').on('click', '.hover-menu .pause, .hover-menu .pause *', function()
        {
            $(hover.element).find('audio, video').el[0].pause();
        });

        $('.workspace').on('click', '.hover-menu progress', function(event)
        {
            var media = $(hover.element).find('audio, video').el[0];
            var progress = $(this).width() / event.layerX;
            var seconds = media.duration / progress;

            media.currentTime = seconds;
        });

        // Remove hover menu when changing slides
        $('.workspace').on('slides-changed', function(event)
        {
            hover.stop();
        });

        // Bind to media (audio / video) events
        document.addEventListener('play', function(event)
        {
            var parent = $(event.target).parents('.content').el[0];

            if(parent == hover.element)
            {
                $(hover.template).find('.controls .pause').removeClass('hidden');
                $(hover.template).find('.controls .play').addClass('hidden');
            }
        }, true);

        document.addEventListener('pause', function(event)
        {
            var parent = $(event.target).parents('.content').el[0];

            if(parent == hover.element)
            {
                $(hover.template).find('.controls .play').removeClass('hidden');
                $(hover.template).find('.controls .pause').addClass('hidden');
            }
        }, true);

        document.addEventListener('timeupdate', function(event)
        {
            var parent = $(event.target).parents('.content').el[0];

            if(parent == hover.element)
            {
                $(hover.template).find('.controls progress').attr('max', event.target.duration);
                $(hover.template).find('.controls progress').value(event.target.currentTime);
            }
        }, true);
    },
    
    start: function(element)
    {
        // Check if hover menus are currently disabled
        if(!helper.hover.enabled)
        {
            return;
        }

        hover.element = element;

        // Make a clone of the default hover template
        var template = $(hover.baseTemplate).clone();
        hover.template = template;

        // Get information about the current object
        var zindex = parseInt($(element).style('z-index'));
        var size = $(element).size();

        // Make sure no other menus are still active
        hover.stop();

        $(template).style({'height': size.height + 'px', 'width': size.width + 'px', 'z-index': zindex});
        $(template).transform(element.transform);

        $(template).on('click', function(event)
        {
            // Only trigger click when clicking on the menu content (not the menu icons)
            if($(event.target).hasClass('hover-menu'))
            {
                if(hover.tool == 'interact')
                {
                    tools.interact(hover.element);
                }
                else if(hover.tool == 'edit')
                {
                    tools.edit(hover.element);
                }
                else if(hover.tool == 'delete')
                {
                    storage.remove(hover.element);
                    $(template).remove();

                    if(helper.pressed.control)
                    {
                        explode(hover.element);
                    }
                    else
                    {
                        $(hover.element).remove();
                    }
                }
            }
        });

        $(template).on('mouseleave', function()
        {
            hover.stop();
        });

        // Ensure the element being dragged is always on top
        $(template).on('dragstart', function()
        {
            helper.layers++
            $(template).style({'z-index': helper.layers});
            $(element).style({'z-index': helper.layers});

            // Disable pointer-events on content while dragging
            $('.workspace .content').style({'pointer-events': 'none'})<commit_msg>Right click to put an element on the bottom layer<commit_after>var $ = require('wetfish-basic');
var helper = require('../app/helper');
var storage = require('../app/storage');
var tools = require('../app/tools');
var transform = require('../plugins/transform');
var explode = require('../plugins/explode');

// Module which controls the menus that appear when hovering over content
var hover =
{
    tool: 'move',
    element: false,

    init: function()
    {
        // Create a clone of the hover menu html template
        var baseTemplate = $('.hover-menu.hidden').clone();
        $(baseTemplate).removeClass('hidden').addClass('active');

        // Save it for later
        hover.baseTemplate = baseTemplate;

        // Loop through any existing workspace content
        $('.workspace .content').each(function()
        {
            $(this).on('mouseenter', function(event)
            {
                hover.start(event.target);
            });
        });

        // Bind to the creation of new content
        $('.workspace').on('content-created', function(event)
        {
            $(event.detail).on('mouseenter', function(event)
            {
                hover.start(event.target);
            });
        });

        $('.workspace').on('click', '.hover-menu .icon, .hover-menu .icon *', function()
        {
            var element = this;

            // If the user clicks on the font icon instead of the wrapper element
            if(!$(this).hasClass('icon'))
            {
                element = $(this).parents('.icon').el[0];
            }

            // Update the menu currently on the page
            $('.hover-menu .icon.active').removeClass('active');
            $(element).addClass('active');

            hover.tool = $(element).data('tool');

            // Update the saved menu template
            $(hover.baseTemplate).find('.icon.active').removeClass('active');
            $(hover.baseTemplate).find('.icon[data-tool="'+hover.tool+'"]').addClass('active');

            hover.initTools();
            hover.showControls();
        });

        $('.workspace').on('click', '.hover-menu .play, .hover-menu .play *', function()
        {
            $(hover.element).find('audio, video').el[0].play();
        });

        $('.workspace').on('click', '.hover-menu .pause, .hover-menu .pause *', function()
        {
            $(hover.element).find('audio, video').el[0].pause();
        });

        $('.workspace').on('click', '.hover-menu progress', function(event)
        {
            var media = $(hover.element).find('audio, video').el[0];
            var progress = $(this).width() / event.layerX;
            var seconds = media.duration / progress;

            media.currentTime = seconds;
        });

        // Remove hover menu when changing slides
        $('.workspace').on('slides-changed', function(event)
        {
            hover.stop();
        });

        // Bind to media (audio / video) events
        document.addEventListener('play', function(event)
        {
            var parent = $(event.target).parents('.content').el[0];

            if(parent == hover.element)
            {
                $(hover.template).find('.controls .pause').removeClass('hidden');
                $(hover.template).find('.controls .play').addClass('hidden');
            }
        }, true);

        document.addEventListener('pause', function(event)
        {
            var parent = $(event.target).parents('.content').el[0];

            if(parent == hover.element)
            {
                $(hover.template).find('.controls .play').removeClass('hidden');
                $(hover.template).find('.controls .pause').addClass('hidden');
            }
        }, true);

        document.addEventListener('timeupdate', function(event)
        {
            var parent = $(event.target).parents('.content').el[0];

            if(parent == hover.element)
            {
                $(hover.template).find('.controls progress').attr('max', event.target.duration);
                $(hover.template).find('.controls progress').value(event.target.currentTime);
            }
        }, true);
    },
    
    start: function(element)
    {
        // Check if hover menus are currently disabled
        if(!helper.hover.enabled)
        {
            return;
        }

        hover.element = element;

        // Make a clone of the default hover template
        var template = $(hover.baseTemplate).clone();
        hover.template = template;

        // Get information about the current object
        var zindex = parseInt($(element).style('z-index'));
        var size = $(element).size();

        // Make sure no other menus are still active
        hover.stop();

        $(template).style({'height': size.height + 'px', 'width': size.width + 'px', 'z-index': zindex});
        $(template).transform(element.transform);

        $(template).on('mousedown', function(event)
        {
            // Only trigger click when clicking on the menu content (not the menu icons)
            if($(event.target).hasClass('hover-menu'))
            {
                // If right click was pressed
                if(event.buttons == 2)
                {
                    // Move element to the bottom layer
                    $(hover.element).style({'z-index': 0});
                    storage.update(hover.element);
                }
                else
                {
                    if(hover.tool == 'interact')
                    {
                        tools.interact(hover.element);
                    }
                    else if(hover.tool == 'edit')
                    {
                        tools.edit(hover.element);
                    }
                    else if(hover.tool == 'delete')
                    {
                        storage.remove(hover.element);
                        $(template).remove();

                        if(helper.pressed.control)
                        {
                            explode(hover.element);
                        }
                        else
                        {
                            $(hover.element).remove();
                        }
                    }
                }
            }
        });

        $(template).on('mouseleave', function()
        {
            hover.stop();
        });

        // Ensure the element being dragged is always on top
        $(template).on('dragstart', function()
        {
            helper.layers++
            $(template).style({'z-index': helper.layers});
            $(element).style({'z-index': helper.layers});

            // Disable pointer-events on content while dragging
            $('.workspace .content').style({'pointer-events': 'none'})
{'fraction_non_alphanumeric': 0.15468093236530378, 'fraction_numerical': 0.001222774168895682, 'mean_word_length': 1.5749704840613932, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3469149', 'n_tokens_mistral': 3269, 'n_tokens_neox': 3135, 'n_words': 677}