extended-spine
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -39,2 +39,3 @@ // Generated by CoffeeScript 1.6.3 | ||
Controller.init = function(jQuery, scope) { | ||
var that; | ||
if (scope == null) { | ||
@@ -44,4 +45,13 @@ scope = '[data-application]:first'; | ||
$ = jQuery; | ||
that = this; | ||
$.fn.getController = function() { | ||
return $(this).data('controller'); | ||
var controller, | ||
_this = this; | ||
controller = $(this).data('controller'); | ||
if (!controller || typeof controller === 'string' && hasAttr($(this), 'data-controller') && hasAttr($(this), 'data-lazy')) { | ||
return function() { | ||
return that.createController($(_this).attr('data-controller'), $(_this)); | ||
}; | ||
} | ||
return controller; | ||
}; | ||
@@ -93,3 +103,3 @@ if (scope !== false) { | ||
Controller.findElementsWithController = function(scope) { | ||
Controller.findElementsWithController = function(scope, self) { | ||
var result, | ||
@@ -100,8 +110,11 @@ _this = this; | ||
} | ||
if (self == null) { | ||
self = true; | ||
} | ||
scope = $(scope); | ||
result = []; | ||
if (hasAttr(scope, 'data-controller')) { | ||
if (self && hasAttr(scope, 'data-controller')) { | ||
result.push(scope); | ||
} | ||
scope.find('*[data-controller]').each(function(i, el) { | ||
scope.find('*[data-controller]:not([data-lazy])').each(function(i, el) { | ||
el = $(el); | ||
@@ -113,3 +126,3 @@ return result.push(el); | ||
Controller.refresh = function(scope) { | ||
Controller.refresh = function(scope, self) { | ||
var el, _i, _len, _ref, _results; | ||
@@ -119,3 +132,6 @@ if (scope == null) { | ||
} | ||
_ref = this.findElementsWithController(scope); | ||
if (self == null) { | ||
self = true; | ||
} | ||
_ref = this.findElementsWithController(scope, self); | ||
_results = []; | ||
@@ -129,3 +145,3 @@ for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
Controller.unbind = function(scope) { | ||
Controller.unbind = function(scope, self) { | ||
var controller, el, _i, _len, _ref, _results; | ||
@@ -135,3 +151,6 @@ if (scope == null) { | ||
} | ||
_ref = this.findElementsWithController(scope); | ||
if (self == null) { | ||
self = true; | ||
} | ||
_ref = this.findElementsWithController(scope, self); | ||
_results = []; | ||
@@ -178,2 +197,6 @@ for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
Controller.find = function(controller) { | ||
return $('[data-controller="' + controller + '"]').getController(); | ||
}; | ||
return Controller; | ||
@@ -180,0 +203,0 @@ |
{ | ||
"name": "extended-spine", | ||
"description": "Some extensions for spine framework", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"author": { | ||
@@ -25,12 +25,15 @@ "name": "David Kudera", | ||
"dependencies": { | ||
"spine": "~1.2.1", | ||
"is-mobile": "~0.2.2" | ||
"spine": "1.2.2", | ||
"is-mobile": "0.2.2" | ||
}, | ||
"devDependencies": { | ||
"chai": "~1.8.0", | ||
"mocha": "~1.13.0" | ||
"chai": "1.8.1", | ||
"mocha": "1.15.1", | ||
"mocha-phantomjs": "3.2.0", | ||
"phantomjs": "1.9.2-5" | ||
}, | ||
"scripts": { | ||
"test": "cd ./test; mocha-phantomjs ./index.html;" | ||
"test": "mocha-phantomjs -p ./node_modules/phantomjs/bin/phantomjs ./test/index.html", | ||
"test-build": "cd ./test; simq build;" | ||
} | ||
} |
@@ -0,1 +1,5 @@ | ||
[![NPM version](https://badge.fury.io/js/extended-spine.png)](http://badge.fury.io/js/extended-spine) | ||
[![Dependency Status](https://gemnasium.com/sakren/node-extended-spine.png)](https://gemnasium.com/sakren/node-extended-spine) | ||
[![Build Status](https://travis-ci.org/sakren/node-extended-spine.png?branch=master)](https://travis-ci.org/sakren/node-extended-spine) | ||
# extended-spine | ||
@@ -67,3 +71,3 @@ | ||
``` | ||
Controller = require 'extended-spine' | ||
Controller = require 'extended-spine/Controller' | ||
Controller.init($) | ||
@@ -80,2 +84,37 @@ | ||
Methods `unbind` and `refresh` manipulates also with element on which it was called. You can of course disable that. | ||
``` | ||
Controller.unbind(el, false) | ||
Controller.refresh(el, false) | ||
``` | ||
## Finding controllers | ||
From jQuery element: | ||
``` | ||
menu = $('#menu').getController() | ||
// or | ||
menu = $('[data-controller="/app/controller/Menu"]').getController() | ||
``` | ||
Otherwise: | ||
``` | ||
menu = Controller.find('/app/controller/Menu') | ||
``` | ||
## Lazy controllers | ||
If you don't want to instantiate some controller immediately, you can add html attribute `data-lazy` to. | ||
``` | ||
<div data-controller="/path/to/my/controller" data-lazy></div> | ||
``` | ||
Now when you want to create instance of this controller, you have to get it's controller factory and use it. | ||
``` | ||
factory = Controller.find('/path/to/my/controller') // for lazy controllers, factory function is returned | ||
controller = factory() // just call it and it will return created controller | ||
``` | ||
## Mobile/computer specific controllers | ||
@@ -98,2 +137,11 @@ | ||
* 1.2.0 | ||
+ Tests modules does not need to be installed globally | ||
+ Some updates | ||
+ Added find method | ||
+ Added lazy controller option | ||
+ Added lazy option | ||
+ Added badges | ||
+ Added travis | ||
* 1.1.0 | ||
@@ -100,0 +148,0 @@ + Automatically creates html id |
{ | ||
"packages": { | ||
"test": { | ||
"application": "./tests.js", | ||
"base": "../", | ||
"target": "./test/application.js", | ||
"modules": [ | ||
"./tests/*.coffee", | ||
"../Controller.js", | ||
"./app/*.coffee" | ||
"./test/tests/*.coffee", | ||
"./test/app/*.coffee", | ||
"./lib/Controller.js" | ||
], | ||
"aliases": { | ||
"extended-spine/Controller": "/lib/Controller.js" | ||
}, | ||
"run": [ | ||
"/tests/Controller" | ||
"/test/tests/Controller" | ||
] | ||
@@ -13,0 +17,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
192617
23
2585
159
4
6
1
Updatedis-mobile@0.2.2
Updatedspine@1.2.2