Skip to content

Commit

Permalink
daisy
Browse files Browse the repository at this point in the history
  • Loading branch information
YuhangGe authored and YuhangGe committed Apr 18, 2012
1 parent cbf4574 commit 696034a
Show file tree
Hide file tree
Showing 17 changed files with 757 additions and 880 deletions.
2 changes: 1 addition & 1 deletion data/load_doodle.php
Expand Up @@ -121,7 +121,7 @@ function encode_image_file($fn) {
return uchr(0);
}

$dr = base64_encode(file_get_contents($d_fpath . $fn));
$dr = "data:image/png;base64,".base64_encode(file_get_contents($d_fpath . $fn));
$len = strlen($dr);
$h = (($len & 0xffff0000)>>16) & 0x0000ffff;
$l = $len & 0x0000ffff;
Expand Down
4 changes: 2 additions & 2 deletions index.php
Expand Up @@ -211,7 +211,7 @@
<a id="ctrl-handword" href="javascript:ctrlSetCurMode();" title="手寫模式下您可以使用鼠標右鍵輸入手寫文字">手寫(已開)</a>
<a id="ctrl-doodle" href="javascript:ctrlSetCurMode();" title="塗鴉模式下您可以使用鼠標右鍵繪製塗鴉">塗鴉(已關)</a>
<span id="ctrl-doodle-option" style="display:none;" >
<span id="ctrl-doodle-option" style=";" >
<a href="javascript:;" title="選擇畫筆類型">畫筆:</a>
<select id="ctrl-doodle-type" onchange="ctrlSetDoodleType();">
<option>普通</option>
Expand Down Expand Up @@ -244,7 +244,7 @@
</div> -->
</span>
<a href="javascript:ctrlDoodleEdit();" title="進行塗鴉編輯模式,可以選擇、縮放、旋轉塗鴉" id="ctrl-doodle-edit">編輯塗鴉</a>
<a style="position: relative;">
<a style="position: relative;width:25px;" title="选择颜色">
<div id="colorSelector"><div></div></div>
</a>
Expand Down
138 changes: 101 additions & 37 deletions js/editor/clipboard.js
@@ -1,43 +1,106 @@
if( typeof Daisy === 'undefined')
Daisy = {};
/**
* 模拟的剪贴板,在firefox下不能直接向系统剪贴板中写入数据。
* 使用单例模式。
*/
Daisy.Clipboard = function() {
this.text = "";
this.data = null;
};

(function(C) {
(function(Daisy, $) {
/**
* 模拟的剪贴板,在firefox下不能直接向系统剪贴板中写入数据。
* 使用单例模式。
*/
Daisy.Clipboard = function() {
this.inner_text = "";
this.inner_data = null;
this.saved_event = null;
this.saved_callback = null;

this._image_delegate = $.createDelegate(this,this._imageLoad);
this._text_delegate = $.createDelegate(this, this._textLoad);
};
var C = Daisy.Clipboard;
C.prototype = {
getData : function(){
return this.data;
getData : function(e, callback) {
if(e == null || typeof callback !== 'function') {
return null;
}
this.saved_event = e;
this.saved_callback = callback;
if(e && e.clipboardData && e.clipboardData.types) {
/**
* chrome safari
*/
var d_type = e.clipboardData.types[0];
$.log(e.clipboardData.types);
$.log(e.clipboardData.items);
if(d_type === "text/html") {
this.data = {
type : 'html',
value : e.clipboardData.getData("text/html")
}
this._checkData();
}else if(d_type === "text/uri-list"){
this.data = {
type : 'url',
value : e.clipboardData.getData("text/uri-list")
}
this._checkData();
}else if(/image/.test(d_type)) {
var reader = new FileReader();

reader.onload = this._image_delegate;

reader.readAsDataURL(e.clipboardData.items[0].getAsFile());
} else {
this.data = {
type : 'text',
value : e.clipboardData.getData("text/plain")
}
this._checkData();
}

} else if(window.clipboardData) {
/**
* IE 9
*/
this.data = {
type : 'text',
value : window.clipboardData.getData('text')
};
this._checkData();
} else {
/*
* firefox
*/
window.setTimeout( this._text_delegate , 5);

}

},
setData : function(data){
this.data = data;
_textLoad : function() {
this.data = {
type : 'text',
value : this.saved_event.target.value
};
this._checkData();
},
getText : function(e) {
var clip = window.clipboardData;
if(e && e.clipboardData)
clip = e.clipboardData;
if(clip)
return clip.getData("text");
else
return this.text;
$.dprint("get clip");
_imageLoad : function(evt) {

this.data = {
type : 'image',
value : evt.target.result
};
this._checkData();
},
_checkData : function() {
if(this.data.type === "text") {
if(this.data.value === "") {
this.data = null;
} else if(this.data.value === this.inner_text) {
this.data.type = "item";
this.data.value = this.inner_data;
}
}

this.saved_callback(this.data);

},
setText : function(e, txt) {
if(txt == null || txt == "")
return;
var clip = window.clipboardData;
if(e && e.clipboardData)
clip = e.clipboardData;
if(clip)
clip.setData("text", txt);
else
this.text = txt;
$.dprint("set clip: %s", txt);
setData : function(type, value, e) {
this.data = data;
}
}

Expand All @@ -47,4 +110,5 @@ Daisy.Clipboard = function() {
C.__instance__ = new C();
return C.__instance__;
}
})(Daisy.Clipboard);
})(Daisy, Daisy.$);

0 comments on commit 696034a

Please sign in to comment.