Skip to content

Instantly share code, notes, and snippets.

View wei-lee's full-sized avatar

Wei Li wei-lee

  • Intercom
  • Dublin, Ireland
View GitHub Profile
@wei-lee
wei-lee / $fh.file.js
Created July 22, 2011 14:40
$fh.file example
$fh.file({
act: 'upload',
filepath: '/example/file/path/image.jpg',
server: 'http://example.com/upload'
}, function (res) {
alert("Response is " + res.res + ". Sent data : " + res.size);
}, function (err) {
alert("Error " + err);
});
@wei-lee
wei-lee / upload_photo.js
Created July 22, 2011 15:10
An example to demonstrate how to upload a photo on device to a server using $fh.cam and $fh.file
$fh.cam({
act: 'picture',
source: 'photo',
uri: true
}, function (res) {
if (res.uri) {
$('#result').html('<p>' + res.uri + '</p>');
var img = new Image();
img.src = res.uri;
$('#result').css('width', '100%').css('height', '90%').append(img);
@wei-lee
wei-lee / gist:1099663
Created July 22, 2011 15:20 — forked from feedhenry-gists/gist:1015130
Camera Call
$fh.cam({act:'picture'}, function(res){
var img = new Image();
img.src='data:image/'+res.format+';base64,'+res.b64;
} );
@wei-lee
wei-lee / cam.js
Created July 22, 2011 15:24
$fh.cam return file path
$fh.cam({
act: 'picture',
source: 'photo',
uri: true
}, function (res) {
if (res.uri) {
filetoupload = res.uri;
$('#result').html('<p>' + res.uri + '</p>');
var img = new Image();
img.src = res.uri;
@wei-lee
wei-lee / gist:1178476
Created August 29, 2011 14:14 — forked from feedhenry-gists/gist:1015194
Local Storage Call
$fh.data( {act:'save', key:'foo', val:'bar'} );
$fh.data( {key:'foo'}, function(res) {
alert( res.key+'='+res.val );
});
@wei-lee
wei-lee / gist:1237823
Created September 23, 2011 16:37
$fh.push: register device on the client
$fh.push({act:'register', params:{bb:{port:bb_push_port, appId:bb_push_appId, serverUrl: bb_push_serverUrl}}}, function(e){
var token = e.deviceToken || e.apid || e.devicePIN;
alert(token);
}, function(){
//do something here
});
@wei-lee
wei-lee / gist:1237832
Created September 23, 2011 16:41
$fh.push: receive push notification messages on the device
//the receive function need to be placed in $fh.ready so that it will receive messages when the app starts up
$fh.ready({}, function(){
$fh.push({act:'receive'}, function(notification){
alert(notification.message);
}, function(err){
//error handler
}
)
});
@wei-lee
wei-lee / gist:1237837
Created September 23, 2011 16:45
$fh.push register device on the cloud side
var token = $params.token;
var platform = $params.platform;
$fh.push({'act':'register', 'type':'dev', 'params':{'id':token, 'platform':platform}});
@wei-lee
wei-lee / gist:1237843
Created September 23, 2011 16:47
$fh.push: push a message
var message = "hello from FH";
var deviceToken = "xxxxxxxxxxxxxxxxxxxxxx";
var ios_message = {'device_tokens': [deviceToken],'aps':{'alert':message}};
$fh.push({'act':'push', 'type':'dev', 'params':ios_message});
@wei-lee
wei-lee / gist:1237846
Created September 23, 2011 16:49
$fh.push: broadcast a message
var message = "hello from FH";
var android_message = {'android':{'alert':message}};
$fh.push({'act':'broadcast', 'type':'dev', 'params':android_message});