Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Namespaced binding handlers #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/bindings/alertBinding.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ko.bindingHandlers.alert = {
ko.bindingHandlers['knockstrap.alert'] = {
init: function () {
return { controlsDescendantBindings: true };
},
Expand Down Expand Up @@ -36,4 +36,4 @@ ko.bindingHandlers.alert = {
}
};

ko.virtualElements.allowedBindings.alert = true;
ko.virtualElements.allowedBindings['knockstrap.alert'] = true;
4 changes: 2 additions & 2 deletions src/bindings/carouselBinding.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ko.bindingHandlers.carousel = {
ko.bindingHandlers['knockstrap.carousel'] = {

defaults: {
css: 'carousel slide',
Expand Down Expand Up @@ -42,7 +42,7 @@
init: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
var $element = $(element),
value = valueAccessor(),
defaults = ko.bindingHandlers.carousel.defaults,
defaults = ko.bindingHandlers['knockstrap.carousel'].defaults,
extendDefaults = function(defs, type) {
var extended = {
name: defs.name,
Expand Down
2 changes: 1 addition & 1 deletion src/bindings/checkboxBinding.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Knockout checked binding doesn't work with Bootstrap checkboxes
ko.bindingHandlers.checkbox = {
ko.bindingHandlers['knockstrap.checkbox'] = {
init: function (element, valueAccessor) {
var $element = $(element),
handler = function (e) {
Expand Down
2 changes: 1 addition & 1 deletion src/bindings/classBinding.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Inspired by https://github.com/knockout/knockout/wiki/Bindings---class
var previousClassKey = '__ko__previousClassValue__';

ko.bindingHandlers['class'] = {
ko.bindingHandlers['knockstrap.class'] = {
update: function (element, valueAccessor) {
if (element[previousClassKey]) {
ko.utils.toggleDomNodeCssClass(element, element[previousClassKey], false);
Expand Down
4 changes: 2 additions & 2 deletions src/bindings/modalBinding.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ko.bindingHandlers.modal = {
ko.bindingHandlers['knockstrap.modal'] = {
defaults: {
css: 'modal fade',
dialogCss: '',
Expand Down Expand Up @@ -29,7 +29,7 @@
init: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
var $element = $(element),
value = valueAccessor(),
defaults = ko.bindingHandlers.modal.defaults,
defaults = ko.bindingHandlers['knockstrap.modal'].defaults,
options = ko.utils.extend({ show: $element.data().show || false }, ko.utils.unwrapProperties(value.options)),
extendDefaults = function (defs, val) {
var extended = {
Expand Down
2 changes: 1 addition & 1 deletion src/bindings/popoverBinding.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var popoverDomDataTemplateKey = '__popoverTemplateKey__';

ko.bindingHandlers.popover = {
ko.bindingHandlers['knockstrap.popover'] = {

init: function (element) {
var $element = $(element);
Expand Down
4 changes: 2 additions & 2 deletions src/bindings/progressBinding.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ko.bindingHandlers.progress = {
ko.bindingHandlers['knockstrap.progress'] = {
defaults: {
css: 'progress',
text: '',
Expand All @@ -12,7 +12,7 @@
var $element = $(element),
value = valueAccessor(),
unwrappedValue = ko.unwrap(value),
defs = ko.bindingHandlers.progress.defaults,
defs = ko.bindingHandlers['knockstrap.progress'].defaults,
model = $.extend({}, defs, unwrappedValue);

if (typeof unwrappedValue === 'number') {
Expand Down
2 changes: 1 addition & 1 deletion src/bindings/radioBinding.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Knockout checked binding doesn't work with Bootstrap radio-buttons
ko.bindingHandlers.radio = {
ko.bindingHandlers['knockstrap.radio'] = {
init: function (element, valueAccessor) {

if (!ko.isObservable(valueAccessor())) {
Expand Down
2 changes: 1 addition & 1 deletion src/bindings/toggleBinding.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ko.bindingHandlers.toggle = {
ko.bindingHandlers['knockstrap.toggle'] = {
init: function (element, valueAccessor) {
var value = valueAccessor();

Expand Down
2 changes: 1 addition & 1 deletion src/bindings/tooltipBinding.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ko.bindingHandlers.tooltip = {
ko.bindingHandlers['knockstrap.tooltip'] = {
init: function (element) {
var $element = $(element);

Expand Down
2 changes: 1 addition & 1 deletion src/templates/progress.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="progress-bar" role="progressbar" aria-valuemin="0" aria-valuemax="100"
data-bind="style: { width: barWidth }, attr: { 'aria-valuenow': value }, css: { active: animated, 'progress-bar-striped': striped }, 'class': barType">
data-bind="style: { width: barWidth }, attr: { 'aria-valuenow': value }, css: { active: animated, 'progress-bar-striped': striped }, 'knockstrap.class': barType">
<span data-bind="css: { 'sr-only': textHidden }">
<span data-bind="text: value"></span>% <span data-bind="text: text"></span>
</span>
Expand Down
4 changes: 2 additions & 2 deletions tests/bindings/alertBindingBehaviors.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
describe('Binding: alert', function () {
this.prepareTestElement('<div data-bind="alert: value"></div>');
this.prepareTestElement('<div data-bind="knockstrap.alert: value"></div>');

beforeEach(function () {
this.testElement.after('<script id="test-template" type="text/html"><div class="test-template" data-bind="text: label">Text</div></script>');
Expand Down Expand Up @@ -97,7 +97,7 @@
};

// change test element to ko virtual elements for this spec
this.testElement = this.testElement.removeAttr('data-bind').html('<!-- ko alert: value --><!-- /ko -->');
this.testElement = this.testElement.removeAttr('data-bind').html('<!-- ko knockstrap.alert: value --><!-- /ko -->');

ko.applyBindings(vm, this.testElement[0]);

Expand Down
2 changes: 1 addition & 1 deletion tests/bindings/carouselBindingBehaviors.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
describe('Binding: carousel', function () {
this.prepareTestElement('<div data-bind="carousel: value"></div>');
this.prepareTestElement('<div data-bind="knockstrap.carousel: value"></div>');

beforeEach(function() {
this.testElement.after('<script id="test-template" type="text/html"><div class="test-template" data-bind="text: label">Text</div></script>');
Expand Down
4 changes: 2 additions & 2 deletions tests/bindings/checkboxBindingBehaviors.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
describe('Binding: checkbox', function () {
describe('Array case', function () {
this.prepareTestElement('<div class="btn-group form-group" data-toggle="buttons" data-bind="checkbox: value">'
this.prepareTestElement('<div class="btn-group form-group" data-toggle="buttons" data-bind="knockstrap.checkbox: value">'
+ '<label class="btn btn-primary"><input type="checkbox" value="A" />A</label>'
+ '<label class="btn btn-primary"><input type="checkbox" value="B" />B</label>'
+ '<label class="btn btn-primary"><input type="checkbox" value="C" />C</label>'
Expand Down Expand Up @@ -105,7 +105,7 @@

describe('Boolean case', function () {
this.prepareTestElement('<div class="btn-group form-group" data-toggle="buttons">'
+ '<label class="btn btn-primary"><input type="checkbox" data-bind="checkbox: value" />A</label>'
+ '<label class="btn btn-primary"><input type="checkbox" data-bind="knockstrap.checkbox: value" />A</label>'
+ '</div>');

it('Should throw exception for non-observable value', function () {
Expand Down
2 changes: 1 addition & 1 deletion tests/bindings/classBindingBehaviors.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
describe('Binding: class', function () {
this.prepareTestElement('<div data-bind="class: value"></div>');
this.prepareTestElement('<div data-bind="knockstrap.class: value"></div>');

it('Should add class to element', function () {
var vm = {
Expand Down
2 changes: 1 addition & 1 deletion tests/bindings/modalBindingBehaviors.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
describe('Binding: modal', function () {
this.prepareTestElement('<div data-bind="modal: value"></div>');
this.prepareTestElement('<div data-bind="knockstrap.modal: value"></div>');

beforeEach(function() {
this.testElement.after('<script id="test-template" type="text/html"><div id="test">Text</div></script>');
Expand Down
2 changes: 1 addition & 1 deletion tests/bindings/popoverBindingBehaviors.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
describe('Binding: popover', function () {
this.prepareTestElement('<div data-bind="popover: value">Test</div>');
this.prepareTestElement('<div data-bind="knockstrap.popover: value">Test</div>');

afterEach(function() {
$('.popover').remove();
Expand Down
2 changes: 1 addition & 1 deletion tests/bindings/progressBindingBehaviors.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
describe('Binding: progress', function() {
this.prepareTestElement('<div data-bind="progress: value"></div>');
this.prepareTestElement('<div data-bind="knockstrap.progress: value"></div>');

it('Should add "progress" class to target element', function() {
ko.applyBindings({ value: 1 }, this.testElement[0]);
Expand Down
2 changes: 1 addition & 1 deletion tests/bindings/radioBindingBehaviors.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
describe('Binding: radio', function () {
this.prepareTestElement('<div class="btn-group form-group" data-toggle="buttons" data-bind="radio: value">'
this.prepareTestElement('<div class="btn-group form-group" data-toggle="buttons" data-bind="knockstrap.radio: value">'
+ '<label class="btn btn-primary"><input type="radio" name="options" value="A" />A</label>'
+ '<label class="btn btn-primary"><input type="radio" name="options" value="B" />B</label>'
+ '</div>');
Expand Down
2 changes: 1 addition & 1 deletion tests/bindings/toggleBindingBehaviors.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
describe('Binding: toggle', function () {
this.prepareTestElement('<button data-toggle="button" data-bind="toggle: value">toggle</button>');
this.prepareTestElement('<button data-toggle="button" data-bind="knockstrap.toggle: value">toggle</button>');

it('Shoud throw exception for non-observable value', function() {
var el = this.testElement[0];
Expand Down
2 changes: 1 addition & 1 deletion tests/bindings/tooltipBindingBehaviors.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
describe('Binding: tooltip', function () {
this.prepareTestElement('<div data-bind="tooltip: options">Text</div>');
this.prepareTestElement('<div data-bind="knockstrap.tooltip: options">Text</div>');

afterEach(function() {
$('.tooltip').remove();
Expand Down