Skip to content
Permalink
Browse files

Added not minified dev-js file.

  • Loading branch information...
robbz committed Mar 16, 2013
1 parent de70eb0 commit 1826a0b04617a304f800c8c5964e2a90801565e8
Showing with 187 additions and 3 deletions.
  1. +17 −1 Gruntfile.js
  2. +168 −0 bin/flexigin-0.0.1.js
  3. +2 −2 bin/flexigin-0.0.1.min.js
@@ -26,6 +26,21 @@ module.exports = function (grunt) {
}
},

concat: {
options: {
banner: '/*!\n' +
' * <%= pkg.name %> - v<%= pkg.version %>\n' +
' * (c) <%= pkg.author %>\n' +
' * License: MIT (http://www.opensource.org/licenses/mit-license.php)\n' +
' * <%= grunt.template.today("yyyy-mm-dd") %> \n' +
' */\n'
},
dist: {
src: ['lib/flexigin.js', 'lib/load.js', 'lib/resolve.js'],
dest: 'bin/flexigin-<%= pkg.version %>.js'
}
},

watch: {
options: {
files: [ 'lib/*.js', '!node_modules/**/*.js' ],
@@ -37,6 +52,7 @@ module.exports = function (grunt) {

grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-concat');

grunt.registerTask('default', [ 'uglify' ]);
grunt.registerTask('default', [ 'uglify', 'concat' ]);
};
@@ -0,0 +1,168 @@
/*!
* flexigin - v0.0.1
* (c) Roberto Bez (http://www.devangelist.de)
* License: MIT (http://www.opensource.org/licenses/mit-license.php)
* 2013-03-16
*/
(function(window) {
var fx = function(components, options, callback) {
if (typeof components === 'function') {
components = '/';
callback = components;
}
if (typeof options === 'function') {
callback = options;
options = {};
}
options = options || {};
components = fx.resolve(components);
fx.load(components, options, callback);
};

fx.set = function(key, value) {
fx[key] = value;
};
fx.get = function(key) {
return fx[key];
}

window.fx = fx;

if (typeof define !== 'undefined') {
define(function () {
return fx;
});
}
})(window);
(function(fx, $) {
var load = function(components, options, callback) {
options = options || {};

var query = fx.query();
$.each(components, function(key, component) {
query.add(component, options);
});
if (query.isEmpty()) {
callback();
return;
}
query.run(options, callback);
};

fx.loaded = [];
var query = function() {
var query = [];
var loader = this;
var deferreds = getDeferreds();
return {
add: function(component, options) {
if (fx.loaded.indexOf(component) !== -1) {
return;
}
query.push(deferreds[component.type](component.url, options));
loader.loaded.push(component);
},
run: function(options, callback) {
var onLoad = function(data) {
if (typeof ko !== 'undefined' && typeof options.viewModel !== 'undefined') {
var viewModel = options.viewModel();
if (viewModel.hasOwnProperty('init')) {
viewModel.init();
}
ko.applyBindings(viewModel, $(options.container || 'body')[0]);
}
callback(null, data);
};
$.when.apply($, query)
.done(onLoad)
.fail(callback);
},
length: function() {
return query.length;
},
isEmpty: function() {
return query.length === 0;
}
}
};

var getDeferreds = function() {
return {
html: function(url, options) {
var onLoad = function(html) {
$(options.container || 'body').append(html);
};
return $.get(url).done(onLoad);
},
css: function(url) {
var onLoad = function(css) {
$('head').append('<style>' + css + '</style>');
};
return $.get(url).done(onLoad);
},
js: function(url) {
return $.getScript(url);
}
};
};

fx.load = load;
fx.query = query;
})(fx, jQuery);
(function(fx, $) {
var url = function() {
return {
build: function(component, type) {
component = trimSlash(component);
return (fx.get('route') || '/{component}/{type}/')
.replace('{component}', component)
.replace('{type}', type);
},
getExtension: function(url) {
var parts = url.split('/');
return parts[parts.length - 1];
}
}
};

var resolve = function(components) {
var url = fx.url();
var extensions = ['js', 'css', 'html'];
var createComponent = function(component, extension) {
return {
url: url.build(component, extension),
type: extension
};
}

var resolved = [];
if (typeof components === 'string') {
components = [components];
}
$.each(components, function(key, component) {
if (typeof component === 'string') {
var extension = url.getExtension(component);

// If we got an extensionless url, create a component for each extension.
if (extensions.indexOf(extension) === -1) {
$.each(extensions, function(key, extension) {
resolved.push(createComponent(component, extension));
});
} else {
component = component.substr(0, component.lastIndexOf('/'));
resolved.push(createComponent(component, extension));
}
} else {
resolved.push(component);
}
});
return resolved;
};

var trimSlash = function(text) {
return text.replace(/^\/+|\/+$/g, '');
};

fx.resolve = resolve;
fx.url = url;
})(fx, jQuery);

Some generated files are not rendered by default. Learn more.

0 comments on commit 1826a0b

Please sign in to comment.
You can’t perform that action at this time.