src/trumbowyg.js
function (title, fields, cmd) {
            var t = this,
                prefix = t.o.prefix,
                lg = t.lang,
                html = '';

            $.each(fields, function (fieldName, field) {
                var l = field.label || fieldName,
                    n = field.name || fieldName,
                    a = field.attributes || {};

                var attr = Object.keys(a).map(function (prop) {
                    return prop + '="' + a[prop] + '"';
                }).join(' ');

                html += '<label><input type="' + (field.type || 'text') + '" name="' + n + '"' +
                    (field.type === 'checkbox' && field.value ? ' checked="checked"' : ' value="' + (field.value || '').replace(/"/g, '&quot;')) +
                    '"' + attr + '><span class="' + prefix + 'input-infos"><span>' +
                    (lg[l] ? lg[l] : l) +
                    '</span></span></label>';
            });

            return t.openModal(title, html)
                .on(CONFIRM_EVENT, function () {
                    var $form = $('form', $(this)),
                        valid = true,
                        values = {};

                    $.each(fields, function (fieldName, field) {
                        var n = field.name || fieldName;

                        var $field = $('input[name="' + n + '"]', $form),
                            inputType = $field.attr('type');

                        switch (inputType.toLowerCase()) {
                            case 'checkbox':
                                values[n] = $field.is(':checked');
                                break;
                            case 'radio':
                                values[n] = $field.filter(':checked').val();
                                break;
                            default:
                                values[n] = $.trim($field.val());
                                break;
                        }
                        // Validate value
                        if (field.required && values[n] === '') {
                            valid = false;
                            t.addErrorOnModalField($field, t.lang.required);
                        } else if (field.pattern && !field.pattern.test(values[n])) {
                            valid = false;
                            t.addErrorOnModalField($field, field.patternError);
                        }
                    });

                    if (valid) {
                        t.restoreRange();

                        if (cmd(values, fields)) {
                            t.syncCode();
                            t.$c.trigger('tbwchange');
                            t.closeModal();
                            $(this).off(CONFIRM_EVENT);
                        }
                    }
                })
                .one(CANCEL_EVENT, function () {
                    $(this).off(CONFIRM_EVENT);
                    t.closeModal();
                });
        }
function (title, fields, cmd) {
            var t = this,
                prefix = t.o.prefix,
                lg = t.lang,
                html = '';

            $.each(fields, function (fieldName, field) {
                var l = field.label || fieldName,
                    n = field.name || fieldName,
                    a = field.attributes || {};

                var attr = Object.keys(a).map(function (prop) {
                    return prop + '="' + a[prop] + '"';
                }).join(' ');

                html += '<label><input type="' + (field.type || 'text') + '" name="' + n + '"' +
                    (field.type === 'checkbox' && field.value ? ' checked="checked"' : ' value="' + (field.value || '').replace(/"/g, '&quot;')) +
                    '"' + attr + '><span class="' + prefix + 'input-infos"><span>' +
                    (lg[l] ? lg[l] : l) +
                    '</span></span></label>';
            });

            return t.openModal(title, html)
                .on(CONFIRM_EVENT, function () {
                    var $form = $('form', $(this)),
                        valid = true,
                        values = {};

                    $.each(fields, function (fieldName, field) {
                        var n = field.name || fieldName;

                        var $field = $('input[name="' + n + '"]', $form),
                            inputType = $field.attr('type');

                        switch (inputType.toLowerCase()) {
                            case 'checkbox':
                                values[n] = $field.is(':checked');
                                break;
                            case 'radio':
                                values[n] = $field.filter(':checked').val();
                                break;
                            default:
                                values[n] = $.trim($field.val());
                                break;
                        }
                        // Validate value
                        if (field.required && values[n] === '') {
                            valid = false;
                            t.addErrorOnModalField($field, t.lang.required);
                        } else if (field.pattern && !field.pattern.test(values[n])) {
                            valid = false;
                            t.addErrorOnModalField($field, field.patternError);
                        }
                    });

                    if (valid) {
                        t.restoreRange();

                        if (cmd(values, fields)) {
                            t.syncCode();
                            t.$c.trigger('tbwchange');
                            t.closeModal();
                            $(this).off(CONFIRM_EVENT);
                        }
                    }
                })
                .one(CANCEL_EVENT, function () {
                    $(this).off(CONFIRM_EVENT);
                    t.closeModal();
                });
        }
function ( title , fields , cmd ) { var t = this , prefix = t . o . prefix , lg = t . lang , html = '' ; $ . each ( fields , function ( fieldName , field ) { var l = field . label || fieldName , n = field . name || fieldName , a = field . attributes || { } ; var attr = Object . keys ( a ) . map ( function ( prop ) { return prop + '="' + a [ prop ] + '"' ; } ) . join ( ' ' ) ; html += '<label><input type="' + ( field . type || 'text' ) + '" name="' + n + '"' + ( field . type === 'checkbox' && field . value ? ' checked="checked"' : ' value="' + ( field . value || '' ) . replace ( / " / g , '&quot;' ) ) + '"' + attr + '><span class="' + prefix + 'input-infos"><span>' + ( lg [ l ] ? lg [ l ] : l ) + '</span></span></label>' ; } ) ; return t . openModal ( title , html ) . on ( CONFIRM_EVENT , function ( ) { var $form = $ ( 'form' , $ ( this ) ) , valid = true , values = { } ; $ . each ( fields , function ( fieldName , field ) { var n = field . name || fieldName ; var $field = $ ( 'input[name="' + n + '"]' , $form ) , inputType = $field . attr ( 'type' ) ; switch ( inputType . toLowerCase ( ) ) { case 'checkbox' : values [ n ] = $field . is ( ':checked' ) ; break ; case 'radio' : values [ n ] = $field . filter ( ':checked' ) . val ( ) ; break ; default : values [ n ] = $ . trim ( $field . val ( ) ) ; break ; } // Validate value if ( field . required && values [ n ] === '' ) { valid = false ; t . addErrorOnModalField ( $field , t . lang . required ) ; } else if ( field . pattern && ! field . pattern . test ( values [ n ] ) ) { valid = false ; t . addErrorOnModalField ( $field , field . patternError ) ; } } ) ; if ( valid ) { t . restoreRange ( ) ; if ( cmd ( values , fields ) ) { t . syncCode ( ) ; t . $c . trigger ( 'tbwchange' ) ; t . closeModal ( ) ; $ ( this ) . off ( CONFIRM_EVENT ) ; } } } ) . one ( CANCEL_EVENT , function ( ) { $ ( this ) . off ( CONFIRM_EVENT ) ; t . closeModal ( ) ; } ) ; }
Preformatted build and management modal
Preformatted build and management modal