{"id":21077678,"url":"https://github.com/loo2k/wshare","last_synced_at":"2025-03-14T04:11:29.427Z","repository":{"id":11178180,"uuid":"13554911","full_name":"loo2k/wshare","owner":"loo2k","description":"wshare 微博分享插件","archived":false,"fork":false,"pushed_at":"2014-02-23T12:55:53.000Z","size":164,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-20T23:15:28.825Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://github.com/loo2k/wshare","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/loo2k.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-10-14T07:26:45.000Z","updated_at":"2018-04-14T13:16:29.000Z","dependencies_parsed_at":"2022-09-01T20:41:04.395Z","dependency_job_id":null,"html_url":"https://github.com/loo2k/wshare","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loo2k%2Fwshare","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loo2k%2Fwshare/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loo2k%2Fwshare/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loo2k%2Fwshare/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/loo2k","download_url":"https://codeload.github.com/loo2k/wshare/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243521288,"owners_count":20304187,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-19T19:37:47.521Z","updated_at":"2025-03-14T04:11:29.402Z","avatar_url":"https://github.com/loo2k.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## wshare 分享插件简介\n\nwshare 是一个可以自定义网页分享内容的一个 jQuery 插件，可以方便的自定义分享按钮点击之后的分享内容/链接/图片/视频。\n\n同时，wshare 仅保留少数的分享站点，对比起现有的一些分享插件更加简洁，更加轻便。\n\n## 快速使用\n\n### HTML\n\n```wshare``` 插件依赖 ```jQuery``` 库，所以在使用之前需要先引用 ```jQuery``` 库，并加载 wshare 插件：\n\n```html\n\u003cscript src=\"path/jquery.min.js\"\u003e\u003c/script\u003e\n\u003cscript src=\"path/wshare.js\"\u003e\u003c/script\u003e\n```\n\n指定好 ```data-toggle``` 和 ```data-type``` 属性即可直接使用。\n\n```html\n\u003ca id=\"wshare-demo\" data-toggole=\"wshare\" data-type=\"weibo\" href=\"javascript:;\"\u003e分享到微博\u003c/a\u003e\n```\n\n### JavaScript\n\n在没有指定 ```data-type``` 属性的时候可以通过 JavaScript 绑定。\n\n```javascript\n$(function() {\n\t$('#wshare-demo').wshare();\n})\n```\n\n### 默认分享\n\n如果你是用以上的代码，默认的分享内容是网页的标题，默认的链接是当前页面的 URL，图片跟视频为空。\n\n## 使用方法\n\n### 通过 HTML 属性使用\n\n给你需要绑定 wshare 插件的元素增加 ```data-toggle=\"wshare\"``` 和 ```data-type=\"weibo\"``` 属性即可。\n\n（该样例的演示的是绑定 wshare 插件，分享方式使用的是新浪微博）\n\n在默认的情况下你甚至不用编写 JavaScript 代码，就能指定需要分享的内容：\n\n```html\n\u003c!-- 你需要先指定好绑定元素的 ID，这里是 wshare-demo --\u003e\n\u003ca id=\"wshare-demo\" data-toggle=\"wshare\" data-type=\"weibo\" href=\"javascript:;\"\u003e分享到微博\u003c/a\u003e\n```\n\n你可以根据下面的 HTML 代码指定这个按钮点击之后的分享内容，这是在没有使用 JavaScript 控制的时候优先级最高的方法：\n\n```html\n\u003c!-- 根据绑定元素的 ID 可以指定该 ID 的分享内容，ID 设置为 ID_wsContent --\u003e\n\u003cinput id=\"wshare-demo_wsContent\" type=\"hidden\" value=\"wshare 是一个简洁轻便的网页分享插件\"\u003e\n\n\u003c!-- 根据绑定元素的 ID 可以指定该 ID 的分享链接，ID 设置为 ID_wsUrl --\u003e\n\u003cinput id=\"wshare-demo_wsUrl\" type=\"hidden\" value=\"http://github.com/loo2k/wshare\"\u003e\n\n\u003c!-- 根据绑定元素的 ID 可以指定该 ID 的分享图片，ID 设置为 ID_wsPic --\u003e\n\u003cinput id=\"wshare-demo_wsPic\" type=\"hidden\" value=\"http://placehold.it/150x150\"\u003e\n\n\u003c!-- 根据绑定元素的 ID 可以指定该 ID 的分享视频，ID 设置为 ID_wsVideo --\u003e\n\u003cinput id=\"wshare-demo_wsVideo\" type=\"hidden\" value=\"http://v.youku.com/v_show/id_XMTA5MjI1Nzcy.html\"\u003e\n```\n\n同时，你可以根据下面的 HTML 代码指定网页内所有分享按钮点击之后的分享内容：\n\n```html\n\u003c!-- 指定全局的分享内容 --\u003e\n\u003cinput id=\"wsContent\" type=\"hidden\" value=\"wshare 是一个简洁轻便的网页分享插件\"\u003e\n\n\u003c!-- 指定全局的分享链接 --\u003e\n\u003cinput id=\"wsUrl\" type=\"hidden\" value=\"http://github.com/loo2k/wshare\"\u003e\n\n\u003c!-- 指定全局的分享图片 --\u003e\n\u003cinput id=\"wsPic\" type=\"hidden\" value=\"http://placehold.it/150x150\"\u003e\n\n\u003c!-- 指定全局的分享视频 --\u003e\n\u003cinput id=\"wsVideo\" type=\"hidden\" value=\"http://v.youku.com/v_show/id_XMTA5MjI1Nzcy.html\"\u003e\n```\n\n如果你给 ```#wshare-demo``` 元素指定了 ```data-target``` 属性的话，插件会优先调用以 ```data-target``` 属性指定的值来匹配 ID，如：\n\n```html\n\u003ca id=\"wshare-demo\" data-toggle=\"wshare\" data-type=\"weibo\" data-target=\"Weibo\" href=\"javascript:;\"\u003e分享到微博\u003c/a\u003e\n```\n\n则会优先调用：\n\n```html\n\u003c!-- 分享内容 --\u003e\n\u003cinput id=\"Weibo_wsContent\" type=\"hidden\" value=\"wshare 是一个简洁轻便的网页分享插件\"\u003e\n\n\u003c!-- 分享链接/图片/视频同理... --\u003e\n```\n\n### 通过 JavaScript 使用\n\n通过 JavaScript 使用你也可以使用跟 HTML 一样的方法进行绑定，但是在这里的演示将尽量使用 JavaScript 操作。\n\n首先，你有一个需要绑定的 HTML 元素：\n\n```html\n\u003ca id=\"wshare-demo\" href=\"javascirpt:;\"\u003e分享到微博\u003c/a\u003e\n```\n\n使用 JavaScript 对元素进行绑定：\n\n```javascript\n// 默认的绑定方法\n$(function() {\n\t$('#wshare-demo').wshare();\n})\n```\n\n这样绑定了的元素也会像 HTML 绑定一样，寻找指定的元素获得需要分享的内容，而且会根据网页中的 ```window``` 对象获得指定的分享内容。\n\n```javascript\n// 根据绑定元素的 ID 可以指定该 ID 的分享内容，增加 window 子对象 ID_wsContent\nwindow['wshare-demo_wsContent'] = 'wshare 是一个简洁轻便的网页分享插件';\n\n// 根据绑定元素的 ID 可以指定该 ID 的分享链接，增加 window 子对象 ID_wsUrl\nwindow['wshare-demo_wsUrl'] = 'http://github.com/loo2k/wshare';\n\n// 图片/视频等同理...\n```\n\n你也可以用在 ```window``` 对象中设置全局的分享内容\n\n```javascript\n// 指定全局的分享内容\nwindow['wsContent'] = 'wshare 是一个简洁轻便的网页分享插件';\n\n// 链接/图片/视频同理...\n```\n\n你也可以在绑定事件的时候指定 ```target```：\n\n```javascript\n$(function() {\n\t$('#wshare-demo').wshare({\n\t\ttarget: 'Weibo'\n\t})\n})\n\n// 按照以上方法绑定则会优先获取 window 对象中的 Weibo_wsContent 的内容\nwindow['Weibo_wsContent'] = \"wshare 是一个简洁轻便的网页分享插件\";\n```\n\n### 选项\n\n| *属性*\t|*数据类型*\t|*默认值*\t|*说明*\t|\n|---|:---:|:---:|---|\n| type\t|String\t\t|weibo\t|分享方式，默认值是新浪微博，腾讯微博则为 \"qq\"，目前仅支持两种分享方式 |\n| target\t|String\t\t|false\t|如果指定了 target 插件会优先调用以 target 开头以 _wsContent 的元素或者 window 对象的属性为默认的分享内容 |\n| wsContent\t|String/Function\t|false\t|此处设置分享内容，优先级最高，如果 function 返回值是 false 则调用默认处理方式 |\n| wsUrl\t\t|String/Function\t|false\t|此处设置分享链接，优先级最高，如果 function 返回值是 false 则调用默认处理方式 |\n| wsPic\t\t|String/Function\t|false\t|此处设置分享图片，优先级最高，如果 function 返回值是 false 则调用默认处理方式 |\n| wsVideo\t|String/Function\t|false\t|此处设置分享视频，优先级最高，如果 function 返回值是 false 则调用默认处理方式 |","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floo2k%2Fwshare","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Floo2k%2Fwshare","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floo2k%2Fwshare/lists"}