Mobile Widget Custom Event with trigger

by kendomobile

HTML

<script src="https://getfirebug.com/firebug-lite.js"></script>
<script src="http://cdn.kendostatic.com/2013.2.716/js/kendo.all.min.js"></script>
<!-- Demo created for the book: Building Mobile Applications Using Kendo UI Mobile andASP.NET Web API.
http://www.packtpub.com/building-mobile-applications-with-kendoui-html5/book -->
<div id="output"> </div>

JavaScript

//create a mobile widget
var mobileWidget = new kendo.mobile.ui.Widget();

//attach a custom event
mobileWidget.bind("customEvent", function(e) {
    
    // mobileWidget object can be accessed 
    //inside this function as 
    //'e.sender' and 'this' . 
    output('customEvent fired');  
    
    //read event specific data if it exists
    if(e.eventData !== undefined){
        output('customEvent fired with data: '
                    + e.eventData);  
    }    
});

//trigger the event with some data 
mobileWidget.trigger("customEvent", 
                     { eventData:'Kendo UI is cool!' });

function output(data){
    $("#output").append(data);
    $("#output").append("<br/>");
    
}