sb-styleguide 0.0.7 → 0.0.8
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.
@@ -0,0 +1,9 @@
|
|
1
|
+
%a{:href=>"#clickyclick", :class=>"btn", :data=> {:gaevent=>"ping|ding"}}
|
2
|
+
|
3
|
+
%a{:href=>"#clickyclick", :class=>"btn2", :data=> {:gaevent=>""}}
|
4
|
+
|
5
|
+
%a{:href=>"#clickyclick", :class=>"btn3", :data=> {"gaevent-load" =>'ping|ding'}}
|
6
|
+
|
7
|
+
%form{:class=>"GAForm", :data=>{"gaevent-form"=>"ping|ding"}}
|
8
|
+
%input{:type=>"text"}
|
9
|
+
%input{:type=>"submit"}
|
@@ -0,0 +1,83 @@
|
|
1
|
+
#=require styleguide/plugins/tbg-ga-events
|
2
|
+
|
3
|
+
root = this
|
4
|
+
describe "Google Analytics Events", ->
|
5
|
+
beforeEach ->
|
6
|
+
loadFixtures 'plugins/tbg-ga-events_fixture'
|
7
|
+
window._gaq = []
|
8
|
+
|
9
|
+
describe "a jQuery Plugin", ->
|
10
|
+
it "should be defined on jquery object", ->
|
11
|
+
expect( $('.btn').gaEvent() ).toBeDefined()
|
12
|
+
|
13
|
+
it "should return element", ->
|
14
|
+
expect( $('.btn').gaEvent()[0] ).toBe($('.btn')[0])
|
15
|
+
|
16
|
+
describe "getting Events", ->
|
17
|
+
|
18
|
+
it "can be initated for onload event", ->
|
19
|
+
# This is an ugly way to test the content but as it is fired on load
|
20
|
+
# then we must 'assume' this will be fired and test the internal working
|
21
|
+
# of the plugin.
|
22
|
+
$('[data-gaevent-load]').each ->
|
23
|
+
$(this).gaEvent null, 'gaevent-load'
|
24
|
+
|
25
|
+
$but = $('.btn3')
|
26
|
+
$data = $but.data 'gaeventplugin'
|
27
|
+
expect( $data.eventcontent ).toEqual('ping|ding')
|
28
|
+
|
29
|
+
|
30
|
+
it "can be initated on click", ->
|
31
|
+
$but = $('.btn').click()
|
32
|
+
$data = $but.data 'gaeventplugin'
|
33
|
+
expect( $data.eventcontent ).toEqual('ping|ding')
|
34
|
+
|
35
|
+
it "can be initated via a form submit event", ->
|
36
|
+
$form = $('.GAForm')
|
37
|
+
$('body').trigger 'tbgform-success' , [$form]
|
38
|
+
$data = $form.data 'gaeventplugin'
|
39
|
+
expect( $data.eventcontent ).toEqual('ping|ding')
|
40
|
+
|
41
|
+
it "should remove GAEvent hooks if no event is supplied", ->
|
42
|
+
$but = $('.btn2').click()
|
43
|
+
expect( $but.data('gaevent') ).not.toBeDefined()
|
44
|
+
expect( $but.data('gaeventplugin') ).not.toBeDefined()
|
45
|
+
|
46
|
+
|
47
|
+
describe "send Events", ->
|
48
|
+
beforeEach ->
|
49
|
+
root._gaq = []
|
50
|
+
|
51
|
+
it "should add the event to the google array on click method", ->
|
52
|
+
$('.btn').click()
|
53
|
+
expect(root._gaq.length).toEqual(1)
|
54
|
+
|
55
|
+
it "should add the event to the google array on form method", ->
|
56
|
+
$('body').trigger 'tbgform-success' , [$('.GAForm')]
|
57
|
+
expect(root._gaq.length).toEqual(1)
|
58
|
+
|
59
|
+
it "should add the event to the google array on onLoad method", ->
|
60
|
+
$('[data-gaevent-load]').each ->
|
61
|
+
$(this).gaEvent null, 'gaevent-load'
|
62
|
+
expect(root._gaq.length).toEqual(1)
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
# Must be the last test as we unbind
|
67
|
+
# the plugin to the data api
|
68
|
+
describe "the data API", ->
|
69
|
+
it "should be initated on click", ->
|
70
|
+
$but = $('.btn').click()
|
71
|
+
$data = $but.data('gaeventplugin')
|
72
|
+
expect( $data ).toBeDefined()
|
73
|
+
|
74
|
+
it "should be add the constructor to the data element", ->
|
75
|
+
$but = $('.btn').click()
|
76
|
+
$data = $but.data('gaeventplugin')
|
77
|
+
expect( $data instanceof $.fn.gaEvent.Constructor ).toBeTruthy()
|
78
|
+
|
79
|
+
it "should not be initated if unattached via data API", ->
|
80
|
+
$('body').off('.gaEvent.data-api')
|
81
|
+
$but = $('.btn').click()
|
82
|
+
$data = $but.data('gaeventplugin')
|
83
|
+
expect( $data ).not.toBeDefined()
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# ============================================================
|
2
|
+
# GAEvents v0.0.0
|
3
|
+
# http://URL
|
4
|
+
# ============================================================
|
5
|
+
# Copyright 2012 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
|
+
# Useage:
|
21
|
+
# ========================
|
22
|
+
#
|
23
|
+
# HAML> %a{:href=>"#clickyclick", :class=>"btn", :data=> {:gaevent=>"category|action|opt_label|opt_value|opt_noninteraction"}}
|
24
|
+
# See: https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide
|
25
|
+
|
26
|
+
plugin = ($)->
|
27
|
+
|
28
|
+
"use strict"
|
29
|
+
|
30
|
+
# GAEVENT CLASS DEFINITION
|
31
|
+
# =========================
|
32
|
+
class GAEvent
|
33
|
+
constructor: ( element, @eventcontent ) ->
|
34
|
+
$el = $(element)
|
35
|
+
@sendEvent (if typeof eventcontent.split('|') isnt "array" then eventcontent.split('|') else [eventcontent])
|
36
|
+
|
37
|
+
_constructor: GAEvent
|
38
|
+
|
39
|
+
sendEvent : (data)->
|
40
|
+
data.unshift('_trackEvent')
|
41
|
+
_gaq?.push data
|
42
|
+
|
43
|
+
# Private method
|
44
|
+
removeData = ( $el, ev )->
|
45
|
+
$el.removeAttr('data-' + ev)
|
46
|
+
$el.removeData(ev)
|
47
|
+
|
48
|
+
|
49
|
+
# GAEVENT PLUGIN DEFINITION
|
50
|
+
# ==========================
|
51
|
+
|
52
|
+
$.fn.gaEvent = ( option , type = "gaevent") ->
|
53
|
+
this.each ->
|
54
|
+
$this = $(@)
|
55
|
+
data = $this.data 'gaeventplugin'
|
56
|
+
if not (eventContent= $this.data type ) then return removeData($this, type)
|
57
|
+
if !data then $this.data 'gaeventplugin', (data = new GAEvent @, eventContent)
|
58
|
+
if typeof option is 'string' then data[option].call $this
|
59
|
+
|
60
|
+
$.fn.gaEvent.Constructor = GAEvent
|
61
|
+
|
62
|
+
# DATA API
|
63
|
+
# ===================================
|
64
|
+
|
65
|
+
$ ->
|
66
|
+
|
67
|
+
$('body').on 'click.gaEvent.data-api', '[data-gaevent]' , ( e ) ->
|
68
|
+
$this = $(e.target)
|
69
|
+
$this.gaEvent()
|
70
|
+
|
71
|
+
$('body').on 'tbgform-success.gaEvent.data-api', (e, $form)->
|
72
|
+
$form.gaEvent null, 'gaevent-form'
|
73
|
+
|
74
|
+
# Can't turn this off via the data API
|
75
|
+
# @todo Enable Data API ga-event-load method
|
76
|
+
$('[data-gaevent-load]').each ->
|
77
|
+
$(this).gaEvent null, 'gaevent-load'
|
78
|
+
|
79
|
+
|
80
|
+
do ( plugin ) ->
|
81
|
+
if typeof define is 'function' and define.amd
|
82
|
+
# AMD. Register as an anonymous module.
|
83
|
+
define(['jquery'], plugin)
|
84
|
+
else
|
85
|
+
# Browser globals
|
86
|
+
plugin(jQuery)
|
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: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -239,9 +239,11 @@ files:
|
|
239
239
|
- script/rails
|
240
240
|
- spec/javascripts/fixtures/plugins/tbg-close_fixture.html.haml
|
241
241
|
- spec/javascripts/fixtures/plugins/tbg-forms_fixture.html.haml
|
242
|
+
- spec/javascripts/fixtures/plugins/tbg-ga-events_fixture.html.haml
|
242
243
|
- spec/javascripts/fixtures/plugins/tbg-switch_fixture.html.haml
|
243
244
|
- spec/javascripts/plugins/tbg-close_spec.js.coffee
|
244
245
|
- spec/javascripts/plugins/tbg-forms_spec.js.coffee
|
246
|
+
- spec/javascripts/plugins/tbg-ga-events_spec.js.coffee
|
245
247
|
- spec/javascripts/plugins/tbg-switch_spec.js.coffee
|
246
248
|
- spec/javascripts/spec.js.coffee
|
247
249
|
- vendor/assets/fonts/ss-social-circle.eot
|
@@ -270,6 +272,7 @@ files:
|
|
270
272
|
- vendor/assets/javascripts/styleguide/lib/ss-standard.js
|
271
273
|
- vendor/assets/javascripts/styleguide/plugins/tbg-close.js.coffee
|
272
274
|
- vendor/assets/javascripts/styleguide/plugins/tbg-forms.js.coffee
|
275
|
+
- vendor/assets/javascripts/styleguide/plugins/tbg-ga-events.js.coffee
|
273
276
|
- vendor/assets/javascripts/styleguide/plugins/tbg-respinsiveresize.js.coffee
|
274
277
|
- vendor/assets/javascripts/styleguide/plugins/tbg-switch.js.coffee
|
275
278
|
- vendor/assets/stylesheets/.gitkeep
|
@@ -328,9 +331,11 @@ summary: styleguide
|
|
328
331
|
test_files:
|
329
332
|
- spec/javascripts/fixtures/plugins/tbg-close_fixture.html.haml
|
330
333
|
- spec/javascripts/fixtures/plugins/tbg-forms_fixture.html.haml
|
334
|
+
- spec/javascripts/fixtures/plugins/tbg-ga-events_fixture.html.haml
|
331
335
|
- spec/javascripts/fixtures/plugins/tbg-switch_fixture.html.haml
|
332
336
|
- spec/javascripts/plugins/tbg-close_spec.js.coffee
|
333
337
|
- spec/javascripts/plugins/tbg-forms_spec.js.coffee
|
338
|
+
- spec/javascripts/plugins/tbg-ga-events_spec.js.coffee
|
334
339
|
- spec/javascripts/plugins/tbg-switch_spec.js.coffee
|
335
340
|
- spec/javascripts/spec.js.coffee
|
336
341
|
has_rdoc:
|