Skip to content
This repository has been archived by the owner on Feb 20, 2020. It is now read-only.

Commit

Permalink
fixed loading of duplicate reousrces
Browse files Browse the repository at this point in the history
  • Loading branch information
Saeid Mohadjer authored and Saeid Mohadjer committed Feb 22, 2016
1 parent 4883c97 commit 8292d98
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "resourceLoader",
"homepage": "https://github.com/virtualidentityag/conditional-resource-loader",
"version": "0.0.4",
"version": "0.0.5",
"main": "resourceLoader.js",
}
5 changes: 5 additions & 0 deletions demo/css/demo.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.demo1,
.demo2 {
padding: 20px;
margin-bottom: 20px;
}
3 changes: 1 addition & 2 deletions demo/css/demo1.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.demo {
.demo1 {
background: salmon;
padding: 20px;
}
3 changes: 1 addition & 2 deletions demo/css/demo2.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.demo {
.demo2 {
background: yellow;
padding: 40px;
}
6 changes: 5 additions & 1 deletion demo/demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
</script>
</head>
<body>
<div class="demo" data-init="(function() {$('.demo').plugin1();})" data-resources="[{test: (function() {return true;}), paths: ['js/jquery.plugin1.js', 'css/demo1.css', 'css/demo2.css']}]">
<div class="demo1" data-init="(function() {$('.demo1').plugin();})" data-resources="[{test: (function() {return true;}), paths: ['js/jquery.plugin.js', 'css/demo.css', 'css/demo1.css']}]">
This component's resources (css and js) are loaded via conditional loader! See logs in console...
</div>

<div class="demo2" data-init="(function() {$('.demo2').plugin();})" data-resources="[{test: (function() {return true;}), paths: ['js/jquery.plugin.js', 'css/demo.css', 'css/demo2.css']}]">
This component's resources (css and js) are loaded via conditional loader! See logs in console...
</div>
</body>
Expand Down
4 changes: 2 additions & 2 deletions demo/js/jquery.plugin1.js → demo/js/jquery.plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
;(function ($, window, document, undefined) {
'use strict';

var pluginName = 'plugin1',
var pluginName = 'plugin',
defaults = {
foo: 'bar'
};
Expand All @@ -32,7 +32,7 @@
},

myFunction: function(){
console.log('boilerplate - myFunction was executed');
console.log('initializing ', this.$element.attr('class'));
}
};

Expand Down
18 changes: 7 additions & 11 deletions resourceLoader.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* VI Resource Loader v0.0.4
* VI Resource Loader v0.0.5
* For documentation see:
* https://github.com/virtualidentityag/conditional-resource-loader
*/
Expand All @@ -12,14 +12,10 @@ function resourceLoader(options) {
};
var styles = [];
var scripts = [];

var getResources = function() {
$.each(loader.conditionsAllArray, function () {
$.each(this.resources, function() {
var resource = this;
var js = [];
var css = [];

var test = this.test ? this.test() : true;

if (test) {
Expand All @@ -38,19 +34,19 @@ function resourceLoader(options) {
}

if (path.indexOf('.css') > -1) {
css.push(path);
if ($.inArray(path, styles) === -1) {
styles.push(path);
}
} else {
js.push(path);
if ($.inArray(path, scripts) === -1) {
scripts.push(path);
}
}
});

$.merge(scripts, js);
$.merge(styles, css);
}
});
});
};

var loadResources = function () {
var jsCounter = 0;
var cssCounter = 0;
Expand Down

0 comments on commit 8292d98

Please sign in to comment.