Skip to content

Commit

Permalink
fix merge conflict, conflict in minified version of build output
Browse files Browse the repository at this point in the history
  • Loading branch information
ghost1face committed Jul 1, 2014
2 parents 47c1d06 + d42e048 commit f31d41f
Show file tree
Hide file tree
Showing 12 changed files with 172 additions and 23 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "knockout-kendo",
"version": "0.8.0",
"version": "0.8.1",
"main": "build/knockout-kendo.min.js",
"dependencies": {
"knockout": ">= 2.0"
Expand Down
67 changes: 59 additions & 8 deletions build/knockout-kendo.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* knockout-kendo 0.8.0
* knockout-kendo 0.8.1
* Copyright © 2013 Ryan Niemeyer & Telerik
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -221,7 +221,7 @@ ko.kendo.BindingFactory = function() {
}
},
disposeWhenNodeIsRemoved: element
}).extend({ throttle: 1 });
}).extend({ throttle: (options.throttle || options.throttle === 0) ? options.throttle : 1 });

//if option is not observable, then dispose up front after executing the logic once
if (!ko.isObservable(options[prop])) {
Expand Down Expand Up @@ -249,10 +249,14 @@ ko.kendo.BindingFactory = function() {

//bind to a single event
this.handleOneEvent = function(eventName, eventConfig, options, element, widget, childProp, context) {
var handler;
var handler = typeof eventConfig === "function" ? eventConfig : options[eventConfig.call];

//not an observable, use function as handler with normal KO args
if (eventConfig.call && typeof options[eventConfig.call] === "function") {
//call a function defined directly in the binding definition, supply options that were passed to the binding
if (typeof eventConfig === "function") {
handler = handler.bind(context.$data, options);
}
//use function passed in binding options as handler with normal KO args
else if (eventConfig.call && typeof options[eventConfig.call] === "function") {
handler = options[eventConfig.call].bind(context.$data, context.$data);
}
//option is observable, determine what to write to it
Expand Down Expand Up @@ -317,6 +321,7 @@ var extendAndRedraw = function(prop) {
};
};


//library is in a closure, use this private variable to reduce size of minified file
var createBinding = ko.kendo.bindingFactory.createBinding.bind(ko.kendo.bindingFactory);

Expand Down Expand Up @@ -648,20 +653,23 @@ createBinding({
max: function(newMax) {
this.options.max = newMax;
//make sure current value is still valid
if (this.value() > newMax) {
var value = this.value();
if ((value || value === 0) && value > newMax) {
this.value(newMax);
}
},
min: function(newMin) {
this.options.min = newMin;
//make sure that current value is still valid
if (this.value() < newMin) {
var value = this.value();
if ((value || value === 0) && value < newMin ) {
this.value(newMin);
}
}
}
});


createBinding({
name: "kendoPanelBar",
async: true
Expand All @@ -672,7 +680,8 @@ createBinding({
parent: "kendoPanelBar",
watch: {
enabled: ENABLE,
expanded: [EXPAND, COLLAPSE]
expanded: [EXPAND, COLLAPSE],
selected: [SELECT]
},
childProp: "item",
events: {
Expand All @@ -683,6 +692,10 @@ createBinding({
collapse: {
writeTo: EXPANDED,
value: false
},
select: {
writeTo: SELECTED,
value: VALUE
}
},
async: true
Expand Down Expand Up @@ -734,6 +747,44 @@ createBinding({
}
});

createBinding({
name: "kendoSortable",
defaultOption: DATA,
events: {
end: function(options, e) {
var dataKey = "__ko_kendo_sortable_data__",
data = e.action !== "receive" ? ko.dataFor(e.item[0]) : e.draggableEvent[dataKey],
items = options.data,
underlyingArray = options.data;

//remove item from its original position
if (e.action === "sort" || e.action === "remove") {
underlyingArray.splice(e.oldIndex, 1);

//keep track of the item between remove and receive
if (e.action === "remove") {
e.draggableEvent[dataKey] = data;
}
}

//add the item to its new position
if (e.action === "sort" || e.action === "receive") {
underlyingArray.splice(e.newIndex, 0, data);

//clear the data we passed
delete e.draggableEvent[dataKey];

//we are moving the item ourselves via the observableArray, cancel the draggable and hide the animation
$(e.draggableEvent.target).hide();
e.preventDefault();
}

//signal that the observableArray has changed now that we are done changing the array
items.valueHasMutated();
}
}
});

createBinding({
name: "kendoSplitter",
async: true
Expand Down
4 changes: 2 additions & 2 deletions build/knockout-kendo.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "knockout-kendo",
"version": "0.8.0",
"version": "0.8.1",
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-uglify": "0.x.x",
Expand Down
43 changes: 41 additions & 2 deletions spec/knockout-kendo-bindingSpecFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,14 @@ var generateEventHandlerTests = function(widgetConfig, testOptions) {
if (widgetConfig.events.hasOwnProperty(prop)) {
config = widgetConfig.events[prop];
config = typeof config === "string" ? { writeTo: config, value: config } : config;
vm[(config.call || config.writeTo) + "_spy"] = jasmine.createSpy();

//setup spies for testing that functions were called appropriately
if (typeof config === "function") {
vm[prop + "_spy"] = widgetConfig.events[prop] = jasmine.createSpy();
}
else {
vm[(config.call || config.writeTo) + "_spy"] = jasmine.createSpy();
}

if (config.writeTo) {
//create a computed (that calls the spy) to bind against the "writeTo" option
Expand All @@ -173,7 +180,7 @@ var generateEventHandlerTests = function(widgetConfig, testOptions) {
options += (options ? ", " : "{ ") + config.writeTo + ": " + config.writeTo + '_test';
}
}
else if (config.call) {
else if (typeof config.call === "string") {
vm[config.call] = vm[config.call + "_spy"];

if (options.indexOf(config.call + ": ") < 0) {
Expand All @@ -192,6 +199,7 @@ var generateEventHandlerTests = function(widgetConfig, testOptions) {
}
}

options = options || "{"
options += "}";
test = $(testOptions.html).first().attr("data-bind", widgetConfig.name + ": " + options);
setup(test, vm);
Expand Down Expand Up @@ -226,6 +234,37 @@ var generateEventHandlerTests = function(widgetConfig, testOptions) {
});
});
}
else if (typeof config === "function") {
//test calling a function
describe("when " + event + " event is triggered", function() {
it("should call the " + event + "handler with the appropriate arguments and context", function() {
var mostRecent;

//wait for widgets that are initialized asynchronously
waits(0);

runs(function() {
var spy = vm[event + "_spy"];
console.log(event, spy);

widget = $(el).data(widgetConfig.name);

spy.reset();

//trigger the event
widget.trigger(event);

mostRecent = spy.mostRecentCall;

expect(mostRecent.object).toBe(vm);

//if a function is configured directly in the widget config, then pass the options
expect(typeof mostRecent.args[0]).toBe("object");
expect(typeof mostRecent.args[1].preventDefault).toBe("function");
});
});
});
}
else {
//test calling a function
describe("when " + event + " event is triggered", function() {
Expand Down
8 changes: 8 additions & 0 deletions spec/knockout-kendoSortable.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
describe("ko.bindingHandlers.kendoSortable", function(){
//standard cases
ko.kendo.generateBindingSpecs("kendoSortable", {
html: "<div></div>"
});

//additional kendoSortable cases
});
1 change: 1 addition & 0 deletions spec/runner.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<script type="text/javascript" src="knockout-kendoRangeSlider.spec.js"></script>
<script type="text/javascript" src="knockout-kendoScheduler.spec.js"></script>
<script type="text/javascript" src="knockout-kendoSlider.spec.js"></script>
<script type="text/javascript" src="knockout-kendoSortable.spec.js"></script>
<script type="text/javascript" src="knockout-kendoSplitter.spec.js"></script>
<script type="text/javascript" src="knockout-kendoTabStrip.spec.js"></script>
<script type="text/javascript" src="knockout-kendoTimePicker.spec.js"></script>
Expand Down
14 changes: 9 additions & 5 deletions src/knockout-kendo-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ ko.kendo.BindingFactory = function() {
}
},
disposeWhenNodeIsRemoved: element
}).extend({ throttle: 1 });
}).extend({ throttle: (options.throttle || options.throttle === 0) ? options.throttle : 1 });

//if option is not observable, then dispose up front after executing the logic once
if (!ko.isObservable(options[prop])) {
Expand Down Expand Up @@ -217,10 +217,14 @@ ko.kendo.BindingFactory = function() {

//bind to a single event
this.handleOneEvent = function(eventName, eventConfig, options, element, widget, childProp, context) {
var handler;
var handler = typeof eventConfig === "function" ? eventConfig : options[eventConfig.call];

//not an observable, use function as handler with normal KO args
if (eventConfig.call && typeof options[eventConfig.call] === "function") {
//call a function defined directly in the binding definition, supply options that were passed to the binding
if (typeof eventConfig === "function") {
handler = handler.bind(context.$data, options);
}
//use function passed in binding options as handler with normal KO args
else if (eventConfig.call && typeof options[eventConfig.call] === "function") {
handler = options[eventConfig.call].bind(context.$data, context.$data);
}
//option is observable, determine what to write to it
Expand Down Expand Up @@ -283,4 +287,4 @@ var extendAndRedraw = function(prop) {
this.value(0.001 + this.value());
}
};
};
};
2 changes: 2 additions & 0 deletions src/knockout-kendo.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ kendo = kendo || window.kendo;

//import "knockout-kendoSlider.js"

//import "knockout-kendoSortable.js"

//import "knockout-kendoSplitter.js"

//import "knockout-kendoTabStrip.js"
Expand Down
8 changes: 5 additions & 3 deletions src/knockout-kendoNumericTextBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@ createBinding({
max: function(newMax) {
this.options.max = newMax;
//make sure current value is still valid
if (this.value() > newMax) {
var value = this.value();
if ((value || value === 0) && value > newMax) {
this.value(newMax);
}
},
min: function(newMin) {
this.options.min = newMin;
//make sure that current value is still valid
if (this.value() < newMin) {
var value = this.value();
if ((value || value === 0) && value < newMin ) {
this.value(newMin);
}
}
}
});
});
7 changes: 6 additions & 1 deletion src/knockout-kendoPanelBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ createBinding({
parent: "kendoPanelBar",
watch: {
enabled: ENABLE,
expanded: [EXPAND, COLLAPSE]
expanded: [EXPAND, COLLAPSE],
selected: [SELECT]
},
childProp: "item",
events: {
Expand All @@ -19,6 +20,10 @@ createBinding({
collapse: {
writeTo: EXPANDED,
value: false
},
select: {
writeTo: SELECTED,
value: VALUE
}
},
async: true
Expand Down
37 changes: 37 additions & 0 deletions src/knockout-kendoSortable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
createBinding({
name: "kendoSortable",
defaultOption: DATA,
events: {
end: function(options, e) {
var dataKey = "__ko_kendo_sortable_data__",
data = e.action !== "receive" ? ko.dataFor(e.item[0]) : e.draggableEvent[dataKey],
items = options.data,
underlyingArray = options.data;

//remove item from its original position
if (e.action === "sort" || e.action === "remove") {
underlyingArray.splice(e.oldIndex, 1);

//keep track of the item between remove and receive
if (e.action === "remove") {
e.draggableEvent[dataKey] = data;
}
}

//add the item to its new position
if (e.action === "sort" || e.action === "receive") {
underlyingArray.splice(e.newIndex, 0, data);

//clear the data we passed
delete e.draggableEvent[dataKey];

//we are moving the item ourselves via the observableArray, cancel the draggable and hide the animation
$(e.draggableEvent.target).hide();
e.preventDefault();
}

//signal that the observableArray has changed now that we are done changing the array
items.valueHasMutated();
}
}
});

0 comments on commit f31d41f

Please sign in to comment.