<commit_before>/*jshint jquery: true, browser: true*/
/*global _: false, Backbone: false, ActionQueue: true, LogType: true*/
(function(L) {
    'use strict';

    L.views.NoteView = Backbone.View.extend({
        tagName: 'li',
        className: 'note hbox justified_box',
        initialize: function(options) {
            var that = this;
            $(window).one('beforeunload', function() {
                that.undelegateEvents();
                that.stopListening();
            });
            this.template = L.templates["note"];
            this.listenTo(this.model, 'change:contents', _.mask(this.updateContents, 2));
            this.listenTo(this.model, 'change:meta', _.mask(this.updateMeta, 2));
        },
        remove : function(options) {
            if (this._rendered) {
                var el = this.$el;
                if (options && options.animate) {
                    el.stop().fadeOut({queue: false}, 200).slideUp(300, function() {
                        el.remove();
                    });
                } else {
                    el.remove();
                }
            }
        },
        isVisible: function() {
            // This assumes that el having a parent means that it is visible. Much
            // faster than checking $el.is(':visible') and speed is important here.
            return this.el && this.el.parentNode;
        },
        render: function(options) {
            var that = this;
            this.$el.on('DOMNodeRemoved', function(evt) {
              if (evt.srcElement === that.el) {
                that.cleanupEditor()
              }
            });
            this.$el.attr("id", "note-"+this.model.id);

            if (this._rendered) {
                this.cleanupEditor();
                this.undelegateEvents();
                this.delegateEvents();
            } else {
                this._rendered = true;

                this.updateContents(options);
                this.updateMeta();
            }

            return this;
        },
        cleanupEditor: function() {
            if (this.editor) {
                this.editor.remove();
                delete this.editor;
            }
        },
        updateMeta: function(options) {
            this.$el.attr('class', this.className);
            if (this.model.get('meta').pinned) {
                this.$el.addClass('pinned');
            }
        },
        updateContents: function(options) {
            this.$el.html(this.template(this.model.toJSON()));
        },
        events: {
            'click .close-btn': 'onRemoveClicked',
            'click .contents': 'onClick',
            'click .contents a': 'onLinkOpen',
            'keyup .contents': 'onKeyUp',
            'blur .editor': 'onBlur'
        },
        getNoteText: function() {
            return this.$('.contents').html();
        },
        onLinkOpen: function(event) {
          this.model.trigger('user:open-bookmark', this.model, this, event.target.href);
        },
        onRemoveClicked: function() {
          L.notebook.trashNote(this.model);
          return false;
        },
        expand: function() {
            this.$el.css('height', 'auto');
        },
        collapse: function() {
            this.$el.css('height', '');
        },
        openEditor: function() {
            // I know that this is unreadable. But it makes a point.
            // (it's complicated)

            var $contentsEl = this.$('.contents'),
                $editorEl = this.$('.editor-container');
            if (!this.editor) {
              this.editor = new ListIt.views.Editor({
                text: $contentsEl.html()
              });
              $editorEl.html(this.editor.render().el);
            }
            $editorEl.show();
            $contentsEl.hide();
            this.editor.focus();
            this.model.trigger('user:edit', this.model, this);
        },
        onBlur: function() {
            var that = this;
            if (!this.editor || this.editor.isShowingDialog()) {
                return;
            }
            _.defer(function() {
                var focusedEditor = $(document.activeElement).closest('.editor').get(0),
                    myEditor = that.$('.editor').get(0);

                if (focusedEditor !== myEditor) {
                    that.closeEditor();
                }
            });
        },
        closeEditor: function() {
            this.model.changeContents(this.editor.getText(), window);
            this.model.trigger('user:save', this.model, this);
            this.collapse();
            this.$('.editor-container').hide();
            this.$('.contents').show();
        },
        onClick: function(e) {
            if (!e.target.href) {
                this.expand();
                this.openEditor();
            }
        },
        /**
        * Scroll List so note selected with tab is at top.
        */
        onKeyUp: function(event) {
            if (event.keyCode === 9) { // TAB
                event.target.scrollIntoView();
                $('#notes')[0].scrollTop -= 4;
            }
        },
        openLink: function() {
            window.debug('READY');
            L.openLinkTimer = setTimeout(function () {
                window.debug('FIRE');
                window.open(this.model.get('meta').fullURL);
            }, 50);
        }
    });

    L.views.NoteCollectionView = Backbone.View.extend({
        defaults: {
            noteHeight: '1.3em', //L.base.oneLineHeight, //'1.2em',
            lastFocusedNote: null
        },
        initialize: function() {
            var that = this;
            this.subViews = {}; // Note views
            this.renderNext = 0;
            this.listenTo(this.collection, 'add', _.mask(this.addNote, 0, 2));
            this.listenTo(this.collection, 'remove', function(note, col, options) {
              that.removeNote(note, _.defaults({}, options));
            });
            this.listenTo(this.collection, 'reset', _.mask(this.reset, 1));
            this.listenTo(this.collection, 'sort', _.mask(this.sort));
            this.listenTo(L.preferences, 'change:shrinkNotes', this.updateNoteShrinkState);
            $(window).one('beforeunload', function() {<commit_msg>Cancel note edit on escape.<commit_after>/*jshint jquery: true, browser: true*/
/*global _: false, Backbone: false, ActionQueue: true, LogType: true*/
(function(L) {
    'use strict';

    L.views.NoteView = Backbone.View.extend({
        tagName: 'li',
        className: 'note hbox justified_box',
        initialize: function(options) {
            var that = this;
            $(window).one('beforeunload', function() {
                that.undelegateEvents();
                that.stopListening();
            });
            this.template = L.templates["note"];
            this.listenTo(this.model, 'change:contents', _.mask(this.updateContents, 2));
            this.listenTo(this.model, 'change:meta', _.mask(this.updateMeta, 2));
        },
        remove : function(options) {
            if (this._rendered) {
                var el = this.$el;
                if (options && options.animate) {
                    el.stop().fadeOut({queue: false}, 200).slideUp(300, function() {
                        el.remove();
                    });
                } else {
                    el.remove();
                }
            }
        },
        isVisible: function() {
            // This assumes that el having a parent means that it is visible. Much
            // faster than checking $el.is(':visible') and speed is important here.
            return this.el && this.el.parentNode;
        },
        render: function(options) {
            var that = this;
            this.$el.on('DOMNodeRemovedFromDocument', function(evt) {
              if (evt.srcElement === that.el) {
                that.cleanupEditor()
              }
            });
            this.$el.attr("id", "note-"+this.model.id);

            if (this._rendered) {
                this.cleanupEditor();
                this.undelegateEvents();
                this.delegateEvents();
            } else {
                this._rendered = true;

                this.updateContents(options);
                this.updateMeta();
            }

            return this;
        },
        cleanupEditor: function() {
            if (this.editor) {
                this.editor.remove();
                delete this.editor;
            }
        },
        updateMeta: function(options) {
            this.$el.attr('class', this.className);
            if (this.model.get('meta').pinned) {
                this.$el.addClass('pinned');
            }
        },
        updateContents: function(options) {
            this.$el.html(this.template(this.model.toJSON()));
        },
        events: {
            'click   .close-btn':   'onRemoveClicked',
            'click   .contents':    'onClick',
            'click   .contents a':  'onLinkOpen',
            'keyup   .contents':    'onKeyUp',
            'blur    .editor':      'onBlur',
            'keydown .editor':      'onKeyDown'
        },
        getNoteText: function() {
            return this.$('.contents').html();
        },
        onLinkOpen: function(event) {
          this.model.trigger('user:open-bookmark', this.model, this, event.target.href);
        },
        onRemoveClicked: function() {
          L.notebook.trashNote(this.model);
          return false;
        },
        expand: function() {
            this.$el.css('height', 'auto');
        },
        collapse: function() {
            this.$el.css('height', '');
        },
        openEditor: function() {
            // I know that this is unreadable. But it makes a point.
            // (it's complicated)

            var $contentsEl = this.$('.contents'),
                $editorEl = this.$('.editor-container');
            if (!this.editor) {
              this.editor = new ListIt.views.Editor({
                text: $contentsEl.html()
              });
              $editorEl.html(this.editor.render().el);
            }
            $editorEl.show();
            $contentsEl.hide();
            this.editor.focus();
            this.model.trigger('user:edit', this.model, this);
        },
        onBlur: function() {
            var that = this;
            if (!this.editor || this.editor.isShowingDialog()) {
                return;
            }
            _.defer(function() {
                var focusedEditor = $(document.activeElement).closest('.editor').get(0),
                    myEditor = that.$('.editor').get(0);

                if (focusedEditor !== myEditor) {
                    that.closeEditor();
                }
            });
        },
        closeEditor: function() {
            this.model.changeContents(this.editor.getText(), window);
            this.model.trigger('user:save', this.model, this);
            this.collapse();
            this.$('.editor-container').hide();
            this.$('.contents').show();
        },
        onClick: function(e) {
            if (!e.target.href) {
                this.expand();
                this.openEditor();
            }
        },
        /**
        * Scroll List so note selected with tab is at top.
        */
        onKeyUp: function(event) {
            if (event.keyCode === KeyCode.TAB) {
                event.target.scrollIntoView();
                $('#notes')[0].scrollTop -= 4;
            }
        },
        onKeyDown: function(event) {
          if (event.keyCode === KeyCode.ESC && this.editor && !this.editor.isShowingDialog()) {
            this.closeEditor();
          }
        },
        openLink: function() {
            window.debug('READY');
            L.openLinkTimer = setTimeout(function () {
                window.debug('FIRE');
                window.open(this.model.get('meta').fullURL);
            }, 50);
        }
    });

    L.views.NoteCollectionView = Backbone.View.extend({
        defaults: {
            noteHeight: '1.3em', //L.base.oneLineHeight, //'1.2em',
            lastFocusedNote: null
        },
        initialize: function() {
            var that = this;
            this.subViews = {}; // Note views
            this.renderNext = 0;
            this.listenTo(this.collection, 'add', _.mask(this.addNote, 0, 2));
            this.listenTo(this.collection, 'remove', function(note, col, options) {
              that.removeNote(note, _.defaults({}, options));
            });
            this.listenTo(this.collection, 'reset', _.mask(this.reset, 1));
            this.listenTo(this.collection, 'sort', _.mask(this.sort));
            this.listenTo(L.preferences, 'change:shrinkNotes', this.updateNoteShrinkState);
            $(window).one('beforeunload', function() {
{'fraction_non_alphanumeric': 0.14507691106426174, 'fraction_numerical': 0.0035137034434293743, 'mean_word_length': 1.442410373760488, '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': '6235673', 'n_tokens_mistral': 3465, 'n_tokens_neox': 3333, 'n_words': 630}