|
var ios = (Ti.Platform.name === 'iPhone OS'); |
|
var ipad = (ios && Ti.Platform.osname === 'ipad'); |
|
|
|
if (ios) { |
|
var Social = require('dk.napp.social'); |
|
} |
|
|
|
var facebook_appid, facebook; |
|
|
|
function share(args) { |
|
|
|
if (ios && Social.isActivityViewSupported()) { |
|
|
|
if (ipad) { |
|
Social.activityPopover({ |
|
text: args.url ? (args.text ? args.text + ' ' + args.url : args.url) : args.text, |
|
image: args.image, |
|
removeIcons: args.removeIcons, |
|
view: args.view |
|
}); |
|
|
|
} else { |
|
Social.activityView({ |
|
text: args.url ? (args.text ? args.text + ' ' + args.url : args.url) : args.text, |
|
image: args.image, |
|
removeIcons: args.removeIcons |
|
}); |
|
} |
|
|
|
return; |
|
} |
|
|
|
var options = ['Twitter', 'Facebook', L('Cancel')]; |
|
|
|
if (args.removeIcons && typeof args.removeIcons === 'string') { |
|
var removeIcons = args.removeIcons.split(','); |
|
|
|
var removeTwitter = removeIcons.indexOf('twitter'); |
|
if (removeTwitter >= 0) { |
|
options.splice(removeTwitter, 1); |
|
} |
|
|
|
var removeFacebook = removeIcons.indexOf('facebook'); |
|
if (removeFacebook >= 0) { |
|
options.splice(removeFacebook, 1); |
|
} |
|
} |
|
|
|
if (options.length === 1) { |
|
return; |
|
} |
|
|
|
var dialog = Ti.UI.createOptionDialog({ |
|
cancel: options.length - 1, |
|
options: options, |
|
title: args.title, |
|
titleid: args.titleid, |
|
androidView: args.androidView, |
|
tizenView: args.tizenView |
|
}); |
|
|
|
dialog.addEventListener('click', function (e) { |
|
|
|
if (options[e.index] === 'Twitter') { |
|
|
|
if (ios && Social.isTwitterSupported()) { |
|
Social.twitter({ |
|
text: args.text, |
|
image: args.image, |
|
url: args.url |
|
}); |
|
} |
|
|
|
} else if (options[e.index] === 'Facebook') { |
|
|
|
if (ios && Social.isFacebookSupported()) { |
|
Social.facebook({ |
|
text: args.text, |
|
image: args.image, |
|
url: args.url |
|
}); |
|
|
|
} else if (facebook_appid !== false) { |
|
|
|
if (!facebook_appid) { |
|
facebook_appid = Ti.App.Properties.getString('ti.facebook.appid', false); |
|
|
|
if (facebook_appid === false) { |
|
return; |
|
} |
|
|
|
if (Ti.version >= '3.1.0') { |
|
facebook = require('facebook'); |
|
facebook.appid = facebook_appid; |
|
} else { |
|
Ti.Facebook.appid = facebook_appid; |
|
} |
|
} |
|
|
|
if (facebook) { |
|
facebook.dialog('feed', { |
|
link: args.url, |
|
caption: args.caption, |
|
description: args.description || args.text, |
|
picture: args.image |
|
}, function (e) { |
|
return; |
|
}); |
|
|
|
} else { |
|
Ti.Facebook.dialog('feed', { |
|
link: args.url, |
|
caption: args.caption, |
|
description: args.description || args.text, |
|
picture: args.image |
|
}, function (e) { |
|
return; |
|
}); |
|
} |
|
} |
|
} |
|
|
|
return; |
|
}); |
|
|
|
if (ipad) { |
|
dialog.show({ |
|
animated: args.animated, |
|
rect: args.rect, |
|
view: args.view |
|
}); |
|
|
|
} else { |
|
dialog.show(); |
|
} |
|
|
|
return; |
|
} |
|
|
|
exports.share = share; |