Micro-credit js-sdk sharing function Interface Common logic encapsulation examples _javascript tips

Source: Internet
Author: User
Tags class definition

This paper illustrates the common logic encapsulation of micro-js-sdk sharing function interface. Share to everyone for your reference, specific as follows:

Micro-Letter Js-sdk 1.0, share description:

1. Currently supported by 5 sharing interface, which share Tencent Weibo can basically ignore

2. Interface only defines the data when sharing, does not provide trigger sharing function

First, use the example in the Ready event

Share objects using
var sharedata={title
  : ' Share title ',
  desc: ' Share description ',
  link: ' http://www.gongjuji.net ',
  imgurl: ' Http://www.gongjuji.net/favicon.ico ',
  success:function () {
    AppendText (' share success ');
  },
  //user canceled
  cancel:function () {
    appendtext (' share cancellation ');
  }
var share=new wxshare (sharedata);
Share.bind ();

Second, the Encapsulation class definition:

Micro-credit sharing event monitoring, common function encapsulation (function () {var wxshare=function (opts) {var defaults={title: ' Share title ',//share title, cannot be empty desc: ',//share Description, can be empty, (share to the circle of friends, do not support description) Link: ',//share page address, can not be empty imgurl: ',//sharing is the cover picture, can not be empty success:function () {},//sharing successful trigger cancel
: function () {}//share cancellation trigger, can call} this.opts=$.extend ({},defaults,opts) when needed;
    wxshare.prototype={//Binding micro-trust friends Circle, send friend Bindwx:function () {var _opts=this.opts;
      Listening, sharing to the circle of friends Wx.onmenusharetimeline ({title:_opts.title, Link:_opts.link, Imgurl:_opts.imgurl,
      Success:function () {if (_opts.success) _opts.success ();
      }, Calcel:function () {if (_opts.cancel) _opts.cancel ();
    }
    }); Listening, sharing to friends (type,dataurl Basic can give up do not use) Wx.onmenushareappmessage ({title: _opts.title,//share title desc: _opts.desc ,//Share description Link: _opts.link,//Share link Imgurl: _opts.imgurl,//Share icon Success:function () {if (_opt
      s.success) _opts.success ();
 },     Cancel:function () {if (_opts.cancel) _opts.cancel ();
  }
    });
    },//binding QQ space, QQ friend Bindqq:function () {var _opts=this.opts; Listening, sharing to QQ space Wx.onmenushareqzone ({title: _opts.title,//share title desc: _opts.desc,//Share description Link: _opts . link,//share link Imgurl: _opts.imgurl,//Share icon Success:function () {if (_opts.success) _opts.
      Success ();
      }, Cancel:function () {if (_opts.cancel) _opts.cancel ();
    }
    }); Listening, sharing to QQ Wx.onmenushareqq ({title: _opts.title,//share title desc: _opts.desc,//Share description Link: _opts.link ,//share links Imgurl: _opts.imgurl,//Share icon Success:function () {if (_opts.success) _opts.succe
      SS ();
      }, Cancel:function () {if (_opts.cancel) _opts.cancel ();
  }
    });
    },//binding default, do not use Tencent Weibo bind:function () {this.bindwx ();
  THIS.BINDQQ (); },//Bind all, including Tencent Weibo bindall:function() {this.bind ();
    var _opts=this.opts;
      Listening, sharing to Tencent Weibo (basically can give up not to use) Wx.onmenushareweibo ({title: _opts.title,//share title Desc:_opts.desc,//Share description
          Link: _opts.link,//Share link imgurl:_opts.imgurl,//Share icon Success:function () {if (_opts.success)
      _opts.success ();
      }, Cancel:function () {if (_opts.cancel) _opts.cancel ();
  }
    });
}} Window.wxshare=wxshare;

 })();

More readers interested in JavaScript-related content can view this site: "JavaScript in the JSON Operation tips Summary", "JavaScript switching effects and techniques summary", "JavaScript Search Algorithm Skills summary", " JavaScript animation effects and tips Summary, "JavaScript Error and debugging skills Summary", "JavaScript data structure and algorithm skills summary", "JavaScript traversal algorithm and Skills summary" and "JavaScript Mathematical operation Usage Summary"

I hope this article will help you with JavaScript programming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.