Skip to content

Commit

Permalink
Merge pull request #29 from danjford/gh-pages
Browse files Browse the repository at this point in the history
Fixing babel and updating examples
  • Loading branch information
danjford committed Dec 23, 2015
2 parents 0759228 + 7523d84 commit 77f6a16
Show file tree
Hide file tree
Showing 14 changed files with 129 additions and 89 deletions.
3 changes: 2 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"plugins": ["external-helpers-2"]
"plugins": ["external-helpers-2"],
"presets": ["es2015-rollup"]
}
15 changes: 9 additions & 6 deletions _posts/2015-12-19-easy-events.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,18 @@ categories: example
{%raw-%}
router.createRoute({
path: '/',
controller: function() { },
controller: {

actions: {
randomColor: function() {
this.set('color', "#" + Math.random().toString(16).slice(2, 8));
}
}

},
view: {
el: '#target',
template: '<div id="random-color" style="background-color: \{{color}};"></div><button on-click="randomColor">click me</button>'
},
actions: {
randomColor: function() {
this.set('color', "#" + Math.random().toString(16).slice(2, 8));
}
}
});
{%endraw-%}
Expand Down
2 changes: 1 addition & 1 deletion _posts/2015-12-19-get-html-from-other-pages.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ categories: example
{%raw-%}
router.createRoute({
path: '/example',
controller: function() { },
controller: { },
view: {
el: '#target',
template: {
Expand Down
17 changes: 13 additions & 4 deletions _posts/2015-12-19-simple-hierarchy.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,24 @@ categories: example
{%raw-%}
router.createRoute({
path: '/',
controller: function() {
console.log('This is the index page.');
controller: {

controller: function() {
console.log('This is the index page.');
}

}

});

router.createRoute({
path: '[/]blog',
controller: function() {
console.log('This is the child of that ^ index page.');
controller: {

controller: function() {
console.log('This is the child of that ^ index page.');
}

}
});
{%endraw-%}
Expand Down
24 changes: 14 additions & 10 deletions _posts/2015-12-19-simple-todo-mvc.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,24 @@ categories: example
{% highlight javascript %}
router.createRoute({
path: '/',
controller: function() { },
controller: {

actions: {
addTodo: function ( event, inputVal ) {
if ( inputVal.length && this.get('todo.items').length < this.get('todo.max') ) {
this.push( 'todo.items', { task: inputVal } );
this.set('todo.input', '');
}
event.original.preventDefault();
}
}

},
view: {
el: '#main-page',
data: { 'todo': { 'items': [], 'max': 5 } },
template: document.querySelector('#todo').innerHTML
},
actions: {
addTodo: function ( event, inputVal ) {
if ( inputVal.length && this.get('todo.items').length < this.get('todo.max') ) {
this.push( 'todo.items', { task: inputVal } );
this.set('todo.input', '');
}
event.original.preventDefault();
}
}
});
{% endhighlight %}
</div>
Expand Down
2 changes: 1 addition & 1 deletion _posts/2015-12-19-two-way-data-binding.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ categories: example
{%raw-%}
router.createRoute({
path: '/',
controller: function() { },
controller: { },
view: {
el: '#target',
template: '<input type="text" value="\{{fullName}}"/> Hi my name is \{{fullName}}, and I find this is so simple!'
Expand Down
61 changes: 34 additions & 27 deletions assets/js/lodestar-ractive.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* LodestarJS Router - 1.1.0.
Author: Dan J Ford
Contributors: undefined
Published: Tue Dec 22 2015 02:17:07 GMT+0000 (GMT) */
/* Lodestar-Ractive - 1.1.0.
Author: Dan J Ford
Contributors: undefined
Published: Wed Dec 23 2015 00:40:31 GMT+0000 (GMT) */

(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
Expand Down Expand Up @@ -378,15 +378,6 @@ Published: Tue Dec 22 2015 02:17:07 GMT+0000 (GMT) */
createPointer.childRoutes[routeObject.path].controller = routeObject.controller;
}

/**
* Returns all of the current routes in this instance of the Router.
* @return {Object} returns the routes.
*/
function getRoutes() {

return copy({}, this.routes);
}

function formatRoute(route) {

if (route === '') {
Expand Down Expand Up @@ -484,6 +475,17 @@ Published: Tue Dec 22 2015 02:17:07 GMT+0000 (GMT) */
return formattedRoute === '' ? '/' : formattedRoute;
}

function listenEvent(target, e, f) {

if (hasEventListener) {

target.addEventListener(e, f, false);
} else {

target.attachEvent(e, f);
}
}

/**
* This sets up the events for 'Hashchange' and 'History' mode depending on what has been selected and what is available.
* @return {Void}, nothing returned
Expand All @@ -495,36 +497,34 @@ Published: Tue Dec 22 2015 02:17:07 GMT+0000 (GMT) */

if (this.config.loggingLevel === 'HIGH') logger.debug('Listener is now active.');

var windowListener = hasEventListener ? window.addEventListener : window.attachEvent,
docListener = hasEventListener ? document.addEventListener : document.attachEvent,
initialLink = this.config.useHistory && hasHistory ? window.location.pathname : window.location.hash;
var initialLink = this.config.useHistory && hasHistory ? window.location.pathname : window.location.hash;

this.config.listenerActive = true;

docListener('click', function (e) {
listenEvent(document, 'click', function (e) {
window.LodeVar.previousPath = formatRoute.call(_this, removeOrigin(window.location.href));
});

if (!this.config.useHistory || !hasHistory) {

if (this.config.loggingLevel === 'HIGH') logger.debug('Listening for hash changes.');

windowListener(hasEventListener ? 'hashchange' : 'onhashchange', function () {
listenEvent(window, hasEventListener ? 'hashchange' : 'onhashchange', function () {
_this.resolve(formatRoute.call(_this, window.location.hash));
});
} else if (this.config.useHistory && hasHistory) {

if (this.config.loggingLevel === 'HIGH') logger.debug('Listening for clicks or popstate.');

docListener('click', function (e) {

listenEvent(document, 'click', function (e) {
var historyLink = historyClick.call(_this, e);

if (historyLink) {
_this.resolve(historyLink);
}
});
windowListener('popstate', function () {

listenEvent(window, 'popstate', function () {
_this.resolve(formatRoute.call(_this, window.location.pathname));
});
}
Expand Down Expand Up @@ -605,7 +605,6 @@ Published: Tue Dec 22 2015 02:17:07 GMT+0000 (GMT) */

createRoute: createRoute,
map: map,
getRoutes: getRoutes,
resolve: resolve,
notFound: function notFound(callback) {
this.userNotFound = callback;
Expand Down Expand Up @@ -669,13 +668,18 @@ Published: Tue Dec 22 2015 02:17:07 GMT+0000 (GMT) */
function setup(options) {

var controllerOpts = options.controller ? options.controller : {},
getParent = this.getParent;
getParent = this.getParent,
hasView = typeof options.view !== 'undefined';

this.controllerModel = hasView ? new Ractive(options.view) : {};

this.controllerModel = new Ractive(options.view);
if (hasView) {

if (controllerOpts.actions) this.controllerModel.on(controllerOpts.actions);
if (controllerOpts.observe) this.controllerModel.observe(controllerOpts.observe);
if (controllerOpts.observeOnce) this.controllerModel.observeOnce(controllerOpts.observeOnce);
}

if (controllerOpts.actions) this.controllerModel.on(controllerOpts.actions);
if (controllerOpts.observe) this.controllerModel.observe(controllerOpts.observe);
if (controllerOpts.observeOnce) this.controllerModel.observeOnce(controllerOpts.observeOnce);
if (typeof this.getParent === 'function') this.controllerModel.getParent = function () {
return getParent().controllerModel;
};
Expand Down Expand Up @@ -725,6 +729,9 @@ Published: Tue Dec 22 2015 02:17:07 GMT+0000 (GMT) */

setup.call(this, options);
}
} else {

setup.call(this, options);
}
}

Expand Down
56 changes: 35 additions & 21 deletions assets/js/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 77f6a16

Please sign in to comment.