Skip to content
This repository has been archived by the owner on Dec 15, 2021. It is now read-only.

Commit

Permalink
加入文字选择功能,不过还没有实现文字直接共享。
Browse files Browse the repository at this point in the history
  • Loading branch information
MerrickZ committed Jan 16, 2014
1 parent 63a629b commit 8f89a11
Show file tree
Hide file tree
Showing 4 changed files with 198 additions and 155 deletions.
Binary file added src/www/img/ic_share.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions src/www/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var app = {
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
//window.addEventListener('oncontextmenu', app.onContextMenu);
},
// deviceready Event Handler
//
Expand Down Expand Up @@ -73,6 +74,7 @@ var app = {
if (id === 'menu') {
loadContent(element, id);
}

};

bb.init(config);
Expand Down Expand Up @@ -437,4 +439,34 @@ function tabswitcher() {
} else {
bb.actionBar.highlightAction(g('a3'));
}
}
///////////////////////////////////////////文字选择与共享////////////////////////////////////////////////



function shareText() {
var selectedItem = getSelText();
if (selectedItem) {
Invoke.shareText(selectedItem);
} else {
Toast.regular("您未选择要分享的内容", 1000);
}
}

function getSelText()
{
if (window.getSelection)
{
return window.getSelection();
}
else if (document.getSelection)
{
return document.getSelection();
}
else if (document.selection)
{
return document.selection.createRange().text;
}
else
return "";
}
314 changes: 163 additions & 151 deletions src/www/js/bfb_bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,176 +103,188 @@ var Invoke = {
};

