var widgetize = (function () { var exports = {}; var widgets = {}; widgets.poll = voting_widget; widgets.tictactoe = tictactoe_widget; widgets.todo = todo_widget; widgets.zform = zform; var widget_contents = {}; exports.widget_contents = widget_contents; function set_widget_in_message(row, widget_elem) { var content_holder = row.find('.message_content'); content_holder.empty().append(widget_elem); } exports.activate = function (in_opts) { var widget_type = in_opts.widget_type; var extra_data = in_opts.extra_data; var events = in_opts.events; var row = in_opts.row; var message = in_opts.message; var post_to_server = in_opts.post_to_server; events.shift(); if (!widgets[widget_type]) { blueslip.warn('unknown widget_type', widget_type); return; } var callback = function (data) { post_to_server({ msg_type: 'widget', data: data, }); }; if (row.attr('id').startsWith('zhome') && narrow_state.active()) { // Don't place widget in a home message row if we are narrowed // to active state return; } var widget_elem = widget_contents[message.id]; if (widget_elem) { set_widget_in_message(row, widget_elem); return; } // We depend on our widgets to use templates to build // the HTML that will eventually go in this div. widget_elem = $('