mirror of
https://github.com/Tygs/0bin.git
synced 2023-08-10 21:13:00 +03:00
Clipboard works but no virual feedback on over
This commit is contained in:
parent
ea93fcf35e
commit
3c1bd1b16e
@ -156,10 +156,9 @@ li.L5, li.L6, li.L7, li.L8, li.L9
|
|||||||
background: inherit;
|
background: inherit;
|
||||||
}
|
}
|
||||||
|
|
||||||
#clip-container div:hover,
|
a#clip-button.hover{
|
||||||
#clip-button:hover,
|
|
||||||
#clip-button a:hover{
|
|
||||||
cursor:pointer;
|
cursor:pointer;
|
||||||
|
text-decoration:underline;
|
||||||
}
|
}
|
||||||
|
|
||||||
#copy-success, #short-url-success {
|
#copy-success, #short-url-success {
|
||||||
|
@ -2,12 +2,12 @@
|
|||||||
// Author: Joseph Huckaby
|
// Author: Joseph Huckaby
|
||||||
|
|
||||||
var ZeroClipboard = {
|
var ZeroClipboard = {
|
||||||
|
|
||||||
version: "1.0.7",
|
version: "1.0.7",
|
||||||
clients: {}, // registered upload clients on page, indexed by id
|
clients: {}, // registered upload clients on page, indexed by id
|
||||||
moviePath: 'ZeroClipboard.swf', // URL to movie
|
moviePath: 'ZeroClipboard.swf', // URL to movie
|
||||||
nextId: 1, // ID of next movie
|
nextId: 1, // ID of next movie
|
||||||
|
|
||||||
$: function(thingy) {
|
$: function(thingy) {
|
||||||
// simple DOM lookup utility function
|
// simple DOM lookup utility function
|
||||||
if (typeof(thingy) == 'string') thingy = document.getElementById(thingy);
|
if (typeof(thingy) == 'string') thingy = document.getElementById(thingy);
|
||||||
@ -34,31 +34,31 @@ var ZeroClipboard = {
|
|||||||
}
|
}
|
||||||
return thingy;
|
return thingy;
|
||||||
},
|
},
|
||||||
|
|
||||||
setMoviePath: function(path) {
|
setMoviePath: function(path) {
|
||||||
// set path to ZeroClipboard.swf
|
// set path to ZeroClipboard.swf
|
||||||
this.moviePath = path;
|
this.moviePath = path;
|
||||||
},
|
},
|
||||||
|
|
||||||
dispatch: function(id, eventName, args) {
|
dispatch: function(id, eventName, args) {
|
||||||
// receive event from flash movie, send to client
|
// receive event from flash movie, send to client
|
||||||
var client = this.clients[id];
|
var client = this.clients[id];
|
||||||
if (client) {
|
if (client) {
|
||||||
client.receiveEvent(eventName, args);
|
client.receiveEvent(eventName, args);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
register: function(id, client) {
|
register: function(id, client) {
|
||||||
// register new client to receive events
|
// register new client to receive events
|
||||||
this.clients[id] = client;
|
this.clients[id] = client;
|
||||||
},
|
},
|
||||||
|
|
||||||
getDOMObjectPosition: function(obj, stopObj) {
|
getDOMObjectPosition: function(obj, stopObj) {
|
||||||
// get absolute coordinates for dom element
|
// get absolute coordinates for dom element
|
||||||
var info = {
|
var info = {
|
||||||
left: 0,
|
left: 0,
|
||||||
top: 0,
|
top: 0,
|
||||||
width: obj.width ? obj.width : obj.offsetWidth,
|
width: obj.width ? obj.width : obj.offsetWidth,
|
||||||
height: obj.height ? obj.height : obj.offsetHeight
|
height: obj.height ? obj.height : obj.offsetHeight
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -70,25 +70,25 @@ var ZeroClipboard = {
|
|||||||
|
|
||||||
return info;
|
return info;
|
||||||
},
|
},
|
||||||
|
|
||||||
Client: function(elem) {
|
Client: function(elem) {
|
||||||
// constructor for new simple upload client
|
// constructor for new simple upload client
|
||||||
this.handlers = {};
|
this.handlers = {};
|
||||||
|
|
||||||
// unique ID
|
// unique ID
|
||||||
this.id = ZeroClipboard.nextId++;
|
this.id = ZeroClipboard.nextId++;
|
||||||
this.movieId = 'ZeroClipboardMovie_' + this.id;
|
this.movieId = 'ZeroClipboardMovie_' + this.id;
|
||||||
|
|
||||||
// register client with singleton to receive flash events
|
// register client with singleton to receive flash events
|
||||||
ZeroClipboard.register(this.id, this);
|
ZeroClipboard.register(this.id, this);
|
||||||
|
|
||||||
// create movie
|
// create movie
|
||||||
if (elem) this.glue(elem);
|
if (elem) this.glue(elem);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ZeroClipboard.Client.prototype = {
|
ZeroClipboard.Client.prototype = {
|
||||||
|
|
||||||
id: 0, // unique ID for us
|
id: 0, // unique ID for us
|
||||||
ready: false, // whether movie is ready to receive events or not
|
ready: false, // whether movie is ready to receive events or not
|
||||||
movie: null, // reference to movie object
|
movie: null, // reference to movie object
|
||||||
@ -96,28 +96,28 @@ ZeroClipboard.Client.prototype = {
|
|||||||
handCursorEnabled: true, // whether to show hand cursor, or default pointer cursor
|
handCursorEnabled: true, // whether to show hand cursor, or default pointer cursor
|
||||||
cssEffects: true, // enable CSS mouse effects on dom container
|
cssEffects: true, // enable CSS mouse effects on dom container
|
||||||
handlers: null, // user event handlers
|
handlers: null, // user event handlers
|
||||||
|
|
||||||
glue: function(elem, appendElem, stylesToAdd) {
|
glue: function(elem, appendElem, stylesToAdd) {
|
||||||
// glue to DOM element
|
// glue to DOM element
|
||||||
// elem can be ID or actual DOM element object
|
// elem can be ID or actual DOM element object
|
||||||
this.domElement = ZeroClipboard.$(elem);
|
this.domElement = ZeroClipboard.$(elem);
|
||||||
|
|
||||||
// float just above object, or zIndex 99 if dom element isn't set
|
// float just above object, or zIndex 99 if dom element isn't set
|
||||||
var zIndex = 99;
|
var zIndex = 99;
|
||||||
if (this.domElement.style.zIndex) {
|
if (this.domElement.style.zIndex) {
|
||||||
zIndex = parseInt(this.domElement.style.zIndex, 10) + 1;
|
zIndex = parseInt(this.domElement.style.zIndex, 10) + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof(appendElem) == 'string') {
|
if (typeof(appendElem) == 'string') {
|
||||||
appendElem = ZeroClipboard.$(appendElem);
|
appendElem = ZeroClipboard.$(appendElem);
|
||||||
}
|
}
|
||||||
else if (typeof(appendElem) == 'undefined') {
|
else if (typeof(appendElem) == 'undefined') {
|
||||||
appendElem = document.getElementsByTagName('body')[0];
|
appendElem = document.getElementsByTagName('body')[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
// find X/Y position of domElement
|
// find X/Y position of domElement
|
||||||
var box = ZeroClipboard.getDOMObjectPosition(this.domElement, appendElem);
|
var box = ZeroClipboard.getDOMObjectPosition(this.domElement, appendElem);
|
||||||
|
|
||||||
// create floating DIV above element
|
// create floating DIV above element
|
||||||
this.div = document.createElement('div');
|
this.div = document.createElement('div');
|
||||||
var style = this.div.style;
|
var style = this.div.style;
|
||||||
@ -127,27 +127,27 @@ ZeroClipboard.Client.prototype = {
|
|||||||
style.width = '' + box.width + 'px';
|
style.width = '' + box.width + 'px';
|
||||||
style.height = '' + box.height + 'px';
|
style.height = '' + box.height + 'px';
|
||||||
style.zIndex = zIndex;
|
style.zIndex = zIndex;
|
||||||
|
|
||||||
if (typeof(stylesToAdd) == 'object') {
|
if (typeof(stylesToAdd) == 'object') {
|
||||||
for (addedStyle in stylesToAdd) {
|
for (addedStyle in stylesToAdd) {
|
||||||
style[addedStyle] = stylesToAdd[addedStyle];
|
style[addedStyle] = stylesToAdd[addedStyle];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// style.backgroundColor = '#f00'; // debug
|
//style.backgroundColor = '#f00'; // debug
|
||||||
|
|
||||||
appendElem.appendChild(this.div);
|
appendElem.appendChild(this.div);
|
||||||
|
|
||||||
this.div.innerHTML = this.getHTML( box.width, box.height );
|
this.div.innerHTML = this.getHTML( box.width, box.height );
|
||||||
},
|
},
|
||||||
|
|
||||||
getHTML: function(width, height) {
|
getHTML: function(width, height) {
|
||||||
// return HTML for movie
|
// return HTML for movie
|
||||||
var html = '';
|
var html = '';
|
||||||
var flashvars = 'id=' + this.id +
|
var flashvars = 'id=' + this.id +
|
||||||
'&width=' + width +
|
'&width=' + width +
|
||||||
'&height=' + height;
|
'&height=' + height;
|
||||||
|
|
||||||
if (navigator.userAgent.match(/MSIE/)) {
|
if (navigator.userAgent.match(/MSIE/)) {
|
||||||
// IE gets an OBJECT tag
|
// IE gets an OBJECT tag
|
||||||
var protocol = location.href.match(/^https/i) ? 'https://' : 'http://';
|
var protocol = location.href.match(/^https/i) ? 'https://' : 'http://';
|
||||||
@ -159,33 +159,33 @@ ZeroClipboard.Client.prototype = {
|
|||||||
}
|
}
|
||||||
return html;
|
return html;
|
||||||
},
|
},
|
||||||
|
|
||||||
hide: function() {
|
hide: function() {
|
||||||
// temporarily hide floater offscreen
|
// temporarily hide floater offscreen
|
||||||
if (this.div) {
|
if (this.div) {
|
||||||
this.div.style.left = '-2000px';
|
this.div.style.left = '-2000px';
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
show: function() {
|
show: function() {
|
||||||
// show ourselves after a call to hide()
|
// show ourselves after a call to hide()
|
||||||
this.reposition();
|
this.reposition();
|
||||||
},
|
},
|
||||||
|
|
||||||
destroy: function() {
|
destroy: function() {
|
||||||
// destroy control and floater
|
// destroy control and floater
|
||||||
if (this.domElement && this.div) {
|
if (this.domElement && this.div) {
|
||||||
this.hide();
|
this.hide();
|
||||||
this.div.innerHTML = '';
|
this.div.innerHTML = '';
|
||||||
|
|
||||||
var body = document.getElementsByTagName('body')[0];
|
var body = document.getElementsByTagName('body')[0];
|
||||||
try { body.removeChild( this.div ); } catch(e) {;}
|
try { body.removeChild( this.div ); } catch(e) {;}
|
||||||
|
|
||||||
this.domElement = null;
|
this.domElement = null;
|
||||||
this.div = null;
|
this.div = null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
reposition: function(elem) {
|
reposition: function(elem) {
|
||||||
// reposition our floating div, optionally to new container
|
// reposition our floating div, optionally to new container
|
||||||
// warning: container CANNOT change size, only position
|
// warning: container CANNOT change size, only position
|
||||||
@ -193,7 +193,7 @@ ZeroClipboard.Client.prototype = {
|
|||||||
this.domElement = ZeroClipboard.$(elem);
|
this.domElement = ZeroClipboard.$(elem);
|
||||||
if (!this.domElement) this.hide();
|
if (!this.domElement) this.hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.domElement && this.div) {
|
if (this.domElement && this.div) {
|
||||||
var box = ZeroClipboard.getDOMObjectPosition(this.domElement);
|
var box = ZeroClipboard.getDOMObjectPosition(this.domElement);
|
||||||
var style = this.div.style;
|
var style = this.div.style;
|
||||||
@ -201,13 +201,13 @@ ZeroClipboard.Client.prototype = {
|
|||||||
style.top = '' + box.top + 'px';
|
style.top = '' + box.top + 'px';
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
setText: function(newText) {
|
setText: function(newText) {
|
||||||
// set text to be copied to clipboard
|
// set text to be copied to clipboard
|
||||||
this.clipText = newText;
|
this.clipText = newText;
|
||||||
if (this.ready) this.movie.setText(newText);
|
if (this.ready) this.movie.setText(newText);
|
||||||
},
|
},
|
||||||
|
|
||||||
addEventListener: function(eventName, func) {
|
addEventListener: function(eventName, func) {
|
||||||
// add user event listener for event
|
// add user event listener for event
|
||||||
// event types: load, queueStart, fileStart, fileComplete, queueComplete, progress, error, cancel
|
// event types: load, queueStart, fileStart, fileComplete, queueComplete, progress, error, cancel
|
||||||
@ -215,22 +215,22 @@ ZeroClipboard.Client.prototype = {
|
|||||||
if (!this.handlers[eventName]) this.handlers[eventName] = [];
|
if (!this.handlers[eventName]) this.handlers[eventName] = [];
|
||||||
this.handlers[eventName].push(func);
|
this.handlers[eventName].push(func);
|
||||||
},
|
},
|
||||||
|
|
||||||
setHandCursor: function(enabled) {
|
setHandCursor: function(enabled) {
|
||||||
// enable hand cursor (true), or default arrow cursor (false)
|
// enable hand cursor (true), or default arrow cursor (false)
|
||||||
this.handCursorEnabled = enabled;
|
this.handCursorEnabled = enabled;
|
||||||
if (this.ready) this.movie.setHandCursor(enabled);
|
if (this.ready) this.movie.setHandCursor(enabled);
|
||||||
},
|
},
|
||||||
|
|
||||||
setCSSEffects: function(enabled) {
|
setCSSEffects: function(enabled) {
|
||||||
// enable or disable CSS effects on DOM container
|
// enable or disable CSS effects on DOM container
|
||||||
this.cssEffects = !!enabled;
|
this.cssEffects = !!enabled;
|
||||||
},
|
},
|
||||||
|
|
||||||
receiveEvent: function(eventName, args) {
|
receiveEvent: function(eventName, args) {
|
||||||
// receive event from flash
|
// receive event from flash
|
||||||
eventName = eventName.toString().toLowerCase().replace(/^on/, '');
|
eventName = eventName.toString().toLowerCase().replace(/^on/, '');
|
||||||
|
|
||||||
// special behavior for certain events
|
// special behavior for certain events
|
||||||
switch (eventName) {
|
switch (eventName) {
|
||||||
case 'load':
|
case 'load':
|
||||||
@ -242,7 +242,7 @@ ZeroClipboard.Client.prototype = {
|
|||||||
setTimeout( function() { self.receiveEvent('load', null); }, 1 );
|
setTimeout( function() { self.receiveEvent('load', null); }, 1 );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// firefox on pc needs a "kick" in order to set these in certain cases
|
// firefox on pc needs a "kick" in order to set these in certain cases
|
||||||
if (!this.ready && navigator.userAgent.match(/Firefox/) && navigator.userAgent.match(/Windows/)) {
|
if (!this.ready && navigator.userAgent.match(/Firefox/) && navigator.userAgent.match(/Windows/)) {
|
||||||
var self = this;
|
var self = this;
|
||||||
@ -250,19 +250,19 @@ ZeroClipboard.Client.prototype = {
|
|||||||
this.ready = true;
|
this.ready = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.ready = true;
|
this.ready = true;
|
||||||
this.movie.setText( this.clipText );
|
this.movie.setText( this.clipText );
|
||||||
this.movie.setHandCursor( this.handCursorEnabled );
|
this.movie.setHandCursor( this.handCursorEnabled );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'mouseover':
|
case 'mouseover':
|
||||||
if (this.domElement && this.cssEffects) {
|
if (this.domElement && this.cssEffects) {
|
||||||
this.domElement.addClass('hover');
|
this.domElement.addClass('hover');
|
||||||
if (this.recoverActive) this.domElement.addClass('active');
|
if (this.recoverActive) this.domElement.addClass('active');
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'mouseout':
|
case 'mouseout':
|
||||||
if (this.domElement && this.cssEffects) {
|
if (this.domElement && this.cssEffects) {
|
||||||
this.recoverActive = false;
|
this.recoverActive = false;
|
||||||
@ -273,13 +273,13 @@ ZeroClipboard.Client.prototype = {
|
|||||||
this.domElement.removeClass('hover');
|
this.domElement.removeClass('hover');
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'mousedown':
|
case 'mousedown':
|
||||||
if (this.domElement && this.cssEffects) {
|
if (this.domElement && this.cssEffects) {
|
||||||
this.domElement.addClass('active');
|
this.domElement.addClass('active');
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'mouseup':
|
case 'mouseup':
|
||||||
if (this.domElement && this.cssEffects) {
|
if (this.domElement && this.cssEffects) {
|
||||||
this.domElement.removeClass('active');
|
this.domElement.removeClass('active');
|
||||||
@ -287,11 +287,11 @@ ZeroClipboard.Client.prototype = {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
} // switch eventName
|
} // switch eventName
|
||||||
|
|
||||||
if (this.handlers[eventName]) {
|
if (this.handlers[eventName]) {
|
||||||
for (var idx = 0, len = this.handlers[eventName].length; idx < len; idx++) {
|
for (var idx = 0, len = this.handlers[eventName].length; idx < len; idx++) {
|
||||||
var func = this.handlers[eventName][idx];
|
var func = this.handlers[eventName][idx];
|
||||||
|
|
||||||
if (typeof(func) == 'function') {
|
if (typeof(func) == 'function') {
|
||||||
// actual function reference
|
// actual function reference
|
||||||
func(this, args);
|
func(this, args);
|
||||||
@ -307,5 +307,5 @@ ZeroClipboard.Client.prototype = {
|
|||||||
} // foreach event handler defined
|
} // foreach event handler defined
|
||||||
} // user defined handler for event
|
} // user defined handler for event
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -81,6 +81,13 @@ zerobin = {
|
|||||||
}else{
|
}else{
|
||||||
return 'Sorry your browser does not support LocalStorage, We cannot display your previous pastes.';
|
return 'Sorry your browser does not support LocalStorage, We cannot display your previous pastes.';
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
get_paste_content: function(){
|
||||||
|
var content_clone = '' ;
|
||||||
|
$("#paste-content li").each(function(index) {
|
||||||
|
content_clone = content_clone + $(this).text() + '\n';
|
||||||
|
});
|
||||||
|
return content_clone;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -152,17 +159,15 @@ if (content && key) {
|
|||||||
|
|
||||||
/* Setup flash clipboard button */
|
/* Setup flash clipboard button */
|
||||||
ZeroClipboard.setMoviePath('/static/js/ZeroClipboard.swf' );
|
ZeroClipboard.setMoviePath('/static/js/ZeroClipboard.swf' );
|
||||||
var clip = new ZeroClipboard.Client();
|
|
||||||
|
|
||||||
clip.addEventListener('onMouseUp', function(){
|
var clip = new ZeroClipboard.Client();
|
||||||
clip.setText($('#paste-content').text());
|
clip.addEventListener('mouseup', function(){
|
||||||
|
clip.setText(zerobin.get_paste_content());
|
||||||
});
|
});
|
||||||
clip.addEventListener('complete', function(){
|
clip.addEventListener('complete', function(){
|
||||||
$('#copy-success').show('fadeUp');
|
$('#copy-success').show('fadeUp', function(){clip.reposition()});
|
||||||
});
|
});
|
||||||
clip.addEventListener('onLoad', function(){
|
clip.glue('clip-button');
|
||||||
});
|
|
||||||
clip.glue('clip-button', 'clip-container' );
|
|
||||||
|
|
||||||
window.onresize = clip.reposition;
|
window.onresize = clip.reposition;
|
||||||
}
|
}
|
||||||
@ -200,10 +205,7 @@ $('.previous-pastes .items').html(zerobin.get_pastes());
|
|||||||
/* clone a paste */
|
/* clone a paste */
|
||||||
$('.btn-clone').click(function(e){
|
$('.btn-clone').click(function(e){
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
var content_clone = '' ;
|
var content_clone = zerobin.get_paste_content();
|
||||||
$("#paste-content li").each(function(index) {
|
|
||||||
content_clone = content_clone + $(this).text() + '\n';
|
|
||||||
});
|
|
||||||
$('.submit-form').show();
|
$('.submit-form').show();
|
||||||
$('.paste-form').remove();
|
$('.paste-form').remove();
|
||||||
$('#content').val(content_clone);
|
$('#content').val(content_clone);
|
||||||
|
File diff suppressed because one or more lines are too long
@ -22,9 +22,8 @@
|
|||||||
<div class="well paste-form">
|
<div class="well paste-form">
|
||||||
<form action="/" method="get" accept-charset="utf-8">
|
<form action="/" method="get" accept-charset="utf-8">
|
||||||
<p>
|
<p>
|
||||||
<span id="clip-container" style="position:relative">
|
<a id="clip-button">Copy To Clipboard</a>
|
||||||
<a id="clip-button">Copy To Clipboard</a>
|
|
|
||||||
</span> |
|
|
||||||
<a id="short-url" href=""
|
<a id="short-url" href=""
|
||||||
target="_blank">Get short url</a>
|
target="_blank">Get short url</a>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user