jQuery.jfiler

Learning the source code jQuery.jfiler by rewriting it

HTML

<input type="file" class="filer">

JavaScript

/*!
 * jQuery.filer
 * Copyright (c) 2016 CreativeDream
 * Website: https://github.com/CreativeDream/jquery.filer
 * Version: 1.3 (14-Sep-2016)
 * Requires: jQuery v1.7.1 or later
 * License: Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
 *
 * Rewritten, commented and expanded for learning purpose
 * #ToBeFinished
 */
 
/*
Short named variables:
q (now param): the only parameter for $.filer()
t (now key), r (now val): key, val on $.each(key, val) which loops on every selectors which use filer()
s (now elem_jfiler): jQuery object, $(r)
b (now class_jfiler): string, css class name used by jQuery.filer
p: $()
o: $()
l: $()
sl: []
n_f (now param_pre_obj)
n (now param_obj)
*/

(function(){
  "use strict";
  $.fn.filer = function(param) {
    return this.each(function(key, val) {
      var elem_jfiler = $(val),
        class_jfiler = '.jFiler',
        p = $(),
        o = $(),
        l = $(),
        sl = [],
        param_pre_obj = $.isFunction(param) ? param(elem_jfiler, $.fn.filer.defaults) : param,
        param_obj = param_pre_obj && $.isPlainObject(param_pre_obj) ? $.extend(true, {}, $.fn.filer.defaults, param_pre_obj) : $.fn.filer.defaults,
        jfiler = {
          init: function() {
            elem_jfiler.wrap('<div class="jFiler"></div>');
            jfiler._set('props');
            //@TODO
          },
          _bindInput: function() {
            //?o
            if (param_obj.changeInput && o.length > 0) {
              //@TODO
            }
          },
          _set: function(element, value) {
            switch (element) {
              case 'props':
                if (!elem_jfiler.prop('jFiler')) {
                  elem_jfiler.prop('jFiler', {
                    options: param_obj,
                    listEl: l,
                    boxEl: p
                    //@TODO
                  });
                }
                break;
            }
          }
        };
      
      jfiler.init();
      //...