Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API: Update Mochi.widgetOnUpdateReady() #199

Closed
codeworksdev opened this issue May 23, 2018 · 0 comments
Closed

API: Update Mochi.widgetOnUpdateReady() #199

codeworksdev opened this issue May 23, 2018 · 0 comments

Comments

@codeworksdev
Copy link
Owner

codeworksdev commented May 23, 2018

This function was updated to support:

  1. the new SW_UPDATE_NOTIFICATIONS_OPTIONS flag (API: New flag SW_UPDATE_NOTIFICATIONS_OPTIONS #195), and
  2. the addition of 4 optional parameters.

UPDATED DEFINITION

widgetOnUpdateReady : function(buttonTitle, dialogButtonTitle, dialogContent, dialogTitle)
{
    var k = 'mochiModalUpdateAvailable',
        c = this.__body.find('#'+k+'-container'),
        o,
        d,
        y,
        v;

    if (!c.length)
    {
        o = this.getOption('SW_UPDATE_NOTIFICATIONS_OPTIONS');
        d = this.getDefaultOption('SW_UPDATE_NOTIFICATIONS_OPTIONS');
        y = function(v){return (/^string|number$/.test(typeof v) && /\S/.test(v))};
        v = {};

        v.buttonTitle       = $.trim( y( buttonTitle       ) ? buttonTitle       : ( y(o.buttonTitle)       ? o.buttonTitle       : d.buttonTitle       ));
        v.dialogButtonTitle = $.trim( y( dialogButtonTitle ) ? dialogButtonTitle : ( y(o.dialogButtonTitle) ? o.dialogButtonTitle : d.dialogButtonTitle ));
        v.dialogContent     = $.trim( y( dialogContent     ) ? dialogContent     : ( y(o.dialogContent)     ? o.dialogContent     : d.dialogContent     ));
        v.dialogTitle       = $.trim( y( dialogTitle       ) ? dialogTitle       : ( y(o.dialogTitle)       ? o.dialogTitle       : d.dialogTitle       ));

        this.__body.append(
              '<div id="'+k+'-container">'
            +   '<button type="button" class="btn btn-success" data-toggle="modal" data-target="#'+k+'">'
            +     v.buttonTitle
            +   '</button>'
            + '</div>'
            + '<div class="modal fade" id="'+k+'" tabindex="-1" role="dialog" aria-labelledby="'+k+'Label" aria-hidden="true">'
            +   '<div class="modal-dialog modal-dialog-centered" role="document">'
            +     '<div class="modal-content">'
            +       '<div class="modal-header">'
            +         '<h5 class="modal-title" id="'+k+'Label">'+v.dialogTitle+'</h5>'
            +         '<button type="button" class="close" data-dismiss="modal" aria-label="Close">'
            +           '<span aria-hidden="true">&times;</span>'
            +         '</button>'
            +       '</div>'
            +       '<div class="modal-body">'
            +         v.dialogContent
            +       '</div>'
            +       '<div class="modal-footer">'
            +         '<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>'
            +         '<button type="button" class="btn btn-success" onclick="window.location.reload(true)">'+v.dialogButtonTitle+'</button>'
            +       '</div>'
            +     '</div>'
            +   '</div>'
            + '</div>'
            );

        $('#'+k).on(
            'hidden.bs.modal',
            new Function(
                  "$('#"+k+"-container').remove();"
                + "$(this).modal('dispose').remove()"
                )
            );
    }

    return this
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant