<commit_before>var Stylesheet = Backbone.Model.extend({
    initialize: function() {
        // Set default values.
        if (!this.get('data')) {
            this.set({'data': ''});
        }
    }
});

var StylesheetList = Backbone.Collection.extend({
    model: Stylesheet
});

var StylesheetListView = Backbone.View.extend({
    initialize: function() {
        _.bindAll(this, 'render');
        this.collection.bind('all', this.render);
        this.render();
        /*
        @TODO: bind re-render to project events.
        */
    },
    render: function() {
        var self = this;
        $(this.el).html(ich.StylesheetListView());
        this.collection.each(function(stylesheet) {
            var stylesheetTab = new StylesheetTabView({
                model: stylesheet,
                list: self
            });
            $('.stylesheets', self.el).append(stylesheetTab.el);
        });
        $('.stylesheets', self.el).sortable({
          axis: 'x'
          // @TODO: proper event.
          // change: TileMill.project.changed
        });

        return this;
    },
    events: {
        'click .tab-add': 'add'
    },
    add: function() {
        new StylesheetPopupView({collection: this.collection});
        return false;
    }
});

var StylesheetPopupView = PopupView.extend({
    events: _.extend(PopupView.prototype.events, {
        'click input.submit': 'submit',
    }),
    initialize: function(params) {
        this.options.title = 'Add stylesheet';
        this.options.content = ich.StylesheetPopupView({}, true);
        this.render();
    },
    submit: function() {
        var id = $('input.text', this.el).val();
        var stylesheet = new Stylesheet({id: id});
        this.collection.add(stylesheet);
        this.remove();
        return false;
    }
});

var StylesheetTabView = Backbone.View.extend({
    tagName: 'a',
    className: 'tab',
    initialize: function (params) {
        _.bindAll(this, 'render');
        this.render();
        this.list = params.list;
        this.input = $('textarea', this.el);
        this.input.val(this.model.get('data'));
        this.codemirror = false;
    },
    render: function () {
        $(this.el).html(ich.StylesheetTabView({ id: this.model.get('id') }));
        return this;
    },
    events: {
        'click .name': 'activate',
        'click .tab-delete': 'delete',
    },
    activate: function() {
        $('.stylesheets a.tab', this.list.el).removeClass('active');
        $('#editor', this.list.el).append(this.input);
        $(this.el).addClass('active');
        if (!this.codemirror) {
            return;
            this.codemirror = CodeMirror.fromTextArea('code', {
                height: '100%',
                stylesheet: 'css/code.css',
                path: 'js/codemirror/js/',
                parserfile: 'parsemss.js',
                parserConfig: window.data.reference,
                /*
                onChange: function() {
                    TileMill.colors.reload(stylesheets);
                    TileMill.project.changed();
                 },
                initCallback: function(cm) {
                    TileMill.colors.reload(stylesheets);
                    TileMill.mirror.grabKeys(
                        // callback
                        function() { },
                        // filter function
                        function(code) {
                            if (code == 19) {
                                $('div#header a.save').trigger('click');
                                return true;
                            } else {
                                return false;
                            }
                        }
                    );
                }
                */
            });
        }

        /*
          var data;
          if (!$('#tabs .active', stylesheets).size() || update === true) {
            if (!update) {
              $('#tabs a.active').removeClass('active');
              stylesheet.addClass('active');

              data = $('input', stylesheet).val();
              $('#code').val(data);
              $.getJSON('js/data/reference.json', {}, function(data) {
                TileMill.mirror = CodeMirror.fromTextArea('code', {
                  height: '100%',
                  parserfile: 'parsemss.js',
                  parserConfig: data,
                  stylesheet: 'css/code.css',
                  path: 'js/codemirror/js/',
                  onChange: function() {
                    TileMill.colors.reload(stylesheets);
                    TileMill.project.changed();
                  },
                  initCallback: function(cm) {
                    TileMill.colors.reload(stylesheets);
                    TileMill.mirror.grabKeys(
                      // callback
                      function() { },
                      // filter function
                      function(code) {
                        if (code == 19) {
                          $('div#header a.save').trigger('click');
                          return true;
                        } else {
                          return false;
                        }
                      }
                    );
                  }
                });
              });
            } else {
              $('#tabs a.active input').val(TileMill.mirror.getCode());
              $('#tabs a.active').removeClass('active');
              stylesheet.addClass('active');

              data = $('input', stylesheet).val();

              var linenum = TileMill.mirror.lineNumber(TileMill.mirror.cursorLine());
              TileMill.mirror.setCode(data);
              TileMill.colors.reload(stylesheets);
              TileMill.mirror.jumpToLine(TileMill.mirror.nthLine(linenum));
            }
          }
        */
    },
    delete: function() {
        alert('@TODO delete');
        return false;
    }
});

