Title: [PATCH] Extending $.messager: a patch and a question
Post by: Juan Antonio Martínez on August 24, 2014, 04:23:00 AM
Hi all! I need a sort of messager.prompt, but using radiobuttons instead of textbox So edited jquery.easyui.min.js and added: ..... win.children("input.messager-input").focus(); return win; }, //JAMC /* msg is { val:text } collection for each radio button */ radio: function(title, msg, fn) { var str=""; $.each(msg,function(val,text){ str +='<br /><input type="radio" name="messager-radio" value="'+val+'">'+text+'\n'; }); var content = '<div class="messager-icon messager-question"></div>' + '<div>' + title + '</div>' + '<br/>' + str + '<div style="clear:both;"/>'; var buttons = {}; buttons[$.messager.defaults.ok] = function(){ win.window('close'); if (fn){ var val=$('input:radio[name="messager-radio"]:checked').val(); fn(val); return false; } }; buttons[$.messager.defaults.cancel] = function(){ win.window('close'); if (fn){ fn(); return false; } }; // _27f: createDialog() var win= _27f(title,content,buttons); return win; }, //END JAMC progress:function(_28e){ var _28f={bar:function(){ ....
This patch works fine for me, but seems a bit dirty because needs patching (obfuscated) library file My Question: ¿Whats the right way (tm) to extend $.messager to add different dialog styles without patching easyui library? Thanks in advance Juan Antonio
Title: Re: [PATCH] Extending $.messager: a patch and a question
Post by: stworthy on August 24, 2014, 07:57:28 AM
Try this: (function($){ function createDialog(title, content, buttons){ var win = $('<div class="messager-body"></div>').appendTo('body'); win.append(content); if (buttons){ var tb = $('<div class="messager-button"></div>').appendTo(win); for(var label in buttons){ $('<a></a>').attr('href', 'javascript:void(0)').text(label) .css('margin-left', 10) .bind('click', eval(buttons[label])) .appendTo(tb).linkbutton(); } } win.window({ title: title, noheader: (title?false:true), width: 300, height: 'auto', modal: true, collapsible: false, minimizable: false, maximizable: false, resizable: false, onClose: function(){ setTimeout(function(){ win.window('destroy'); }, 100); } }); win.window('window').addClass('messager-window'); win.children('div.messager-button').children('a:first').focus(); return win; } $.messager.radio = function(title, msg, fn){ var str=""; $.each(msg,function(val,text){ str +='<br /><input type="radio" name="messager-radio" value="'+val+'">'+text+'\n'; }); var content = '<div class="messager-icon messager-question"></div>' + '<div>' + title + '</div>' + '<br/>' + str + '<div style="clear:both;"/>'; var buttons = {}; buttons[$.messager.defaults.ok] = function(){ win.window('close'); if (fn){ var val=$('input:radio[name="messager-radio"]:checked').val(); fn(val); return false; } }; buttons[$.messager.defaults.cancel] = function(){ win.window('close'); if (fn){ fn(); return false; } }; var win = createDialog(title,content,buttons); win.children('input.messager-input').focus(); return win; } })(jQuery);
Title: Re: [PATCH] Extending $.messager: a patch and a question
Post by: Juan Antonio Martínez on August 24, 2014, 08:19:27 AM
Works fine! Thanks
But still unsure if replicate creatDialog() in my code is a good practice... (what about easyui-lib updates ?) Perhaps an idea for next releases is to provide a new messager.prompt implementing an user-definable text/radio/combo element as dialog body?
Thanks again for your time and your attention Juan Antonio
|