clipbuffer¶
webix.
clipbuffer
¶webix.clipbuffer helper.
Please look into the linked official documentation.
External references¶
Code¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | webix.clipbuffer = {
_area: null,
_blur_id: null,
_ctrl: 0,
/*! create textarea or returns existing
**/
init: function() {
// returns existing textarea
if (this._area !== null)
return this._area;
webix.destructors.push({ obj: this });
// creates new textarea
this._area = document.createElement('textarea');
this._area.className = "webix_clipbuffer";
this._area.setAttribute("webixignore", 1);
document.body.appendChild(this._area);
webix.event(document.body, 'keydown', webix.bind(function(e){
var key = e.keyCode;
var ctrl = !!(e.ctrlKey || e.metaKey);
if (key === 86 && ctrl)
webix.delay(this._paste, this, [e], 100);
}, this));
return this._area;
},
destructor: function(){
this._area = null;
},
/*! set text into buffer
**/
set: function(text) {
this.init();
this._area.value = text;
this.focus();
},
/*! select text in textarea
**/
focus: function() {
// if there is native browser selection, skip focus
if(!this._isSelectRange()){
this.init();
this._area.focus();
this._area.select();
}
},
/*! checks document selection
**/
_isSelectRange: function() {
var text = "";
if (typeof window.getSelection != "undefined") {
text = window.getSelection().toString();
} else if (typeof document.selection != "undefined" && document.selection.type == "Text") {
text = document.selection.createRange().text;
}
return !!text;
},
/*! process ctrl+V pressing
**/
_paste: function(e) {
var trg = e.target || e.srcElement;
if (trg === this._area) {
var text = this._area.value;
var last_active = webix.UIManager.getFocus();
if (last_active && (!last_active.getEditor || !last_active.getEditor())){
last_active.callEvent("onPaste", [text]);
this._area.select();
}
}
}
};
|