--- js/pinterest_button.js 2012-03-12 15:28:20.000000000 +0100
+++ js/pinterest_button.js 2012-03-11 19:36:14.858949000 +0100
@@ -0,0 +1,31 @@
+(function ($) {
+ $(document).ready(function(){
+ $('a.service-links-pinterest-button').each(function(){
+ $(this).attr('count-layout', Drupal.settings.ws_pb.countlayout);
+ });
+
+ window.PinIt = window.PinIt || { loaded:false };
+ if (window.PinIt.loaded) return;
+ window.PinIt.loaded = true;
+ function async_load(){
+ var s = document.createElement("script");
+ s.type = "text/javascript";
+ s.async = true;
+ if (window.location.protocol == "https:") {
+ s.src = "https://assets.pinterest.com/js/pinit.js";
+ }
+ else {
+ s.src = "http://assets.pinterest.com/js/pinit.js";
+ }
+ var x = document.getElementsByTagName("script")[0];
+ x.parentNode.insertBefore(s, x);
+ }
+ if (window.attachEvent) {
+ window.attachEvent("onload", async_load);
+ }
+ else {
+ window.addEventListener("load", async_load, false);
+ }
+
+ });
+})(jQuery);
--- services/widget_services.admin.inc 2012-03-09 19:14:38.000000000 +0100
+++ services/widget_services.admin.inc 2012-03-09 18:12:41.947775000 +0100
@@ -213,5 +213,39 @@
),
);
+ $form['pinterest_button'] = array(
+ '#type' => 'fieldset',
+ '#collapsible' => TRUE,
+ '#collapsed' => FALSE,
+ '#title' => t('Pinterest Button'),
+ );
+ $form['pinterest_button']['service_links_pb_countlayout'] = array(
+ '#title' => t('Pin Count'),
+ '#type' => 'select',
+ '#default_value' => variable_get('service_links_pb_countlayout', 'horizontal'),
+ '#options' => array(
+ 'horizontal' => t('Horizontal'),
+ 'vertical' => t('Vertical'),
+ 'none' => t('No Count'),
+ ),
+ );
+ $form['pinterest_button']['service_links_pb_mediatoken'] = array(
+ '#title' => t('Media parameter'),
+ '#type' => 'textfield',
+ '#default_value' => variable_get('service_links_pb_mediatoken', ''),
+ '#description' => t('Fill the media parameter with a token which will be evaluated by Token module.', array('@url' => 'http://www.drupal.org/project/token')),
+ '#size' => 40,
+ );
+ if (module_exists('token')) {
+ $form['pinterest_button']['token_help'] = array(
+ '#type' => 'fieldset',
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE,
+ '#title' => t('Token help'),
+ '#theme' => 'token_tree',
+ '#token_types' => array('node'),
+ );
+ }
+
return system_settings_form($form);
}
--- services/widget_services.info 2012-03-09 19:14:38.000000000 +0100
+++ services/widget_services.info 2012-03-12 15:31:46.490078000 +0100
@@ -1,5 +1,5 @@
name = Widget Services
-description = Provide the Widgets: Digg Smart Button, Facebook Like, Facebook Share, Google Plus One, Linkedin Share Button, Twitter
+description = Digg Smart Button, Facebook Like, Facebook Share, Google Plus One, Linkedin Share Button, Pinterest, Twitter
core = 7.x
package = Service Links - Services
dependencies[] = service_links
--- services/widget_services.module 2012-03-09 19:14:38.000000000 +0100
+++ services/widget_services.module 2012-03-12 12:06:14.632978000 +0100
@@ -75,6 +75,20 @@
'style' => SERVICE_LINKS_STYLE_EMPTY,
'callback' => 'ws_linkedin_share_button_data',
);
+ $links['pinterest_button'] = array(
+ 'name' => 'Pinterest',
+ 'link' => 'http://pinterest.com/pin/create/button/?url=&description=&media=',
+ 'icon' => 'pinterest.png',
+ 'description' => t('Pin It'),
+ 'javascript' => array(
+ //'http://assets.pinterest.com/js/pinit.js',
+ 'pinterest_button.js',
+ ),
+ 'style' => SERVICE_LINKS_STYLE_EMPTY,
+ 'attributes' => array('class' => array('pin-it-button')),
+ 'callback' => 'ws_pinterest_button_data',
+ 'preset' => 'ws_pinterest_button_tags',
+ );
return $links;
}
@@ -205,6 +219,41 @@
}
}
+/**
+ * Preset function for Pinterest Button, which fill the media tag.
+ */
+function ws_pinterest_button_tags(&$service, &$settings, $node = NULL) {
+ static $media_token;
+
+ if (!isset($media_token)) {
+ $media_token = variable_get('service_links_pb_mediatoken', '');
+ }
+
+ $settings['tag']['pinterest-media'] = '';
+
+ if (module_exists('token')) {
+ $settings['subst']['pinterest-media'] = check_plain(token_replace($media_token, array('node' => $node)));
+ }
+ else {
+ $settings['subst']['pinterest-media'] = '';
+ }
+}
+
+/**
+ * Callback function for Pinterest Button.
+ */
+function ws_pinterest_button_data(&$service, $subst) {
+ static $pb_settings;
+
+ if (!isset($pb_settings)) {
+ $pb_settings = array(
+ 'countlayout' => check_plain(variable_get('service_links_pb_countlayout', 'horizontal')),
+ );
+
+ drupal_add_js(array('ws_pb' => $pb_settings), 'setting');
+ }
+}
+
/**
* Implements hook_menu().
*/