File: socialbutton.rb

package info (click to toggle)
tdiary-contrib 5.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,772 kB
  • sloc: ruby: 17,305; javascript: 8,263; lisp: 562; xml: 451; php: 61; sql: 40; makefile: 18
file content (62 lines) | stat: -rw-r--r-- 2,046 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# socialbutton.rb
#
# Copyright (c) 2011 MATSUOKA Kohei <kmachu@gmail.com>
# You can redistribute it and/or modify it under GPL2.
#

# enable social button names
@conf['socialbutton.enables'] ||= 'twitter,hatena,facebook_like'
# screen name of the user to attribute the tweet to
@conf['socialbutton.twitter.via'] ||= ''

def socialbutton_js_settings
	enable_js('jquery.socialbutton.js')
	enable_js('socialbutton.js')
	add_js_setting('$tDiary.plugin.socialbutton')
	# convert array to json
	add_js_setting('$tDiary.plugin.socialbutton.enables',
						%Q|["#{@conf['socialbutton.enables'].split(',').join('", "')}"]|)

	if @conf['socialbutton.twitter.via'] != ''
		options = "{ twitter: { via: '#{@conf['socialbutton.twitter.via']}' } }"
	else
		options = "{}"
	end
	add_js_setting('$tDiary.plugin.socialbutton.options', options)
end

add_conf_proc('socialbutton', @socialbutton_label_conf) do
	@conf['socialbutton.enables'] ||= []
	if @mode == 'saveconf'
		@conf['socialbutton.enables'] = @cgi.params['socialbutton.enables'].join(",")
		@conf['socialbutton.twitter.via'] = @cgi.params['socialbutton.twitter.via'][0]
	end

	result = <<-HTML
		<h3>#{@socialbutton_label_enables}</h3>
		<ul>
	HTML
	['twitter', 'hatena', 'facebook_like', 'pinterest'].each do |service|
		checked = @conf['socialbutton.enables'].index(service) ? 'checked' : ''
		id = "socialbutton.enables.#{service}"
		result << %Q|<li><input id="#{id}" name="socialbutton.enables" type="checkbox" value="#{service}" #{checked}>|
		result << %Q|<label for="#{id}">#{service}</label></li>|
	end
	result << <<-HTML
		</ul>
		<h3>#{@socialbutton_label_twitter_via}</h3>
		<p><input name="socialbutton.twitter.via" value="#{h(@conf['socialbutton.twitter.via'])}"></p>
	HTML
end

if @mode =~ /^(latest|day|month|nyear)$/
	socialbutton_footer = Proc.new { %Q|<div class="socialbuttons"></div>| }
	if respond_to?(:blogkit?) && blogkit?
		add_body_leave_proc(&socialbutton_footer)
	else
		add_section_leave_proc(&socialbutton_footer)
	end

	# load javascript
	socialbutton_js_settings()
end