Skip to content

Instantly share code, notes, and snippets.

@justinvt
Created May 28, 2010 15:48
Show Gist options
  • Save justinvt/417315 to your computer and use it in GitHub Desktop.
Save justinvt/417315 to your computer and use it in GitHub Desktop.
function copyIntoClipboard(text) {
var flashId = 'flashId-HKxmj5';
/* Replace this with your clipboard.swf location */
//var clipboardSWF = 'http://appengine.bravo9.com/copy-into-clipboard/clipboard.swf';
var clipboardSWF = '/clipboard.swf';
if(!document.getElementById(flashId)) {
var div = document.createElement('div');
div.id = flashId;
document.body.appendChild(div);
}
document.getElementById(flashId).innerHTML = '';
var content = '<embed src="' +
clipboardSWF +
'" FlashVars="clipboard=' + encodeURIComponent(text) +
'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
document.getElementById(flashId).innerHTML = content;
}
var BrowserDetect = {
init: function () {
this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
this.version = this.searchVersion(navigator.userAgent)
|| this.searchVersion(navigator.appVersion)
|| "an unknown version";
this.OS = this.searchString(this.dataOS) || "an unknown OS";
},
searchString: function (data) {
for (var i=0;i<data.length;i++) {
var dataString = data[i].string;
var dataProp = data[i].prop;
this.versionSearchString = data[i].versionSearch || data[i].identity;
if (dataString) {
if (dataString.indexOf(data[i].subString) != -1)
return data[i].identity;
}
else if (dataProp)
return data[i].identity;
}
},
searchVersion: function (dataString) {
var index = dataString.indexOf(this.versionSearchString);
if (index == -1) return;
return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
},
dataBrowser: [
{
string: navigator.userAgent,
subString: "Chrome",
identity: "Chrome"
},
{ string: navigator.userAgent,
subString: "OmniWeb",
versionSearch: "OmniWeb/",
identity: "OmniWeb"
},
{
string: navigator.vendor,
subString: "Apple",
identity: "Safari",
versionSearch: "Version"
},
{
prop: window.opera,
identity: "Opera"
},
{
string: navigator.vendor,
subString: "iCab",
identity: "iCab"
},
{
string: navigator.vendor,
subString: "KDE",
identity: "Konqueror"
},
{
string: navigator.userAgent,
subString: "Firefox",
identity: "Firefox"
},
{
string: navigator.vendor,
subString: "Camino",
identity: "Camino"
},
{ // for newer Netscapes (6+)
string: navigator.userAgent,
subString: "Netscape",
identity: "Netscape"
},
{
string: navigator.userAgent,
subString: "MSIE",
identity: "Explorer",
versionSearch: "MSIE"
},
{
string: navigator.userAgent,
subString: "Gecko",
identity: "Mozilla",
versionSearch: "rv"
},
{ // for older Netscapes (4-)
string: navigator.userAgent,
subString: "Mozilla",
identity: "Netscape",
versionSearch: "Mozilla"
}
],
dataOS : [
{
string: navigator.platform,
subString: "Win",
identity: "Windows"
},
{
string: navigator.platform,
subString: "Mac",
identity: "Mac"
},
{
string: navigator.userAgent,
subString: "iPhone",
identity: "iPhone/iPod"
},
{
string: navigator.platform,
subString: "Linux",
identity: "Linux"
}
]
};
BrowserDetect.init();
function getmetaContents(mn){
var m = document.getElementsByTagName('meta');
for(var i in m){
if(m[i].name == mn){
return m[i].content;
}
}
}
function issueTracker(){
BrowserDetect.init()
var endpoint = "/issues"
//var browser = $.browser.version()
var browser = navigator.appName
var browser = navigator.appVersion;
var tracker = $("<div class='issue_tracker'><div class='expander'>+/-</div></div>")
var trackForm = $("<form action='" + endpoint + "' method='post'><textarea name='issue[description]'></textarea><input type='text' name='issue[browser]' value='" + BrowserDetect.browser + "'><input type='text' name='issue[version]'value='" + BrowserDetect.version+ "'><input type='text' name='issue[os]' value='" + BrowserDetect.OS + "'><input type='button' value='submit' class='submit'><input type='button' class='copy' value='Copy to clipboard'></form>")
var tags = $("<div class='tags'><span class='css'>css</span><span class='javascript'>javascript</span><span class='functional'>functional</span></div>")
var formatted_string = [BrowserDetect.browser, BrowserDetect.version, BrowserDetect.OS,getmetaContents("user_type"),getmetaContents("user_id")].join(" \/ ")
tracker.css({
zIndex:"10",
border:"solid 1px #aaa",
borderWidth:"0 0 1px 1px",
position:"fixed",
bottom:"0px",
right:"0px",
background:"#fff"
})
trackForm.css({
width:"300px",
height:"200px",
display:"none"
})
$("body").prepend(tracker)
$(tracker).append(trackForm)
$(trackForm).append(tags)
$(".expander").css({float:"right"})
$(".issue_tracker form").css({display:"none"})
$(".issue_tracker input[type='text'],.issue_tracker textarea").css({
display:"block",
margin:"0 0 10px 0",
width:"90%"
})
$(".issue_tracker .expander").css({cursor:"pointer"}).click(function(){
$(".issue_tracker form").toggle()
})
$(".issue_tracker .submit").click(function(){
var data = {}
$(this).parent().find("input[type='text'],textarea").each(function(){
data[$(this).attr("name")] = $(this).val()
})
alert(data.toSource())
$(this).parent().toggle()
$.post(endpoint,data,null)
})
var copypaste = $("<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000 width='110' height='14' class='clippy' id='clippy' > <param name='movie' value='/clippy.swf'/> <param name='allowScriptAccess' value='always' /> <param name='quality' value='high' /> <param name='scale' value='noscale' /> <param NAME='FlashVars' value='text=" + formatted_string + "'><param name='bgcolor' value='#FFFEEB'><param name='wmode' value='opaque'><embed src='/clippy.swf' width='110' height='14' name='clippy' quality='high' allowScriptAccess='always' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' FlashVars='text=" + formatted_string + "' bgcolor='#FFFEEB' wmode='opaque'/></object>")
$(".issue_tracker").append(copypaste);
// $("#clippy").trigger("click")
}
issueTracker()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment