Kolka
August 3, 2015, 3:26pm
1
window.WebixView = Backbone.View.extend({
tagName:"div", // <----- remove this
…
var el = this.el ? $(this.el)[0] : document.body; // <-- because in that,
//this.el == "<div></div>" and couldn't be empty
//and it's starts requiring jquery to work
…
});
maksim
August 3, 2015, 5:45pm
2
Yes, you are right, this code has no sense, as with or without tagName property, a DIV will be created if any other this.el value was not provided.
In next build, we will change this line like next
var el = window.$ ? $(this.el)[0] : this.el;
So it will use this.el always and will use jQuery only when jQuery is available on the page.
Kolka
August 4, 2015, 7:50am
3
That way isn’t really good.
var el = window.$ ? $(this.el)[0] : this.el;
If I wrote some code without jquery
new WebixView({
el: document.body,
…
});
it wouldn’t work if I add jquery to page.
This code should work -
var el = this.el ? (typeof this.el) == “string” ? $(this.el)[0] : this.el : document.body;
if el is empty - choose document.body, if el is string - try to find element by jquery, else - el is object.
maksim
August 4, 2015, 9:52am
4
Actually it will work correctly, jQuery itself checks is incoming parameter a string or a node. So
$(document.body)[0] === document.body
Kolka
August 17, 2015, 9:25am
6
Also you need to add support of Backbone.NativeView ( GitHub - akre54/Backbone.NativeView: A reference implementation of a native Backbone.View ) to make jQuery optional. Backbone depends on jQuery…
Something like that -
window.WebixView = (Backbone.NativeView ? Backbone.NativeView : Backbone.View).extend({ … });