mirror of
https://github.com/purplecabbage/phonegap-plugins.git
synced 2026-04-24 03:00:11 -04:00
Social Sharing plugin
This commit is contained in:
committed by
Jesse MacFadyen
parent
27d57c1e40
commit
64e8d34d6d
76
WindowsPhone/PGSocialShare/PGSocialShare.cs
Normal file
76
WindowsPhone/PGSocialShare/PGSocialShare.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Ink;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Animation;
|
||||
using System.Windows.Shapes;
|
||||
using System.Runtime.Serialization;
|
||||
using Microsoft.Phone.Tasks;
|
||||
|
||||
namespace WP7GapClassLib.PhoneGap.Commands
|
||||
{
|
||||
|
||||
public class PGSocialShare : BaseCommand
|
||||
{
|
||||
public enum ShareType
|
||||
{
|
||||
Status = 0, // status update to twitter/facebook/... all supported device accounts
|
||||
Link // share a link on twitter/facebook/ ... all supported device accounts
|
||||
}
|
||||
|
||||
|
||||
[DataContract]
|
||||
public class ShareOptions
|
||||
{
|
||||
[DataMember]
|
||||
public string url;
|
||||
|
||||
[DataMember]
|
||||
public string title;
|
||||
|
||||
[DataMember]
|
||||
public string message;
|
||||
|
||||
[DataMember]
|
||||
public ShareType shareType = ShareType.Status; // default
|
||||
}
|
||||
|
||||
public void share(string options)
|
||||
{
|
||||
ShareOptions opts = JSON.JsonHelper.Deserialize<ShareOptions>(options);
|
||||
switch (opts.shareType)
|
||||
{
|
||||
case ShareType.Status :
|
||||
shareStatus(opts.message);
|
||||
break;
|
||||
case ShareType.Link :
|
||||
shareLink(opts.title, opts.url, opts.message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected void shareStatus(string msg)
|
||||
{
|
||||
ShareStatusTask shareStatusTask = new ShareStatusTask();
|
||||
shareStatusTask.Status = msg;
|
||||
shareStatusTask.Show();
|
||||
|
||||
this.DispatchCommandResult();
|
||||
}
|
||||
|
||||
protected void shareLink(string title, string url, string msg)
|
||||
{
|
||||
ShareLinkTask shareLinkTask = new ShareLinkTask();
|
||||
shareLinkTask.Title = title;
|
||||
shareLinkTask.LinkUri = new Uri(url, UriKind.Absolute);
|
||||
shareLinkTask.Message = msg;
|
||||
shareLinkTask.Show();
|
||||
|
||||
this.DispatchCommandResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
44
WindowsPhone/PGSocialShare/PGSocialShare.js
Normal file
44
WindowsPhone/PGSocialShare/PGSocialShare.js
Normal file
@@ -0,0 +1,44 @@
|
||||
/* MIT licensed */
|
||||
// (c) 2011 Jesse MacFadyen, Adobe Systems Incorporated
|
||||
|
||||
|
||||
|
||||
(function(){
|
||||
|
||||
var PGSocialShare =
|
||||
{
|
||||
ShareType:
|
||||
{
|
||||
status:0,
|
||||
link:1
|
||||
}
|
||||
}
|
||||
|
||||
PhoneGap.addConstructor(function() {
|
||||
|
||||
navigator.plugins.pgSocialShare =
|
||||
{
|
||||
shareStatus:function(msg)
|
||||
{
|
||||
var options = {"message":msg,"shareType":PGSocialShare.ShareType.status};
|
||||
PhoneGap.exec(null,null,"PGSocialShare","share",options);
|
||||
},
|
||||
|
||||
shareLink:function(title,url,msg)
|
||||
{
|
||||
var options = {"message":msg,
|
||||
"title":title,
|
||||
"url":url,
|
||||
"shareType":PGSocialShare.ShareType.link};
|
||||
|
||||
PhoneGap.exec(null,null,"PGSocialShare","share",options);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
})();
|
||||
Reference in New Issue
Block a user