oxjs/source/Ox.UI/js/Core/Clipboard.js

59 lines
1.9 KiB
JavaScript
Raw Normal View History

2011-11-05 16:46:53 +00:00
'use strict';
2012-05-21 10:38:18 +00:00
2011-05-16 08:24:46 +00:00
/*@
2011-05-16 10:49:48 +00:00
Ox.Clipboard <o> Basic clipboard handler
2013-07-13 21:03:29 +00:00
add <f> Add items to clipboard
(items[, type]) -> <n> Number of items
clear <f> Clear clipboard
() -> <n> Number of items
copy <f> Copy items to clipboard
(items[, type]) -> <n> Number of items
paste <f> Paste items from clipboard
() -> <a> Items
type <f> Get item type
() -> <s|undefined> Item type
2011-05-16 08:24:46 +00:00
@*/
2012-05-22 13:14:40 +00:00
Ox.Clipboard = (function() {
var clipboard = {items: [], type: void 0},
$element;
2011-04-22 22:03:10 +00:00
return {
_print: function() {
2013-07-13 21:03:29 +00:00
Ox.print(JSON.stringify(clipboard));
2011-04-22 22:03:10 +00:00
},
2013-07-13 21:03:29 +00:00
add: function(items, type) {
if (type != clipboard.type) {
Ox.Clipboard.clear();
}
clipboard = {items: clipboard.items.concat(items), type: type};
$element && $element.triggerEvent('add', clipboard);
2013-07-13 21:03:29 +00:00
return clipboard.items.length;
},
bindEvent: function() {
if (!$element) {
$element = Ox.Element();
}
$element.bindEvent.apply(this, arguments);
},
2013-07-13 21:03:29 +00:00
clear: function() {
clipboard = {items: [], type: void 0};
$element && $element.triggerEvent('clear', clipboard);
2013-07-13 21:03:29 +00:00
return clipboard.items.length;
},
copy: function(items, type) {
clipboard = {items: items, type: type};
$element && $element.triggerEvent('copy', clipboard);
2013-07-13 21:03:29 +00:00
return clipboard.items.length;
2011-04-22 22:03:10 +00:00
},
paste: function(type) {
2013-07-13 21:03:29 +00:00
return !type || type == clipboard.type ? clipboard.items : [];
$element && $element.triggerEvent('paste', clipboard);
},
2013-07-13 21:03:29 +00:00
type: function() {
return clipboard.type;
},
unbindEvent: function() {
$element && $element.bindEvent.apply(this, arguments);
2011-04-22 22:03:10 +00:00
}
};
}());