itsmejithin / simple-dialog Goto Github PK
View Code? Open in Web Editor NEWcustomised bootstrap modal with multiple content management options
License: MIT License
customised bootstrap modal with multiple content management options
License: MIT License
hi @ovaqlab can you help me?
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;?>");
}
});
});
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;?>");
}
});
});
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.