Skip to content

Commit

Permalink
FIX issue #7 - Weird image request
Browse files Browse the repository at this point in the history
  • Loading branch information
Riccardo Tempesta committed Feb 15, 2017
1 parent 7e202a0 commit 9267d7b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

},
"type": "magento2-module",
"version": "0.2.0",
"version": "0.2.1",
"license": "OSL 3.0",
"autoload": {
"files": [
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="MSP_DevTools" setup_version="0.2.0">
<module name="MSP_DevTools" setup_version="0.2.1">
<sequence>
<module name="MSP_Common"/>

Expand Down
39 changes: 25 additions & 14 deletions view/base/web/js/lib/knockout/template/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@ define(
'use strict';

/**
* Formats path of type "path.to.template" to RequireJS compatible
*
* @param {String} path
* @return {String} - formatted template path
*/
* Formats path of type "path.to.template" to RequireJS compatible
*
* @param {String} path
* @return {String} - formatted template path
*/
function formatTemplatePath(path)
{
return 'text!' + path.replace(/^([^\/]+)/g, '$1/template') + '.html';
}

/**
* Get a random block for MSP devtools
*
* @returns {string}
*/
* Get a random block for MSP devtools
*
* @returns {string}
*/
function getRandomBlockId()
{
var text = "";
Expand All @@ -56,11 +56,16 @@ define(
CoreLoader.loadTemplateOrig = CoreLoader.loadTemplate;

CoreLoader.loadTemplate = function (path) {
var res = CoreLoader.loadTemplateOrig(path);
var defer = $.Deferred();
var content = CoreLoader.loadTemplateOrig(path);

if (res) {
res.done(
if (!window.mspDevTools) {
return content;
}

if (content) {
var defer = $.Deferred();

content.done(
function (tmpl) {
var mspBlockId = getRandomBlockId();

Expand All @@ -71,6 +76,9 @@ define(
id: mspBlockId
};

// we need this to prevent parseHTML to load images
tmpl = tmpl.replace(/\s+src\s*=\s*/, " msp-tmp-src=");

var fragmentsOut = [];
var fragmentsIn = _.toArray($.parseHTML(tmpl));
for (var i=0; i<fragmentsIn.length; i++) {
Expand All @@ -88,6 +96,8 @@ define(
}

tmpl = fragmentsOut.join('');
tmpl = tmpl.replace(/&lt;%=(.+?)%&gt;/, '<%=$1%>');
tmpl = tmpl.replace(/\s+msp-tmp-src=/, " src=");

if (!window.mspDevTools) {
window.mspDevTools = {};
Expand All @@ -98,14 +108,15 @@ define(

window.mspDevTools['uiComponents'][mspBlockId] = payload;
window.postMessage('mspDevToolsUpdate', '*', []);

defer.resolve(tmpl);
}
);

return defer.promise();
}

return res;
return this.loadFromFile(path);
};

return CoreLoader;
Expand Down

0 comments on commit 9267d7b

Please sign in to comment.