zeroclipboard works half the time

41 views Asked by At

For some reason, this zeroclipboard implementation only works about half the time when I refresh the page. It is being served as https on a fully https page. One interesting thing to note is that I can tell when I refresh the page that it's not going to work, as the bit.ly link seems to initially turn blue (default a-link color), then immediately switch to my style.css settings.

<script src="./js/jquery-2.1.3.min.js" type="text/javascript"></script>
<script src="./js/ZeroClipboard.js" type="text/javascript"></script>
<script src="./js/zeroclip.js"></script>

Here's the content of my zeroclip.js:

ZeroClipboard.setMoviePath('http://www.ultrasoundoftheweek.com/clipshare/js/ZeroClipboard10.swf');
var clip2 = new ZeroClipboard.Client();
jQuery(document).ready(function() {
    clip2.addEventListener('mousedown', function() {
        var alltext = $('#result').text();
        clip2.setText(alltext);
    });
    clip2.addEventListener('complete', function() {
        $("#copybutton").html("<font color=\"#434343\"><strike>Copy Link to Clipboard</strike></font><font color=\"#D00000\"> Copied</font>");
        //alert('Copied');
    });
    clip2.glue('copyplain');
});

HTML:

<h2 align="center">ULA ClipShare Uploader</h2>
<br>
<div style="overflow: hidden;">
<div class="topbox">
<h4 class="textl"><a href="https://www.ultrasoundoftheweek.com/clipshare/share.php?&f=e1cQsRltii" >http://bit.ly/1JKAAuJ</a></h4>
<h4 class="textr">Email this Link</h4>
<div class="clear"></div>
<div class="topbox">
<div class="textl" id="copyplain"><button id="copybutton">Copy Link to Clipboard</button></div>
<div id="result" class="result" style="display:none;">http://bit.ly/1JKAAuJ</div>

CSS:

body {
    height: 100%;
    width: 100%;
    text-align: center;
}
#centerContainer {
    height: auto;
    min-height: 100%;
    max-width: 900px;
    text-align: left;
    margin: 0px auto;
    padding-left: 5px;
    padding-right: 5px;
}
P {
    FONT-SIZE: 8pt;
    COLOR: #000000;
    FONT-FAMILY: Oxygen
}
TD {
    FONT-SIZE: 8pt;
    COLOR: #000000;
    FONT-FAMILY: Oxygen
}
h2 {
    FONT-FAMILY: Oxygen
}
h4 {
    FONT-FAMILY: Oxygen
}
.topbox {
    display: table;
    width: 100%;
    height: auto;
    margin: 0px 0px;
}
.topbox .textl {
    display: table-cell;
    height: 32px;
    vertical-align: middle;
    display: inline-block;
}
.topbox .textr {
    display: block;
    float: right;
}
.topbox .clear {
    clear: both;
}
#copyplain {
    position: absolute
}
#copywrite {
    clear: both;
    position: relative;
    z-index: 10;
    height: 3em;
    margin-top: -3em;
}
1

There are 1 answers

0
UltrasoundJelly On

In case anyone else comes across this problem, I was able to solve it after an hour of tinkering. The code works fine if I place the <script src="./js/zeroclip.js"></script> line right above </body>. I guess for some reason it wasn't liking my jQuery(document).ready(function().