blackberry.invoke.card.invokeTargetPicker(request, title,
// success
function() {
},
// error
function(e) {
});
},
// blackberry world
blackberryWorld: {
// vendor page
app: function(id) {
blackberry.invoke.invoke({
target: 'sys.appworld',
action: 'bb.action.OPEN',
uri: 'appworld://content/' + id
},
// success
function() {
},
// error
function() {
});
}
},
// email
email: function(to, subject, body) {
var message = to + '?subject=' + subject + '&body=' + body;
blackberry.invoke.invoke({
target: 'sys.pim.uib.email.hybridcomposer',
action: 'bb.action.OPEN, bb.action.SENDMAIL',
type: 'message/rfc822',
uri: 'mailto:' + message
});
},
// blackberry maps
maps: function(address) {
blackberry.invoke.invoke({
action: 'bb.action.NAVIGATETO',
type: 'application/vnd.blackberry.string.address',
data: address
});
},
// nfc
nfc: function(uri) {
blackberry.invoke.invoke({
target: "sys.NFCViewer",
action: "bb.action.SHARE",
uri: uri
}, function() {
}, function() {
function() {
},
function(e) {
});
},
// twitter
twitter: function(shareText) {
blackberry.invoke.invoke({
target: "Twitter",
action: "bb.action.SHARE",
type: "text/plain",
data: shareText
}, function() {
}, function() {
},
shareText: function(t) {
var title = 'Share';
var request = {
action: 'bb.action.SHARE',
data: t,
target_type: ["APPLICATION", "VIEWER", "CARD"]
};

blackberry.invoke.card.invokeTargetPicker(request, title,
function() {
},
function(e) {
});
},
// blackberry world
blackberryWorld: {
// vendor page
app: function(id) {
blackberry.invoke.invoke({
target: 'sys.appworld',
action: 'bb.action.OPEN',
uri: 'appworld://content/' + id
},
//facebook
facebook: function(shareText) {
blackberry.invoke.invoke({
target: "Facebook",
action: "bb.action.SHARE",
type: "text/plain",
data: shareText
}, function() {
}, function() {
});
// success
function() {
},
utils: {
// filepicker
filePicker: function(success, cancel, failure) {
// error
function() {
});
}
},
// email
email: function(to, subject, body) {
var message = to + '?subject=' + subject + '&body=' + body;
blackberry.invoke.invoke({
target: 'sys.pim.uib.email.hybridcomposer',
action: 'bb.action.OPEN, bb.action.SENDMAIL',
type: 'message/rfc822',
uri: 'mailto:' + message
});
},
// blackberry maps
maps: function(address) {
blackberry.invoke.invoke({
action: 'bb.action.NAVIGATETO',
type: 'application/vnd.blackberry.string.address',
data: address
});
},
// nfc
nfc: function(uri) {
blackberry.invoke.invoke({
target: "sys.NFCViewer",
action: "bb.action.SHARE",
uri: uri
}, function() {
}, function() {
});
},
// twitter
twitter: function(shareText) {
blackberry.invoke.invoke({
target: "Twitter",
action: "bb.action.SHARE",
type: "text/plain",
data: shareText
}, function() {
}, function() {
});
},
//facebook
facebook: function(shareText) {
blackberry.invoke.invoke({
target: "Facebook",
action: "bb.action.SHARE",
type: "text/plain",
data: shareText
}, function() {
}, function() {
});
},
utils: {
// filepicker
filePicker: function(success, cancel, failure) {

var details = {
mode: blackberry.invoke.card.FILEPICKER_MODE_PICKER,
viewMode: blackberry.invoke.card.FILEPICKER_VIEWER_MODE_GRID,
sortBy: blackberry.invoke.card.FILEPICKER_SORT_BY_NAME,
sortOrder: blackberry.invoke.card.FILEPICKER_SORT_ORDER_DESCENDING
};
var details = {
mode: blackberry.invoke.card.FILEPICKER_MODE_PICKER,
viewMode: blackberry.invoke.card.FILEPICKER_VIEWER_MODE_GRID,
sortBy: blackberry.invoke.card.FILEPICKER_SORT_BY_NAME,
sortOrder: blackberry.invoke.card.FILEPICKER_SORT_ORDER_DESCENDING
};

blackberry.invoke.card.invokeFilePicker(details, function(path) {
success(path);
},
// cancel callback
function(reason) {
cancel(reason);
},
// error callback
function(error) {
if (error) {
failure(error);
}
}
);
},
// camera
camera: function(success, cancel, failure) {
var mode = blackberry.invoke.card.CAMERA_MODE_PHOTO;
blackberry.invoke.card.invokeCamera(mode, function(path) {
success(path);
blackberry.invoke.card.invokeFilePicker(details, function(path) {
success(path);
},
// cancel callback
function(reason) {
cancel(reason);
},
function(reason) {
cancel(reason);
},
// error callback
function(error) {
if (error) {
failure(error);
}
}
);
}
}
};
},
// camera
camera: function(success, cancel, failure) {
var mode = blackberry.invoke.card.CAMERA_MODE_PHOTO;
blackberry.invoke.card.invokeCamera(mode, function(path) {
success(path);
},
function(reason) {
cancel(reason);
},
function(error) {
if (error) {
failure(error);
}
}
);
}
}
};



/* ==============================================================================================
* TOASTS - https://developer.blackberry.com/html5/apis/blackberry.ui.toast.html
* =========================================================================================== */
/* ==============================================================================================
* TOASTS - https://developer.blackberry.com/html5/apis/blackberry.ui.toast.html
* =========================================================================================== */

var Toast = {
regular: function(text, timeout) {
try {
timeout = timeout || false;
var options = {
timeout: timeout
};
blackberry.ui.toast.show(text, options);
} catch (e) {
console.log('toast: ' + text);
}
},
withButton: function(text, btnText, btnCallback, timeout) {
try {
timeout = timeout || false;
var options = {
timeout: timeout,
buttonText: btnText,
buttonCallback: eval(btnCallback)
};
blackberry.ui.toast.show(text, options, timeout);
} catch (e) {
console.log('toast: ' + text);
}
}
};
var Toast = {
regular: function(text, timeout) {
try {
timeout = timeout || false;
var options = {
timeout: timeout
};
blackberry.ui.toast.show(text, options);
} catch (e) {
console.log('toast: ' + text);
}
},
withButton: function(text, btnText, btnCallback, timeout) {
try {
timeout = timeout || false;
var options = {
timeout: timeout,
buttonText: btnText,
buttonCallback: eval(btnCallback)
};
blackberry.ui.toast.show(text, options, timeout);
} catch (e) {
console.log('toast: ' + text);
}
}
};



/* ===========================================================================================
* SPINNERS - https://github.com/blackberry/bbUI.js/wiki/Activity-Indicator
* ======================================================================================== */
/* ===========================================================================================
* SPINNERS - https://github.com/blackberry/bbUI.js/wiki/Activity-Indicator
* ======================================================================================== */
// spinner divs in spinners.html

var Spinner = {
'lastOn': false,
off: function() {
if (Spinner.lastOn) {
var el = document.getElementById('spinner-' + Spinner.lastOn);
el.style.display = 'none';
}
},
on: function(size) {
Spinner['lastOn'] = size;
var el = document.getElementById('spinner-' + size);
el.style.display = 'block';
}
};
var Spinner = {
'lastOn': false,
off: function() {
if (Spinner.lastOn) {
var el = document.getElementById('spinner-' + Spinner.lastOn);
el.style.display = 'none';
}
},
on: function(size) {
Spinner['lastOn'] = size;
var el = document.getElementById('spinner-' + size);
el.style.display = 'block';
}
};
Loading

0 comments on commit 8f89a11

Please sign in to comment.