/**
 * Init stylesheet editor.
TileMill.stylesheet.init = function() {
  var stylesheets = $(ich.stylesheets({}));

  // Add stylesheets in order.
  var queue = new TileMill.queue();

  TileMill.stylesheet.initFonts();

  var s = TileMill.mml.parseMML(TileMill.data.mml).stylesheets;
  for (var i in s) {
    var src = s[i];
    queue.add(function(src, stylesheets, next) {
      TileMill.stylesheet.add({ src: src }, stylesheets, next);<commit_msg>Remove commented code, implement simple stylesheet removal.<commit_after>var Stylesheet = Backbone.Model.extend({
    initialize: function() {
        // Set default values.
        if (!this.get('data')) {
            this.set({'data': ''});
        }
    }
});

var StylesheetList = Backbone.Collection.extend({
    model: Stylesheet
});

var StylesheetListView = Backbone.View.extend({
    initialize: function() {
        _.bindAll(this, 'render');
        this.collection.bind('all', this.render);
        this.render();
        /*
        @TODO: bind re-render to project events.
        */
    },
    render: function() {
        var self = this;
        $(this.el).html(ich.StylesheetListView());
        this.collection.each(function(stylesheet) {
            var stylesheetTab = new StylesheetTabView({
                model: stylesheet,
                list: self
            });
            $('.stylesheets', self.el).append(stylesheetTab.el);
        });
        $('.stylesheets', self.el).sortable({
          axis: 'x'
          // @TODO: proper event.
          // change: TileMill.project.changed
        });

        return this;
    },
    events: {
        'click .tab-add': 'add'
    },
    add: function() {
        new StylesheetPopupView({collection: this.collection});
        return false;
    }
});

var StylesheetPopupView = PopupView.extend({
    events: _.extend(PopupView.prototype.events, {
        'click input.submit': 'submit',
    }),
    initialize: function(params) {
        this.options.title = 'Add stylesheet';
        this.options.content = ich.StylesheetPopupView({}, true);
        this.render();
    },
    submit: function() {
        var id = $('input.text', this.el).val();
        var stylesheet = new Stylesheet({id: id});
        this.collection.add(stylesheet);
        this.remove();
        return false;
    }
});

var StylesheetTabView = Backbone.View.extend({
    tagName: 'a',
    className: 'tab',
    initialize: function (params) {
        _.bindAll(this, 'render');
        this.render();
        this.list = params.list;
        this.input = $('textarea', this.el);
        this.input.val(this.model.get('data'));
        this.codemirror = false;
    },
    render: function () {
        $(this.el).html(ich.StylesheetTabView({ id: this.model.get('id') }));
        return this;
    },
    events: {
        'click .name': 'activate',
        'click .tab-delete': 'delete',
    },
    activate: function() {
        $('.stylesheets a.tab', this.list.el).removeClass('active');
        $('#editor', this.list.el).append(this.input);
        $(this.el).addClass('active');
        if (!this.codemirror) {
            return;
            this.codemirror = CodeMirror.fromTextArea('code', {
                height: '100%',
                stylesheet: 'css/code.css',
                path: 'js/codemirror/js/',
                parserfile: 'parsemss.js',
                parserConfig: window.data.reference,
            });
        }
    },
    delete: function() {
        window.app.loading();
        if (confirm('Are you sure you want to delete this stylesheet?')) {
            this.list.collection.remove(this.model);
            this.remove();
            window.app.done();
        }
        else {
            window.app.done();
        }
        return false;
    }
});

/**
 * Init stylesheet editor.
TileMill.stylesheet.init = function() {
  var stylesheets = $(ich.stylesheets({}));

  // Add stylesheets in order.
  var queue = new TileMill.queue();

  TileMill.stylesheet.initFonts();

  var s = TileMill.mml.parseMML(TileMill.data.mml).stylesheets;
  for (var i in s) {
    var src = s[i];
    queue.add(function(src, stylesheets, next) {
      TileMill.stylesheet.add({ src: src }, stylesheets, next);
{'fraction_non_alphanumeric': 0.1460818137013307, 'fraction_numerical': 0.0012814194184327255, 'mean_word_length': 1.5744734838873382, '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': '2982991', 'n_tokens_mistral': 2878, 'n_tokens_neox': 2766, 'n_words': 518}