Giter VIP home page Giter VIP logo

simple-dialog's People

Contributors

ovaqlab avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

simple-dialog's Issues

Copy to clipboard only works in onCancel not onSucces

Hi,
and thank you very much for simpleDialog.js.

I'm using it to popup messages from my Ajax operation success/failure.

In case of failure, I offer the user an option to copy the error message to clipboard.

For some reason (I'm not a Javascript/JQuery expert), the error text is only copied to clipboard in the
first example.

This works:

    <script type="text/javascript">
        $(document).ready(function () {
        $.simpleDialog({
        title:"<?php echo PHPLIST_REST_API_SUBSCRIPTION_HEADER_ERROR?>",
        message:"<?php echo PHPLIST_REST_API_SUBSCRIPTION_TEXT_ERROR.$result?>",
        confirmBtnText:"<?php echo PHPLIST_CLOSE_BUTTON?>",
        closeBtnText:"<?php echo PHPLIST_COPY_BUTTON?>",
        onCancel:function(){
            var text = "phpList Rest API\n";
            var email =  "<?php echo PHPLIST_REST_API_SUBSCRIPTION_EMAIL_TEXT.$subscriberEmail.'\n'?>";
            var error_text = "<?php echo $result .'\n'.$time.'\n'.$ip?>";
            var dummy = document.createElement("textarea");
            document.body.appendChild(dummy);
            dummy.value = text + email + error_text;
            dummy.select();
            document.execCommand("copy");
            document.body.removeChild(dummy);
            alert("<?php echo PHPLIST_CLIPBOARD_COPIED_TEXT;?>");
        }
    });
    });
</script>

This doesnt work (the clipboard contents remain unchanged):

    <script type="text/javascript">
        $(document).ready(function () {
        $.simpleDialog({
        title:"<?php echo PHPLIST_REST_API_SUBSCRIPTION_HEADER_ERROR?>",
        message:"<?php echo PHPLIST_REST_API_SUBSCRIPTION_TEXT_ERROR.$result?>",
        closeBtnText:"<?php echo PHPLIST_CLOSE_BUTTON?>",
        confirmBtnText:"<?php echo PHPLIST_COPY_BUTTON?>",
        onSuccess:function(){
            var text = "phpList Rest API\n";
            var email =  "<?php echo PHPLIST_REST_API_SUBSCRIPTION_EMAIL_TEXT.$subscriberEmail.'\n'?>";
            var error_text = "<?php echo $result .'\n'.$time.'\n'.$ip?>";
            var dummy = document.createElement("textarea");
            document.body.appendChild(dummy);
            dummy.value = text + email + error_text;
            dummy.select();
            document.execCommand("copy");
            document.body.removeChild(dummy);
            alert("<?php echo PHPLIST_CLIPBOARD_COPIED_TEXT;?>");
        }
    });
    });
</script>

When debugging, I noticed that dummy.selectectionStart and dummy.selectionEnd both point to the end of dummy.value.

I suspect that the reason is timing related (probably setTimeout in simpleDialogjs).

If I set a breakpoint on the line "dummy.select()" and immeadiately continue, it works.

Any ideas for a fix? Or, should I just use the onCancel alternative?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.