/**
 * @fileoverview View element constructor
 * @author Kyumin Sim
 * @version 0.2
 */
'use strict';

/**
 * Function for construct html dom element.
 * @function
 * @param {string} tag or html to construct dom element.
 * @param {?object} options include id, classes, parent etc.
 */
Entry.Dom = function(tag, options) {
    var tagRegex = /<(\w+)>/,
        dom;

    if (tag instanceof HTMLElement) dom = $(tag);
    else if (tag instanceof jQuery) dom = tag;
    else if (tagRegex.test(tag)) dom = $(tag);
    else dom = $('<' + tag + '></' + tag + '>');

    if (options === undefined) return dom;
    if (options.id) dom.attr('id', options.id);
    if (options.class) dom.addClass(options.class);
    if (options.classes)
        options.classes.map(function(className) {
            dom.addClass(className);
        });
    if (options.src) dom.attr('src', options.src);
    if (options.parent) options.parent.append(dom);

    dom.bindOnClick = function() {
        var hasChild = false;
        var child;
        var func;

        var handler = function(e) {
            e.stopImmediatePropagation();
            if (e.handled) return;
            e.handled = true;
            func.call(this, e);
        };

        if (arguments.length > 1) {
            func =
                arguments[1] instanceof Function ? arguments[1] : function() {};
            child = typeof arguments[0] === 'string' ? arguments[0] : '';
        } else {
            func =
                arguments[0] instanceof Function ? arguments[0] : function() {};
        }

        if (child) {
            $(this).on('click tab', child, handler);
        } else {
            $(this).on('click tab', handler);
        }
        return this;
    };

    return dom;
};

@@ -320,19 +320,21 @@
 ) %7B%0A    
-var
+const
  tagRege
@@ -350,17 +350,17 @@
 +)%3E/
-,
+;
 %0A    
-   
+let
  dom
@@ -397,16 +397,26 @@
 Element)
+ %7B%0A       
  dom = $
@@ -421,24 +421,26 @@
  $(tag);%0A   
+ %7D
  else if (ta
@@ -459,16 +459,26 @@
  jQuery)
+ %7B%0A       
  dom = t
@@ -480,24 +480,26 @@
 m = tag;%0A   
+ %7D
  else if (ta
@@ -515,16 +515,26 @@
 st(tag))
+ %7B%0A       
  dom = $
@@ -547,53 +547,61 @@
 %0A   
+ %7D
  else 
-dom = $('%3C' + tag + '%3E%3C/' + tag + '%3E');
+%7B%0A        dom = $(%60%3C$%7Btag%7D%3E%3C/$%7Btag%7D%3E%60);%0A    %7D
 %0A%0A  
@@ -628,16 +628,26 @@
 defined)
+ %7B%0A       
  return 
@@ -651,16 +651,22 @@
 rn dom;%0A
+    %7D%0A
     if (
@@ -676,16 +676,26 @@
 ions.id)
+ %7B%0A       
  dom.att
@@ -715,16 +715,22 @@
 ns.id);%0A
+    %7D%0A
     if (
@@ -743,16 +743,26 @@
 s.class)
+ %7B%0A       
  dom.add
@@ -783,16 +783,22 @@
 class);%0A
+    %7D%0A
     if (
@@ -813,16 +813,18 @@
 classes)
+ %7B
 %0A       
@@ -915,16 +915,22 @@
     %7D);%0A
+    %7D%0A
     if (
@@ -941,16 +941,26 @@
 ons.src)
+ %7B%0A       
  dom.att
@@ -982,16 +982,22 @@
 s.src);%0A
+    %7D%0A
     if (
@@ -1011,16 +1011,26 @@
 .parent)
+ %7B%0A       
  options
@@ -1049,16 +1049,22 @@
 nd(dom);
+%0A    %7D
 %0A%0A    do
@@ -1104,41 +1104,11 @@
     
-var hasChild = false;%0A        var
+let
  chi
@@ -1119,19 +1119,19 @@
         
-var
+let
  func;%0A%0A
@@ -1142,11 +1142,13 @@
     
-var
+const
  han
@@ -1241,15 +1241,47 @@
 ed) 
-return;
+%7B%0A                return;%0A            %7D
 %0A   
@@ -1405,32 +1405,16 @@
   func =
-%0A               
  argumen
@@ -1580,32 +1580,16 @@
   func =
-%0A               
  argumen

edit dom.js code formatting