<commit_before>var $ = require('tinyselector');
var types = require('./types.js');
var Items = require('./items.js');

var win = window,
    doc = document,
    editmode = false,
    data = {},
    uploader,
    fonts = new Items(),
    colors = new Items();

var context = {
  scan: function(fn, all) {
    context.parts.apply(context, arguments);
    return context;
  },
  parts: function(fn, all) {
    if( fn === true ) all = fn;
    
    return $(all ? '.ff' : '[ff-id], [ff], [ff-type]').reverse().each(function(i, el) {
      var id = el.getAttribute('ff-id');
      var type = el.getAttribute('ff-type') || el.getAttribute('ff') || 'default';
      var part = el._ff;
      
      if( !part ) {
        var Type = types.get(type);
        if( !Type ) return console.warn('[ff] not found type: ' + type);
        part = el._ff = new Type(el);
        id && part.data(data[id]);
      }
      
      part.id = id;
      typeof fn == 'function' && fn.call(context, part);
    }).slice();
  },
  data: function(newdata) {
    if( !arguments.length ) {
      newdata = {};
      context.parts(function(part) {
        if( part.id ) newdata[part.id] = part.data();
      });
      return newdata;
    }
    
    data = newdata || {};
    context.parts(function(part) {
      part.id && part.data(data[part.id]);
    });
    
    context.fire('ff-data', {
      data: newdata
    });
    
    return context;
  },
  part: function(id) {
    var el = $('[ff-id="' + id + '"]');
    return el[0] && el[0]._ff;
  },
  partof: function(node) {
    var found = $(node).parent(function() {
      return this._ff;
    }, true)[0];
    return found && found._ff;
  },
  editmode: function(b) {
    if( !arguments.length ) return editmode;
    if( editmode === !!b ) return context;
    
    editmode = !!b;
    
    context.parts(function(part) {
      part.editmode(editmode);
    }, true);
    
    context.fire('ff-modechange', {
      editmode: editmode
    });
    
    return context;
  },
  
  // event
  fire: function(type, detail, cancellable, bubble) {
    return !!$(doc).fire(type, detail, cancellable, bubble)[0];
  },
  on: function(type, fn) {
    fn._wrapper = function() {
      return fn.apply(context, arguments);
    };
    
    $(doc).on(type, fn._wrapper);
    return this;
  },
  once: function(type, fn) {
    fn._wrapper = function() {<commit_msg>add context.partsof<commit_after>var $ = require('tinyselector');
var types = require('./types.js');
var Items = require('./items.js');

var win = window,
    doc = document,
    editmode = false,
    data = {},
    uploader,
    fonts = new Items(),
    colors = new Items();

var context = {
  scan: function(fn, all) {
    context.parts.apply(context, arguments);
    return context;
  },
  parts: function(fn, all) {
    if( fn === true ) all = fn;
    
    return $(all ? '.ff' : '[ff-id], [ff], [ff-type]').reverse().each(function(i, el) {
      var id = el.getAttribute('ff-id');
      var type = el.getAttribute('ff-type') || el.getAttribute('ff') || 'default';
      var part = el._ff;
      
      if( !part ) {
        var Type = types.get(type);
        if( !Type ) return console.warn('[ff] not found type: ' + type);
        part = el._ff = new Type(el);
        id && part.data(data[id]);
      }
      
      part.id = id;
      typeof fn == 'function' && fn.call(context, part);
    }).slice();
  },
  data: function(newdata) {
    if( !arguments.length ) {
      newdata = {};
      context.parts(function(part) {
        if( part.id ) newdata[part.id] = part.data();
      });
      return newdata;
    }
    
    data = newdata || {};
    context.parts(function(part) {
      part.id && part.data(data[part.id]);
    });
    
    context.fire('ff-data', {
      data: newdata
    });
    
    return context;
  },
  part: function(id) {
    var el = $('[ff-id="' + id + '"]');
    return el[0] && el[0]._ff;
  },
  partof: function(node) {
    var found = $(node).parent(function() {
      return this._ff;
    }, true)[0];
    return found && found._ff;
  },
  partsof: function(node) {
    var parents = [];
    $(node).parent(function() {
      var part = this._ff;
      if( part ) parents.push(part);
    }, true);
    return parents;
  },
  editmode: function(b) {
    if( !arguments.length ) return editmode;
    if( editmode === !!b ) return context;
    
    editmode = !!b;
    
    context.parts(function(part) {
      part.editmode(editmode);
    }, true);
    
    context.fire('ff-modechange', {
      editmode: editmode
    });
    
    return context;
  },
  
  // event
  fire: function(type, detail, cancellable, bubble) {
    return !!$(doc).fire(type, detail, cancellable, bubble)[0];
  },
  on: function(type, fn) {
    fn._wrapper = function() {
      return fn.apply(context, arguments);
    };
    
    $(doc).on(type, fn._wrapper);
    return this;
  },
  once: function(type, fn) {
    fn._wrapper = function() {
{'fraction_non_alphanumeric': 0.1833502538071066, 'fraction_numerical': 0.0016243654822335025, 'mean_word_length': 2.2927807486631018, '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': '4351620', 'n_tokens_mistral': 1667, 'n_tokens_neox': 1660, 'n_words': 367}