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