<commit_before>// -------------------------------------------------------------------------- \\
// File: NotificationView.js                                                  \\
// Module: PanelViews                                                         \\
// Requires: Core, Foundation, DOM, View                                      \\
// Author: <NAME>                                                       \\
// License: © 2010–2013 Opera Software ASA. All rights reserved.              \\
// -------------------------------------------------------------------------- \\

"use strict";

( function ( NS, undefined ) {

var hiddenLayout = {
    top: 0
};

var NotificationView = NS.Class({

    Extends: NS.View,

    Mixin: NS.AnimatableView,

    animateLayerDuration: 200,

    className: function () {
        return 'NotificationView' +
            ( this.get( 'userMayClose' ) ? ' closable' : '' );
    }.property( 'userMayClose' ),

    destroyOnClose: true,

    isShowing: false,
    userMayClose: true,
    precedence: 0,
    timeout: 0,

    hiddenLayout: hiddenLayout,
    visibleLayout: function () {
        return {
            top: this.get( 'pxHeight' )
        };
    }.property(),

    text: '',
    html: '',

    _timer: null,

    show: function ( notificationsContainer ) {
        notificationsContainer.insertView( this );
        this._show();
        var timeout = this.get( 'timeout' );
        if ( timeout ) {
            this._timer =
                NS.RunLoop.invokeAfterDelay( this.hide, timeout, this );
        }
        return this.set( 'isShowing', true );
    },

    _show: function () {
        if ( this.get( 'isShowing' ) ) {
            this.set( 'layout',  this.get( 'visibleLayout' ) );
        }
    }.later(),

    hide: function () {
        // If we don't have a layerAnimation object yet, we can't have animated
        // in, so just detach immediately. Otherwise, stop the current layer
        // animation, then animate out.
        var layerAnimation = NS.meta( this ).cache.layerAnimation,
            hiddenLayout = this.get( 'hiddenLayout' );
        if ( layerAnimation && this.get( 'layout' ) !== hiddenLayout ) {
            layerAnimation.stop();
            this.set( 'layout', hiddenLayout );
        } else {
            this.detach();
        }
        if ( this._timer ) {
            NS.RunLoop.cancel( this._timer );
            this._timer = null;
        }
        return this.set( 'isShowing', false );
    },

    didAnimate: function () {
        this.increment( 'animating', -1 );
        if ( !this.get( 'animating' ) && !this.get( 'isShowing' ) ) {
            this.detach();
        }
    },

    detach: function () {
        this.get( 'parentView' )
            .removeView( this )
            .notificationDidHide( this );

        if ( this.get( 'destroyOnClose' ) ) {
            this.destroy();
        }
        return this;
    }.queue( 'render' ),

    layout: hiddenLayout,

    draw: function ( layer ) {
        this.drawNotification( layer );
        if ( this.get( 'userMayClose' ) ) {
            layer.appendChild(
                NS.Element.create( 'a.close', [
                    NS.loc( 'Close' )
                ])
            );
        }
    },

    drawNotification: function ( layer ) {
        var text = this.get( 'text' ),
            html = this.get( 'html' );
        if ( text || html ) {
            layer.appendChild(
                this._textNode = NS.Element.create( 'span', {
                    text: text || undefined,
                    html: text ? undefined : html
                })
            );
        }
    },

    notificationNeedsRedraw: function ( self, property, oldValue ) {
       return this.propertyNeedsRedraw( self, property, oldValue );
    }.observes( 'text', 'html' ),
<commit_msg>Make NotificationView reinsertable in same event loop.<commit_after>// -------------------------------------------------------------------------- \\
// File: NotificationView.js                                                  \\
// Module: PanelViews                                                         \\
// Requires: Core, Foundation, DOM, View                                      \\
// Author: <NAME>                                                       \\
// License: © 2010–2013 Opera Software ASA. All rights reserved.              \\
// -------------------------------------------------------------------------- \\

"use strict";

( function ( NS, undefined ) {

var hiddenLayout = {
    top: 0
};

var NotificationView = NS.Class({

    Extends: NS.View,

    Mixin: NS.AnimatableView,

    animateLayerDuration: 200,

    className: function () {
        return 'NotificationView' +
            ( this.get( 'userMayClose' ) ? ' closable' : '' );
    }.property( 'userMayClose' ),

    destroyOnClose: true,

    isShowing: false,
    userMayClose: true,
    precedence: 0,
    timeout: 0,

    hiddenLayout: hiddenLayout,
    visibleLayout: function () {
        return {
            top: this.get( 'pxHeight' )
        };
    }.property(),

    text: '',
    html: '',

    _timer: null,

    show: function ( notificationsContainer ) {
        notificationsContainer.insertView( this );
        this._show();
        var timeout = this.get( 'timeout' );
        if ( timeout ) {
            this._timer =
                NS.RunLoop.invokeAfterDelay( this.hide, timeout, this );
        }
        return this.set( 'isShowing', true );
    },

    _show: function () {
        if ( this.get( 'isShowing' ) ) {
            this.set( 'layout',  this.get( 'visibleLayout' ) );
        }
    }.later(),

    hide: function () {
        // If we don't have a layerAnimation object yet, we can't have animated
        // in, so just detach immediately. Otherwise, stop the current layer
        // animation, then animate out.
        var layerAnimation = NS.meta( this ).cache.layerAnimation,
            hiddenLayout = this.get( 'hiddenLayout' );
        if ( layerAnimation && this.get( 'layout' ) !== hiddenLayout ) {
            layerAnimation.stop();
            this.set( 'layout', hiddenLayout );
        } else {
            this.detach();
        }
        if ( this._timer ) {
            NS.RunLoop.cancel( this._timer );
            this._timer = null;
        }
        return this.set( 'isShowing', false );
    },

    didAnimate: function () {
        this.increment( 'animating', -1 );
        if ( !this.get( 'animating' ) && !this.get( 'isShowing' ) ) {
            this.detach();
        }
    },

    detach: function () {
        this.get( 'parentView' )
            .removeView( this )
            .notificationDidHide( this );

        if ( this.get( 'destroyOnClose' ) ) {
            this.destroy();
        }
        return this;
    },

    layout: hiddenLayout,

    draw: function ( layer ) {
        this.drawNotification( layer );
        if ( this.get( 'userMayClose' ) ) {
            layer.appendChild(
                NS.Element.create( 'a.close', [
                    NS.loc( 'Close' )
                ])
            );
        }
    },

    drawNotification: function ( layer ) {
        var text = this.get( 'text' ),
            html = this.get( 'html' );
        if ( text || html ) {
            layer.appendChild(
                this._textNode = NS.Element.create( 'span', {
                    text: text || undefined,
                    html: text ? undefined : html
                })
            );
        }
    },

    notificationNeedsRedraw: function ( self, property, oldValue ) {
       return this.propertyNeedsRedraw( self, property, oldValue );
    }.observes( 'text', 'html' ),

{'fraction_non_alphanumeric': 0.16312703583061888, 'fraction_numerical': 0.003908794788273616, 'mean_word_length': 1.3211369821590566, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3010337', 'n_tokens_mistral': 2074, 'n_tokens_neox': 1965, 'n_words': 480}