<commit_before>/*
 * Rapid Interface Builder (RIB) - A simple WYSIWYG HTML5 app creator
 * Copyright (c) 2011-2012, Intel Corporation.
 *
 * This program is licensed under the terms and conditions of the
 * Apache License, version 2.0.  The full text of the Apache License is at
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 */
"use strict";

// Page view widget

(function($, undefined) {

    $.widget('rib.pageView', $.rib.baseView, {

        _create: function() {
            var o = this.options,
                e = this.element,
                self = this;

            // Chain up to base class _create()
            $.rib.baseView.prototype._create.call(this);

            this.element
                .append('<div/>')
                .append('<div/>')
                .children(':first')
                    .addClass('panel-section-header')
                    .append('<span class="title">Pages</span>')
                    .append('<span class= "tool"></span>')
                    .children(':last')
                        .append('<a id="addPage">Add Page</a>')
                        .append('<span class="divider">&nbsp;</span>')
                        .append('<a id="copyPage">Duplicate Page</a>')
                    .end()
                .end()
                .children().last()
                    .attr({id: 'pages-wrap'})
                    .addClass('panel-section-contents')
                    .append('<div/>')
                    .children().first()
                        .addClass('page-arrow left')
                        .click( function(e) {
                            self._scrollPage(false);
                            e.stopPropagation();
                            return false;
                         })
                    .end().end()
                    .append('<div/>')
                    .append('<div/>')
                    .children().eq(2)
                        .addClass('page-arrow right')
                        .click( function(e) {
                            self._scrollPage(true);
                            e.stopPropagation();
                            return false;
                         })
                    .end().end()
                .end();
            this.element.find('#pages-wrap')
                .children().eq(1)
                    .attr({id:'box'})
                    .addClass('pages-box')
                    .append('<div/>')
                    .children().first()
                        .addClass('allwidth')
                        .append('<div/>')
                        .children().first()
                            .attr({id:'pages'})
                        .end().end()
                    .end().end()
                .end().end();
            this.element.find('#copyPage').click(this, this._copyPageHandler);
            this.element.find('#addPage').click(this, this._addPageHandler);
            this.options.newPageDialog = $('#pageDialog');
            if (!this.options.newPageDialog.length) {
                this.options.newPageDialog = this._initNewPageDialog();
            }

            return this;
        },

        _setOption: function(key, value) {
            // Chain up to base class _setOptions()
            // FIXME: In jquery UI 1.9 and above, instead use
            //    this._super('_setOption', key, value)
            $.rib.baseView.prototype._setOption.apply(this, arguments);

            switch (key) {
                // Should this REALLY be done here, or plugin registration in
                // the "host"... using the functions mapped in widget options?
                case 'model':
                    this.refresh(null, this);
                    break;
                default:
                    break;
            }
        },

        /*
         * scroll page view
         * direction: boolean. if true, scroll right; false, scroll left.
         */
        _scrollPage: function(left, index) {
            var box = this.element.find('#box'),
                length = this.element.find('.pageIcon').outerWidth(true),
                scroller = this.element.find('#pages'),
                pageCount = scroller.children().length,
                visibleCount = (box.innerWidth() / length).toFixed(), pos,
                scrollLeft = box.scrollLeft();

            if (index === undefined && typeof(left) !== 'boolean') {
                index = parseInt(left,10);
                left = undefined;
            }

            if (index >= 0 && index < scroller.children().length ) {
                if (index*length+length >= scrollLeft + box.innerWidth()) {
                    box.animate({
                        scrollLeft: scrollLeft + index * length + length -
                                    box.innerWidth()});
                } else if (index*length < scrollLeft) {
                    box.animate({scrollLeft: index*length});
                }
                return;
            }

            if(left){
                if (scrollLeft < (pageCount-visibleCount)*length){
                    box.animate({scrollLeft: scrollLeft + length});
                }
            } else {
                if(scrollLeft !== 0){
                    box.animate({scrollLeft: scrollLeft - length});
                }
            }
        },

        refresh: function(event, widget) {
            var pageWidgets,
                model = this.options.model,
                pages = $('#pages', this.element);

            if (model) {
                pageWidgets = model.getDesignRoot().getChildren();
                pages.empty();

                for ( var i = 0; i < pageWidgets.length; i ++) {
                    $('<div>'+(i+1)+'</div>')
                        .addClass('pageIcon')
                        .toggleClass('ui-selected',
                            pageWidgets[i] === model.getActivePage())
                        .data('page', pageWidgets[i])
                        .click(function (e) {
                            model.setActivePage($(this).data('page'));
                        })
                        .appendTo(pages);
                }
            }
            if (!event || !event.name ||
                event.name !== 'activePageChanged'|| !event.page) {
                return;
            } else {<commit_msg>[Page View] reduce click event bind call of pageIcon<commit_after>/*
 * Rapid Interface Builder (RIB) - A simple WYSIWYG HTML5 app creator
 * Copyright (c) 2011-2012, Intel Corporation.
 *
 * This program is licensed under the terms and conditions of the
 * Apache License, version 2.0.  The full text of the Apache License is at
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 */
"use strict";

// Page view widget

(function($, undefined) {

    $.widget('rib.pageView', $.rib.baseView, {

        _create: function() {
            var o = this.options,
                e = this.element,
                self = this;

            // Chain up to base class _create()
            $.rib.baseView.prototype._create.call(this);

            this.element
                .append('<div/>')
                .append('<div/>')
                .children(':first')
                    .addClass('panel-section-header')
                    .append('<span class="title">Pages</span>')
                    .append('<span class= "tool"></span>')
                    .children(':last')
                        .append('<a id="addPage">Add Page</a>')
                        .append('<span class="divider">&nbsp;</span>')
                        .append('<a id="copyPage">Duplicate Page</a>')
                    .end()
                .end()
                .children().last()
                    .attr({id: 'pages-wrap'})
                    .addClass('panel-section-contents')
                    .append('<div/>')
                    .children().first()
                        .addClass('page-arrow left')
                        .click( function(e) {
                            self._scrollPage(false);
                            e.stopPropagation();
                            return false;
                         })
                    .end().end()
                    .append('<div/>')
                    .append('<div/>')
                    .children().eq(2)
                        .addClass('page-arrow right')
                        .click( function(e) {
                            self._scrollPage(true);
                            e.stopPropagation();
                            return false;
                         })
                    .end().end()
                .end();
            this.element.find('#pages-wrap')
                .children().eq(1)
                    .attr({id:'box'})
                    .addClass('pages-box')
                    .append('<div/>')
                    .children().first()
                        .addClass('allwidth')
                        .append('<div/>')
                        .children().first()
                            .attr({id:'pages'})
                        .end().end()
                    .end().end()
                .end().end();
            this.element.find('#copyPage').click(this, this._copyPageHandler);
            this.element.find('#addPage').click(this, this._addPageHandler);
            this.options.newPageDialog = $('#pageDialog');
            if (!this.options.newPageDialog.length) {
                this.options.newPageDialog = this._initNewPageDialog();
            }

            return this;
        },

        _setOption: function(key, value) {
            // Chain up to base class _setOptions()
            // FIXME: In jquery UI 1.9 and above, instead use
            //    this._super('_setOption', key, value)
            $.rib.baseView.prototype._setOption.apply(this, arguments);

            switch (key) {
                // Should this REALLY be done here, or plugin registration in
                // the "host"... using the functions mapped in widget options?
                case 'model':
                    this.refresh(null, this);
                    break;
                default:
                    break;
            }
        },

        /*
         * scroll page view
         * direction: boolean. if true, scroll right; false, scroll left.
         */
        _scrollPage: function(left, index) {
            var box = this.element.find('#box'),
                length = this.element.find('.pageIcon').outerWidth(true),
                scroller = this.element.find('#pages'),
                pageCount = scroller.children().length,
                visibleCount = (box.innerWidth() / length).toFixed(), pos,
                scrollLeft = box.scrollLeft();

            if (index === undefined && typeof(left) !== 'boolean') {
                index = parseInt(left,10);
                left = undefined;
            }

            if (index >= 0 && index < scroller.children().length ) {
                if (index*length+length >= scrollLeft + box.innerWidth()) {
                    box.animate({
                        scrollLeft: scrollLeft + index * length + length -
                                    box.innerWidth()});
                } else if (index*length < scrollLeft) {
                    box.animate({scrollLeft: index*length});
                }
                return;
            }

            if(left){
                if (scrollLeft < (pageCount-visibleCount)*length){
                    box.animate({scrollLeft: scrollLeft + length});
                }
            } else {
                if(scrollLeft !== 0){
                    box.animate({scrollLeft: scrollLeft - length});
                }
            }
        },

        refresh: function(event, widget) {
            var pageWidgets,
                model = this.options.model,
                pages = $('#pages', this.element);

            if (model) {
                pageWidgets = model.getDesignRoot().getChildren();
                pages.empty();

                for ( var i = 0; i < pageWidgets.length; i ++) {
                    $('<div>'+(i+1)+'</div>')
                        .addClass('pageIcon')
                        .toggleClass('ui-selected',
                            pageWidgets[i] === model.getActivePage())
                        .data('page', pageWidgets[i])
                        .appendTo(pages);
                }

                pages.delegate('div', 'click', function(){
                        model.setActivePage($(this).data('page'));
                    });
            }
            if (!event || !event.name ||
                event.name !== 'activePageChanged'|| !event.page) {
                return;
            } else {
{'fraction_non_alphanumeric': 0.1324988190836089, 'fraction_numerical': 0.0036214769327664936, 'mean_word_length': 1.1171666666666666, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3908402', 'n_tokens_mistral': 3160, 'n_tokens_neox': 2918, 'n_words': 623}