Skip to content

Commit

Permalink
And all this time I was doing it wrong... still learning.
Browse files Browse the repository at this point in the history
  • Loading branch information
scudco committed Oct 1, 2009
1 parent 847e7de commit a8d4f4e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
5 changes: 2 additions & 3 deletions jquery.omniture.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
jQuery.fn.attachOmnitureClickMap = function(clickmap,options) {
options = options || {};
if(typeof clickmap === 'function') clickmap = clickmap.call(this);
return this.click(function() {
s_objectID = clickmap;
if(options.remote === true) s.tl(true,'o',clickmap);
s_objectID = (typeof clickmap === 'function') ? clickmap.call(this) : clickmap
if(options.remote === true) s.tl(true,'o');
});
};

18 changes: 16 additions & 2 deletions spec/javascripts/jquery.omniture_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Screw.Unit(function(){

it("should send the Omniture Clickmap(function) when an element which doesn't leave the page is clicked", function() {
fixture($('<a href="#">baz</a>'));
mock(s).should_receive("tl").with_arguments(true,'o','baz').at_least(1, "times");
mock(s).should_receive("tl").with_arguments(true,'o').at_least(1, "times");

$('a').attachOmnitureClickMap(function() { return $(this).text(); }, {remote: true});
expect(typeof s_objectID).to(equal, 'undefined');
Expand All @@ -42,13 +42,27 @@ Screw.Unit(function(){

it("should send the Omniture Clickmap(string) when an element which doesn't leave the page is clicked", function() {
fixture($('<a href="#">baz</a>'));
mock(s).should_receive("tl").with_arguments(true,'o','boo').at_least(1, "times");
mock(s).should_receive("tl").with_arguments(true,'o').at_least(1, "times");

$('a').attachOmnitureClickMap('boo', {remote: true});
expect(typeof s_objectID).to(equal, 'undefined');

$('a').click();
expect(s_objectID).to(equal, 'boo');
});

it("should set separate Omniture Clickmaps when attaching on multiple elements", function() {
fixture($('<div></div>').append('<a id="first" href="#">first</a><a id="second" href="#">second</a>'));
mock(s).should_receive("tl").with_arguments(true,'o').at_least(2, "times");

$('a').attachOmnitureClickMap(function() { return $(this).text(); }, {remote: true});
expect(typeof s_objectID).to(equal, 'undefined');

$('a#first').click();
expect(s_objectID).to(equal, 'first');

$('a#second').click();
expect(s_objectID).to(equal, 'second');
});
});
});

0 comments on commit a8d4f4e

Please sign in to comment.