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

71 lines
2.2 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
@*/
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) {
items = Ox.makeArray(items);
if (items.length) {
if (type != clipboard.type) {
Ox.Clipboard.clear();
}
clipboard = {
items: Ox.unique(clipboard.items.concat(items)),
type: type
};
$element && $element.triggerEvent('add');
2013-07-13 21:03:29 +00:00
}
return clipboard.items.length;
},
bindEvent: function() {
if (!$element) {
$element = Ox.Element();
}
2014-09-20 10:28:38 +00:00
$element.bindEvent.apply($element, arguments);
},
2013-07-13 21:03:29 +00:00
clear: function() {
clipboard = {items: [], type: void 0};
$element && $element.triggerEvent('clear');
2013-07-13 21:03:29 +00:00
return clipboard.items.length;
},
copy: function(items, type) {
items = Ox.makeArray(items);
if (items.length) {
clipboard = {items: items, type: type};
$element && $element.triggerEvent('copy');
}
2013-07-13 21:03:29 +00:00
return clipboard.items.length;
2011-04-22 22:03:10 +00:00
},
items: function(type) {
return !type || type == clipboard.type ? clipboard.items.length : 0;
},
2011-04-22 22:03:10 +00:00
paste: function(type) {
$element && $element.triggerEvent('paste');
2013-07-13 21:03:29 +00:00
return !type || type == clipboard.type ? clipboard.items : [];
},
2013-07-13 21:03:29 +00:00
type: function() {
return clipboard.type;
},
unbindEvent: function() {
2014-09-20 10:28:38 +00:00
$element && $element.unbindEvent.apply($element, arguments);
2011-04-22 22:03:10 +00:00
}
};
};