sb-styleguide 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG.md CHANGED
@@ -1 +1,2 @@
1
- # Changelog
1
+ ## 1.2.0
2
+ - Adding Snowplow events JS plugin
data/Gemfile.lock CHANGED
@@ -8,7 +8,7 @@ GIT
8
8
  PATH
9
9
  remote: .
10
10
  specs:
11
- sb-styleguide (1.0.1)
11
+ sb-styleguide (1.2.0)
12
12
  actionpack (>= 3.1, < 4.1)
13
13
  activesupport (>= 3.1, < 4.1)
14
14
  compass-rails (>= 1.0, < 2.0)
@@ -1,5 +1,5 @@
1
1
  module Sb
2
2
  module Styleguide
3
- VERSION = "1.1.0"
3
+ VERSION = "1.2.0"
4
4
  end
5
5
  end
@@ -0,0 +1,89 @@
1
+ # ============================================================
2
+ # SnowplowEvents v0.0.1
3
+ # http://URL
4
+ # ============================================================
5
+ # Copyright 2013 The Beans Group
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+
20
+ plugin = ($) ->
21
+
22
+ "use strict"
23
+
24
+ # Class definition
25
+ #
26
+ # @example How to use with HAML
27
+ # %a{href: 'path/to/link', data: { spevent: 'category|action|label|prop|value' }}
28
+ # @see https://github.com/snowplow/snowplow/wiki/2-Specific-event-tracking-with-the-Javascript-tracker#371-trackstructevent
29
+ #
30
+ # @example Ensure plugin self-initialises
31
+ # <form data-spevent-load="true">...</form>
32
+ #
33
+ class SPEvent
34
+
35
+ # SPEvent constructor
36
+ #
37
+ # @param el [DOMElement]
38
+ # @param content [String] Pipe-delimited string of event data
39
+ #
40
+ constructor: (el, @content) ->
41
+ $el = $(el)
42
+ @sendEvent (if !(content.split('|') instanceof Array) then content.split('|') else [content]
43
+
44
+ _constructor: SPEvent
45
+
46
+ # Send event to Snowplow
47
+ #
48
+ # sendEvent :: [String] -> [String]
49
+ #
50
+ # @param evData [Array]
51
+ #
52
+ sendEvent: (data) ->
53
+ evData = ['trackStructEvent'].concat data
54
+ _snaq?.push evData
55
+
56
+ # Remove data and assoc attributes from DOM element
57
+ #
58
+ # @param $el [DOMElement] jQuery-wrapped DOM el
59
+ # @param ev [String] Data to be removed
60
+ #
61
+ removeData = ($el, ev) ->
62
+ $el.removeAttr('data-' + ev)
63
+ $el.removeData(ev)
64
+
65
+ # SPEvent plugin
66
+ #
67
+ $.fn.spEvent = (option, type = "spevent") ->
68
+ this.each ->
69
+ $this = $(@)
70
+ $this = if ($t = $(this)).is("[data-#{type}]") then $t else $t.closest("[data-#{type}]")
71
+ data = $this.data 'speventplugin'
72
+ if not (eventContent = $this.data(type)) then return removeData($this, type)
73
+ if !data then $this.data 'speventplugin', (data = new SPEvent @, eventContent)
74
+ if typeof option is 'string' then data[option].call $this
75
+
76
+ $.fn.spEvent.Constructor = SPEvent
77
+
78
+ # Data API
79
+ #
80
+ $ ->
81
+ $('body').on 'click.spEvent.data-api', '[data-spevent]' , ( e ) ->
82
+ $this = $(e.target)
83
+ $this.spEvent()
84
+
85
+ $('body').on 'tbgform-success.spEvent.data-api', (e, $form)->
86
+ $form.spEvent null, 'spevent-form'
87
+
88
+ $('[data-spevent-load]').each ->
89
+ $(this).spEvent null, 'spevent-load'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sb-styleguide
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-08-29 00:00:00.000000000 Z
13
+ date: 2014-01-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: haml
@@ -442,6 +442,7 @@ files:
442
442
  - vendor/assets/images/middleman.png
443
443
  - vendor/assets/index.html.haml
444
444
  - vendor/assets/javascripts/.gitkeep
445
+ - vendor/assets/javascripts/plinth/plugins/tbg-snowplow.js.coffee
445
446
  - vendor/assets/javascripts/styleguide/lib/handlebars.js
446
447
  - vendor/assets/javascripts/styleguide/lib/jquery.fitvids.js
447
448
  - vendor/assets/javascripts/styleguide/lib/ss-social.js
@@ -510,12 +511,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
510
511
  - - ! '>='
511
512
  - !ruby/object:Gem::Version
512
513
  version: '0'
514
+ segments:
515
+ - 0
516
+ hash: -1342012928098939340
513
517
  required_rubygems_version: !ruby/object:Gem::Requirement
514
518
  none: false
515
519
  requirements:
516
520
  - - ! '>='
517
521
  - !ruby/object:Gem::Version
518
522
  version: '0'
523
+ segments:
524
+ - 0
525
+ hash: -1342012928098939340
519
526
  requirements: []
520
527
  rubyforge_project:
521
528
  rubygems_version: 1.8.23
@@ -532,4 +539,3 @@ test_files:
532
539
  - spec/javascripts/plugins/tbg-ga-events_spec.js.coffee
533
540
  - spec/javascripts/plugins/tbg-switch_spec.js.coffee
534
541
  - spec/javascripts/spec.js.coffee
535
- has_rdoc: