Skip to content
Snippets Groups Projects
Verified Commit bc6dc59a authored by Thomas Rientjes's avatar Thomas Rientjes
Browse files

Improve shorthand notation logic

parent fe60660c
No related branches found
No related tags found
No related merge requests found
......@@ -17,6 +17,7 @@
"Resource": true,
"resources": true,
"Setting": true,
"shorthands": true,
"stateManager": true,
"WebRequest": true,
"Whitelist": true,
......@@ -27,7 +28,8 @@
"core/constants.js",
"core/files.js",
"core/mappings.js",
"core/resources.js"
"core/resources.js",
"core/shorthands.js"
],
"rules": {
"no-unused-vars": "off"
......
......@@ -35,7 +35,7 @@ var mappings = {
'swfobject/{version}/swfobject.': resources.swfobject,
'webfont/{version}/webfont.': resources.webfont,
// Common Shorthand Notations [Deprecated]
// Basic Shorthand Notations [Deprecated]
'dojo/1/dojo/dojo.': {
'path': 'resources/dojo/1.6.1/dojo/dojo.js.dec',
'type': 'application/javascript'
......@@ -116,7 +116,7 @@ var mappings = {
'ui/{version}/jquery-ui.js': resources.jQueryUI,
'ui/{version}/jquery-ui.min.js': resources.jQueryUI,
// Common Shorthand Notations [Deprecated]
// Basic Shorthand Notations [Deprecated]
'jquery-latest.': {
'path': 'resources/jquery/1.11.1/jquery.min.js.dec',
'type': 'application/javascript'
......@@ -124,46 +124,6 @@ var mappings = {
'jquery.': {
'path': 'resources/jquery/1.11.1/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery-1.3.min.js': {
'path': 'resources/jquery/1.3.0/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery-1.3.js': {
'path': 'resources/jquery/1.3.0/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery-1.4.min.js': {
'path': 'resources/jquery/1.4.0/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery-1.4.js': {
'path': 'resources/jquery/1.4.0/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery-1.5.min.js': {
'path': 'resources/jquery/1.5.0/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery-1.5.js': {
'path': 'resources/jquery/1.5.0/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery-1.6.min.js': {
'path': 'resources/jquery/1.6.0/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery-1.6.js': {
'path': 'resources/jquery/1.6.0/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery-1.7.min.js': {
'path': 'resources/jquery/1.7.0/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery-1.7.js': {
'path': 'resources/jquery/1.7.0/jquery.min.js.dec',
'type': 'application/javascript'
}
}
},
......
......@@ -100,12 +100,23 @@ requestAnalyzer._findLocalTarget = function (resourceMappings, basePath, channel
if (resourcePattern.startsWith(resourceMold)) {
let targetPath, version;
let targetPath, hostShorthands, version;
targetPath = resourceMappings[resourceMold].path;
targetPath = targetPath.replace(Resource.VERSION_PLACEHOLDER, versionNumber);
version = versionNumber && versionNumber[0] || targetPath.match(Resource.VERSION_EXPRESSION);
hostShorthands = shorthands[channelHost];
if (hostShorthands && hostShorthands[targetPath]) {
let shorthand = hostShorthands[targetPath];
targetPath = shorthand.path;
version = shorthand.version;
} else {
version = versionNumber && versionNumber[0] || targetPath.match(Resource.VERSION_EXPRESSION);
}
// Prepare and return a local target.
return {
......
/**
* Shorthands
* Belongs to Decentraleyes.
*
* @author Thomas Rientjes
* @since 2018-02-24
* @license MPL 2.0
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
'use strict';
/**
* Shorthands
*/
var shorthands = {
// jQuery CDN [Deprecated]
'code.jquery.com': {
'resources/jquery/1.7/jquery.min.js.dec': {
'path': 'resources/jquery/1.7.0/jquery.min.js.dec',
'version': '1.7.0'
},
'resources/jquery/1.6/jquery.min.js.dec': {
'path': 'resources/jquery/1.6.0/jquery.min.js.dec',
'version': '1.6.0'
},
'resources/jquery/1.5/jquery.min.js.dec': {
'path': 'resources/jquery/1.5.0/jquery.min.js.dec',
'version': '1.5.0'
},
'resources/jquery/1.4/jquery.min.js.dec': {
'path': 'resources/jquery/1.4.0/jquery.min.js.dec',
'version': '1.4.0'
},
'resources/jquery/1.3/jquery.min.js.dec': {
'path': 'resources/jquery/1.3.0/jquery.min.js.dec',
'version': '1.3.0'
}
}
};
......@@ -17,6 +17,7 @@
<script src="../../core/files.js"></script>
<script src="../../core/resources.js"></script>
<script src="../../core/mappings.js"></script>
<script src="../../core/shorthands.js"></script>
<script src="../../core/request-sanitizer.js"></script>
<script src="../../core/state-manager.js"></script>
<script src="../../core/request-analyzer.js"></script>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment