By Walter Downes on Thursday, 27 October 2016
Posted in General Issues
Likes 0
Views 192
Votes 0
Hi,
Does anyone know how can I override EasySocial's javascript controllers?
Thanks in advance
Hey there,

Currently that was not possible to override Javascript file in Easysocial at this point of time.
·
Thursday, 27 October 2016 18:15
·
0 Likes
·
0 Votes
·
0 Comments
·
I didn't mean a whole file, but only single controllers. I'm talking about OOP generalization. Something like this:


newController extends EasySocial.Controller.Videos.List{
getVideos : function(){

}
}

$('[data-videos-filter]').addController('newController', {
'{parent}': self,
"type": '...'
});
·
Thursday, 27 October 2016 19:21
·
0 Likes
·
0 Votes
·
0 Comments
·
Hello Walter,

It's not possible to extend the javascript controllers currently but you can always refer it in different ways. For instance,

[gist]
EasySocial.Controller('Videos.List.Custom', {
defaultOptions: {
}
}, function(self, opts, base) {
init: function() {
console.log(self.parent);
}
});

var someOtherController = $('[data-other-controller]').addController('EasySocial.Videos.List');

$('[data-some-element]').addController('EasySocial.Videos.List.Custom', {
"parent": someOtherController
});
[/gist]
·
Saturday, 29 October 2016 17:11
·
0 Likes
·
0 Votes
·
0 Comments
·
Hi.
Sorry for the delayed response.
I don't know why, but in your example the init() function returns allways 'undefined'.
·
Tuesday, 08 November 2016 18:43
·
0 Likes
·
0 Votes
·
0 Comments
·
Sorry, I forgot the curly braces. It should be


$('[data-some-element]').addController('EasySocial.Videos.List.Custom', {
"{parent}": someOtherController
});
·
Tuesday, 08 November 2016 19:13
·
0 Likes
·
0 Votes
·
0 Comments
·
Thanks for replies, but i found another solution


//Original controller
parent = new EasySocial.Controller('EasySocial.Controller.Videos.List');
//Extending default options list
$.extend(true,parent.defaultOptions,{
"{someOption}": "[selector]"
});

//Create new controller
EasySocial.Controller('Videos.List.Custom', {
defaultOptions: parent.defaultOptions //passing extended options
}, function(){
//get controller's body as an object
var child = parent.protoFactory.apply(null, arguments);
//Override parent's methods
$.extend(true,child,{
"getVideos": function(){
alert("debug");
}
});
return child;
});

//Apply new controller
$('[data-videos-listing]').addController('EasySocial.Controller.Videos.List.Custom');
·
Tuesday, 08 November 2016 21:25
·
0 Likes
·
0 Votes
·
0 Comments
·
Cool, glad that your issues are resolved now
·
Tuesday, 08 November 2016 21:56
·
0 Likes
·
0 Votes
·
0 Comments
·
View Full Post