Skip to content

Commit

Permalink
Merge pull request #1793 from cb1kenobi/timob-7162
Browse files Browse the repository at this point in the history
[TIMOB-7162] Finished Ti.UI.Clipboard implementation.
  • Loading branch information
nebrius committed Mar 22, 2012
2 parents 0862591 + 609d74a commit 768e0c9
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 1 deletion.
2 changes: 1 addition & 1 deletion apidoc/Titanium/UI/Clipboard/Clipboard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Titanium.UI.Clipboard
summary: A module used for accessing clipboard data.
extends: Titanium.Module
since: "1.5"
platforms: [android, iphone, ipad]
platforms: [android, iphone, ipad, mobileweb]
methods:
- name: clearData
summary: Clear data of the given mime-type from the clipboard. If no mime-type is given, clear all data from the clipboard.
Expand Down
68 changes: 68 additions & 0 deletions mobileweb/titanium/Ti/UI/Clipboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
define(["Ti/_/Evented", "Ti/_/lang"], function(Evented, lang) {

var storageKey = "ti:clipboard",
plainText = "text/plain",
error = 'Missing required argument "type"',
cache = JSON.parse(localStorage.getItem(storageKey)) || {};

function get(type) {
if (!type) {
throw new Error(error);
}
return cache[type];
}

function set(type, data) {
if (!type) {
throw new Error(error);
}
if (data) {
cache[type] = data;
} else {
delete cache[type];
}
save()
}

function save() {
localStorage.setItem(storageKey, JSON.stringify(cache));
}

return lang.setObject("Ti.UI.Clipboard", Evented, {

clearData: function() {
cache = {};
save();
},

clearText: function() {
set(plainText);
},

getData: function(type) {
return get(type) || null;
},

getText: function() {
return get(plainText) || null;
},

hasData: function(type) {
return !!get(type);
},

hasText: function() {
return !!get(plainText);
},

setData: function(type, data) {
set(type, data);
},

setText: function(text) {
set(plainText, text);
}

});

});
1 change: 1 addition & 0 deletions support/mobileweb/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,7 @@ def find_project_dependencies(self):
'Ti/Map/Annotation',
'Ti/Media/VideoPlayer',
'Ti/UI',
'Ti/UI/Clipboard',
'Ti/UI/MobileWeb',
'Ti/UI/TableViewRow',
'Ti/UI/Tab',
Expand Down

0 comments on commit 768e0c9

Please sign in to comment.