From a54175599ed3d922ef8daf9ef786cc3f05cb3140 Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Tue, 13 Dec 2016 12:50:30 +0100 Subject: [PATCH] editor: use scope variable to avoid complicated closure pattern --- src/browser/js/app/editor/init.js | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/browser/js/app/editor/init.js b/src/browser/js/app/editor/init.js index 2ccdd27a..8bb8494a 100644 --- a/src/browser/js/app/editor/init.js +++ b/src/browser/js/app/editor/init.js @@ -108,23 +108,20 @@ var init = function(){ } actions[' Add widget'] = {} - var createFunction = function(widgetType,container,data){ - return function() { - data.widgets = data.widgets || [] - var newData = {type:widgetType} - if (!target.attr('data-tab')) { - newData.top = Math.round(d.offsetY / (GRIDWIDTH * PXSCALE)) * GRIDWIDTH - newData.left= Math.round(d.offsetX / (GRIDWIDTH * PXSCALE)) * GRIDWIDTH - } - data.widgets.push(newData) - updateDom(container,data) - } - } for (category in widgetCategories) { actions[' Add widget'][category] = {} for (t in widgetCategories[category]) { - var wtype = widgetCategories[category][t] - actions[' Add widget'][category][wtype] = createFunction(wtype,container,data) + let wtype = widgetCategories[category][t] + actions[' Add widget'][category][wtype] = function(){ + data.widgets = data.widgets || [] + var newData = {type:wtype} + if (!target.attr('data-tab')) { + newData.top = Math.round(d.offsetY / (GRIDWIDTH * PXSCALE)) * GRIDWIDTH + newData.left= Math.round(d.offsetX / (GRIDWIDTH * PXSCALE)) * GRIDWIDTH + } + data.widgets.push(newData) + updateDom(container,data) + } } }