Total Complexity | 117 |
Complexity/F | 9.75 |
Lines of Code | 113 |
Function Count | 12 |
Duplicated Lines | 14 |
Ratio | 12.39 % |
Changes | 0 |
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like js/templates.js often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
1 | (function() { |
||
2 | var template = Handlebars.template, templates = Gallery.Templates = Gallery.Templates || {}; |
||
3 | templates['breadcrumb'] = template({"1":function(container,depth0,helpers,partials,data) { |
||
4 | var stack1, helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; |
||
5 | |||
6 | return " <div class=\"crumb " |
||
7 | + alias4(((helper = (helper = helpers.cssClass || (depth0 != null ? depth0.cssClass : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"cssClass","hash":{},"data":data}) : helper))) |
||
8 | + "\" data-dir=\"" |
||
9 | + alias4(((helper = (helper = helpers.dir || (depth0 != null ? depth0.dir : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"dir","hash":{},"data":data}) : helper))) |
||
10 | + "\">\n" |
||
11 | + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.link : depth0),{"name":"if","hash":{},"fn":container.program(2, data, 0),"inverse":container.program(8, data, 0),"data":data})) != null ? stack1 : "") |
||
12 | + " </div>\n"; |
||
13 | },"2":function(container,depth0,helpers,partials,data) { |
||
14 | var stack1, helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}); |
||
15 | |||
16 | return " <a href=\"" |
||
17 | + container.escapeExpression(((helper = (helper = helpers.link || (depth0 != null ? depth0.link : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(alias1,{"name":"link","hash":{},"data":data}) : helper))) |
||
18 | + "\">\n" |
||
19 | + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.img : depth0),{"name":"if","hash":{},"fn":container.program(3, data, 0),"inverse":container.program(6, data, 0),"data":data})) != null ? stack1 : "") |
||
20 | + " </a>\n"; |
||
21 | },"3":function(container,depth0,helpers,partials,data) { |
||
22 | var stack1; |
||
23 | |||
24 | return ((stack1 = helpers["with"].call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.img : depth0),{"name":"with","hash":{},"fn":container.program(4, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : ""); |
||
25 | },"4":function(container,depth0,helpers,partials,data) { |
||
26 | var helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; |
||
27 | |||
28 | return " <img title=\"" |
||
29 | + alias4(((helper = (helper = helpers.title || (depth0 != null ? depth0.title : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"title","hash":{},"data":data}) : helper))) |
||
30 | + "\" src=\"" |
||
31 | + alias4(((helper = (helper = helpers.imageSrc || (depth0 != null ? depth0.imageSrc : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"imageSrc","hash":{},"data":data}) : helper))) |
||
32 | + "\">\n"; |
||
33 | View Code Duplication | },"6":function(container,depth0,helpers,partials,data) { |
|
34 | var helper; |
||
35 | |||
36 | return " " |
||
37 | + container.escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),{"name":"name","hash":{},"data":data}) : helper))) |
||
38 | + "\n"; |
||
39 | View Code Duplication | },"8":function(container,depth0,helpers,partials,data) { |
|
40 | var helper; |
||
41 | |||
42 | return " <span>" |
||
43 | + container.escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),{"name":"name","hash":{},"data":data}) : helper))) |
||
44 | + "</span>\n"; |
||
45 | },"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) { |
||
46 | var stack1; |
||
47 | |||
48 | return ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.crumbs : depth0),{"name":"each","hash":{},"fn":container.program(1, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : ""); |
||
49 | },"useData":true}); |
||
50 | templates['galleryalbum'] = template({"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) { |
||
51 | var helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; |
||
52 | |||
53 | return "<a class=\"row-element\" style=\"width: " |
||
54 | + alias4(((helper = (helper = helpers.targetWidth || (depth0 != null ? depth0.targetWidth : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"targetWidth","hash":{},"data":data}) : helper))) |
||
55 | + "px; height: " |
||
56 | + alias4(((helper = (helper = helpers.targetHeight || (depth0 != null ? depth0.targetHeight : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"targetHeight","hash":{},"data":data}) : helper))) |
||
57 | + "px;\" data-width=\"" |
||
58 | + alias4(((helper = (helper = helpers.targetWidth || (depth0 != null ? depth0.targetWidth : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"targetWidth","hash":{},"data":data}) : helper))) |
||
59 | + "\" data-height=\"" |
||
60 | + alias4(((helper = (helper = helpers.targetHeight || (depth0 != null ? depth0.targetHeight : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"targetHeight","hash":{},"data":data}) : helper))) |
||
61 | + "\" href=\"" |
||
62 | + alias4(((helper = (helper = helpers.targetPath || (depth0 != null ? depth0.targetPath : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"targetPath","hash":{},"data":data}) : helper))) |
||
63 | + "\" data-dir=\"" |
||
64 | + alias4(((helper = (helper = helpers.dir || (depth0 != null ? depth0.dir : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"dir","hash":{},"data":data}) : helper))) |
||
65 | + "\" data-path=\"" |
||
66 | + alias4(((helper = (helper = helpers.path || (depth0 != null ? depth0.path : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"path","hash":{},"data":data}) : helper))) |
||
67 | + "\" data-permissions=\"" |
||
68 | + alias4(((helper = (helper = helpers.permissions || (depth0 != null ? depth0.permissions : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"permissions","hash":{},"data":data}) : helper))) |
||
69 | + "\" data-freespace=\"" |
||
70 | + alias4(((helper = (helper = helpers.freeSpace || (depth0 != null ? depth0.freeSpace : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"freeSpace","hash":{},"data":data}) : helper))) |
||
71 | + "\">\n <div class=\"album-loader loading\"></div>\n <span class=\"album-label\">\n <span class=\"title\">" |
||
72 | + alias4(((helper = (helper = helpers.label || (depth0 != null ? depth0.label : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"label","hash":{},"data":data}) : helper))) |
||
73 | + "</span>\n </span>\n <div class=\"album container\" style=\"width: " |
||
74 | + alias4(((helper = (helper = helpers.targetWidth || (depth0 != null ? depth0.targetWidth : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"targetWidth","hash":{},"data":data}) : helper))) |
||
75 | + "px; height: " |
||
76 | + alias4(((helper = (helper = helpers.targetHeight || (depth0 != null ? depth0.targetHeight : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"targetHeight","hash":{},"data":data}) : helper))) |
||
77 | + "px;\" >\n </div>\n</a>\n"; |
||
78 | },"useData":true}); |
||
79 | templates['galleryimage'] = template({"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) { |
||
80 | var helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; |
||
81 | |||
82 | return "<a class=\"row-element\" style=\"width: " |
||
83 | + alias4(((helper = (helper = helpers.targetWidth || (depth0 != null ? depth0.targetWidth : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"targetWidth","hash":{},"data":data}) : helper))) |
||
84 | + "px; height: " |
||
85 | + alias4(((helper = (helper = helpers.targetHeight || (depth0 != null ? depth0.targetHeight : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"targetHeight","hash":{},"data":data}) : helper))) |
||
86 | + "px;\" href=\"\" data-path=\"" |
||
87 | + alias4(((helper = (helper = helpers.path || (depth0 != null ? depth0.path : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"path","hash":{},"data":data}) : helper))) |
||
88 | + "\">\n <div class=\"image-loader loading\"></div>\n <span class=\"image-label\">\n <span class=\"title\">" |
||
89 | + alias4(((helper = (helper = helpers.label || (depth0 != null ? depth0.label : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"label","hash":{},"data":data}) : helper))) |
||
90 | + "</span>\n </span>\n <div class=\"image container\"></div>\n</a>\n"; |
||
91 | },"useData":true}); |
||
92 | templates['newfilemenu'] = template({"1":function(container,depth0,helpers,partials,data) { |
||
93 | var helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; |
||
94 | |||
95 | return " <li>\n <a href=\"#\" class=\"menuitem\" data-action=\"" |
||
96 | + alias4(((helper = (helper = helpers.id || (depth0 != null ? depth0.id : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"id","hash":{},"data":data}) : helper))) |
||
97 | + "\"><span class=\"icon " |
||
98 | + alias4(((helper = (helper = helpers.iconClass || (depth0 != null ? depth0.iconClass : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"iconClass","hash":{},"data":data}) : helper))) |
||
99 | + " svg\"></span><span class=\"displayname\">" |
||
100 | + alias4(((helper = (helper = helpers.displayName || (depth0 != null ? depth0.displayName : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"displayName","hash":{},"data":data}) : helper))) |
||
101 | + "</span></a>\n </li>\n"; |
||
102 | },"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) { |
||
103 | var stack1, helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; |
||
104 | |||
105 | return "<ul>\n <li>\n <label for=\"file_upload_start\" class=\"menuitem\" data-action=\"upload\" title=\"" |
||
106 | + alias4(((helper = (helper = helpers.uploadMaxHumanFilesize || (depth0 != null ? depth0.uploadMaxHumanFilesize : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"uploadMaxHumanFilesize","hash":{},"data":data}) : helper))) |
||
107 | + "\"><span class=\"svg icon icon-upload\"></span><span class=\"displayname\">" |
||
108 | + alias4(((helper = (helper = helpers.uploadLabel || (depth0 != null ? depth0.uploadLabel : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"uploadLabel","hash":{},"data":data}) : helper))) |
||
109 | + "</span></label>\n </li>\n" |
||
110 | + ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.items : depth0),{"name":"each","hash":{},"fn":container.program(1, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") |
||
111 | + "</ul>\n"; |
||
112 | },"useData":true}); |
||
113 | })(); |
||
114 |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.