大多数代码都有效,除了它没有抓住a
我需要的每个人.post
(function ($) {
'use strict';
var url = window.location.href.split('#')[0];
var post = $('.post').children('a[name]').attr('name');
var helpers = {
"defaults": {
"post": post,
"href": url+'#',
"send": 'true',
"layout": 'button_count',
"width": '125',
"faces": 'false',
"font": 'verdana',
"action": 'like',
"scheme": 'light',
},
"init": function (options) {
var settings = $.extend({}, helpers.defaults, options),
easyface = $('<div />').addClass('easyface fb-like').attr({
"data-href": settings.href + settings.post,
"data-send": settings.send,
"data-layout": settings.layout,
"data-width": settings.width,
"data-show-faces": settings.faces,
"data-font": settings.font,
"data-action": settings.action,
"data-colorscheme": settings.scheme
});
return this.each(function (i, elem) {
var self = $(elem),
data = self.data('easyface');
if (!data) {
self.data('easyface', easyface);
self.append(easyface);
}
});
},
"destroy": function () {
return this.each(function (i, elem) {
var self = $(this),
data = self.data('easyface'); // test to see if we've already called init on this element
$(window).unbind('.easyface'); // unbind any namespaced events, assuming you've namespaced them like "click.easyface"
self.removeData('easyface'); // remove the data flag
self.find('.easyface').remove(); // remove the appended div
});
}
};
//define the method "easyface"
$.fn.easyface = function (method) {
if (helpers[method]) {
// call the method and pass in the settings
return helpers[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || !method) {
// default to the init method and pass in the arg
return helpers.init.apply(this, arguments);
} else {
// throw an error
$.error('Method ' + method + ' does not exist on jQuery.tooltip');
}
};
}(jQuery));
$(function() {
$('body').append('<div id="fb-root"></div>');
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=477049588983712";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
});