Skip to content

Commit c01b5d7

Browse files
committed
11-3-2014w
11-3-2014
1 parent be9d04a commit c01b5d7

File tree

1 file changed

+333
-0
lines changed

1 file changed

+333
-0
lines changed

11-3-2014w

Lines changed: 333 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,333 @@
1+
$.extend({
2+
json2array : function(obj){
3+
var result = [];
4+
$.each( obj, function( key, value ) {
5+
result.push(key ,value);
6+
});
7+
return result;
8+
}
9+
});
10+
(function( $ ){
11+
var defaults = {
12+
onTracking : function() {},
13+
params: {
14+
'DCS.dcssip': "www.helllo.com",
15+
'DCS.dcsuri':'/solutions/default.asp',
16+
'DCS.dcsqry':'tab=Products'
17+
},
18+
onDeepCopy: false,
19+
callback: function() {}
20+
};
21+
22+
var WT = $.wt = function () {
23+
WT.open.apply( this, arguments );
24+
25+
};
26+
// We can use the extend method to merge options/settings as usual:
27+
// But with the added first parameter of TRUE to signify a DEEP COPY:
28+
// var settings = $.extend( true, {}, defaults );
29+
30+
$.extend(WT,{
31+
open: function(opts){
32+
var settings = $.extend(true, defaults, opts );
33+
34+
console.log(this)
35+
settings.callback.apply(this);
36+
return this;
37+
}
38+
});
39+
var methods = {
40+
init : function(options , callback) {
41+
42+
debug( this );
43+
var settings = $.extend(options.onDeepCopy || false,defaults, options );
44+
console.log("wt default parameter objects: " , settings.params);
45+
callback.call(this, options);
46+
return this;
47+
},
48+
apply : function(options) {
49+
//settings = $.extend( true,settings, options );
50+
51+
$(this).each(function(index,el) {
52+
$(el).on('click',function(e){
53+
var settings = $.extend( defaults, options );
54+
55+
56+
console.log("click",$.json2array(settings.params));
57+
//callback
58+
59+
dcsMultiTrack.apply(this,$.json2array(settings.params));
60+
settings.onTracking.call(this);
61+
62+
return false;
63+
});
64+
});
65+
return this;
66+
},// IS
67+
hide : function( ) { },// GOOD
68+
showParams : function( content ) {
69+
//console.log(defaults.params);
70+
return this;
71+
}
72+
73+
};
74+
75+
76+
// Plugin definition.
77+
$.fn.wt = function(methodOrOptions) {
78+
79+
if ( methods[methodOrOptions] ) {
80+
return methods[ methodOrOptions ].apply( this, Array.prototype.slice.call( arguments, 1 ));
81+
} else if ( typeof methodOrOptions === 'object' || ! methodOrOptions ) {
82+
// Default to "init"
83+
return methods.init.apply( this, arguments );
84+
} else {
85+
$.error( 'Method ' + methodOrOptions + ' does not exist on jQuery.wt' );
86+
}
87+
};
88+
89+
// Private function for debugging.
90+
function debug( obj ) {
91+
if ( window.console && window.console.log ) {
92+
window.console.log( "wt selection count: " + obj.length );
93+
}
94+
};
95+
96+
97+
98+
})( jQuery );
99+
/*!
100+
* jQuery lightweight plugin boilerplate
101+
* Original author: @ajpiano
102+
* Further changes, comments: @addyosmani
103+
* Licensed under the MIT license
104+
*/
105+
106+
107+
// the semi-colon before the function invocation is a safety
108+
// net against concatenated scripts and/or other plugins
109+
// that are not closed properly.
110+
;(function ( $, window, document, undefined ) {
111+
112+
// undefined is used here as the undefined global
113+
// variable in ECMAScript 3 and is mutable (i.e. it can
114+
// be changed by someone else). undefined isn't really
115+
// being passed in so we can ensure that its value is
116+
// truly undefined. In ES5, undefined can no longer be
117+
// modified.
118+
119+
// window and document are passed through as local
120+
// variables rather than as globals, because this (slightly)
121+
// quickens the resolution process and can be more
122+
// efficiently minified (especially when both are
123+
// regularly referenced in our plugin).
124+
125+
// Create the defaults once
126+
var pluginName = "defaultPluginName",
127+
defaults = {
128+
propertyName: "value"
129+
};
130+
131+
// The actual plugin constructor
132+
function Plugin( element, options ) {
133+
this.element = element;
134+
135+
// jQuery has an extend method that merges the
136+
// contents of two or more objects, storing the
137+
// result in the first object. The first object
138+
// is generally empty because we don't want to alter
139+
// the default options for future instances of the plugin
140+
this.options = $.extend( {}, defaults, options) ;
141+
142+
this._defaults = defaults;
143+
this._name = pluginName;
144+
145+
this.init();
146+
}
147+
148+
Plugin.prototype.init = function () {
149+
// Place initialization logic here
150+
// We already have access to the DOM element and
151+
// the options via the instance, e.g. this.element
152+
// and this.options
153+
};
154+
155+
// A really lightweight plugin wrapper around the constructor,
156+
// preventing against multiple instantiations
157+
$.fn[pluginName] = function ( options ) {
158+
return this.each(function () {
159+
if ( !$.data(this, "plugin_" + pluginName )) {
160+
$.data( this, "plugin_" + pluginName,
161+
new Plugin( this, options ));
162+
}
163+
});
164+
}
165+
166+
})( jQuery, window, document );
167+
168+
169+
/* [URL] */
170+
;(function(defaults, $, window, document, undefined) {
171+
172+
'use strict';
173+
174+
$.extend({
175+
// Function to change the default properties of the plugin
176+
// Usage:
177+
// jQuery.pluginSetup({property:'Custom value'});
178+
webtrendsSetup : function(options) {
179+
return $.extend(defaults, options);
180+
}
181+
}).fn.extend({
182+
// Usage:
183+
// jQuery(selector).pluginName({property:'value'});
184+
webtrends : function(options) {
185+
186+
options = $.extend(true,{}, defaults, options);
187+
188+
return $(this).each(function() {
189+
190+
console.log(options.parameters);
191+
192+
options.callback.call(this);
193+
// Plugin logic
194+
// Calling the function:
195+
// jQuery(selector).pluginName(options);
196+
});
197+
},
198+
otherMethod : function() {
199+
console.log("test",defaults);
200+
// Some logic
201+
// Calling the function:
202+
// jQuery(selector).otherMethod(options);
203+
return this;
204+
}
205+
});
206+
})({
207+
property : '',
208+
callback: function() {},
209+
otherProperty : "value"
210+
}, jQuery, window, document);
211+
212+
213+
214+
$.fn.wt.defaults = {
215+
onTracking : function() {}
216+
};
217+
218+
$.fn.wt.format = function( txt ) {
219+
return "<b>" + txt + "</b>";
220+
};
221+
222+
223+
224+
225+
226+
227+
228+
229+
230+
231+
232+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
233+
<html xmlns="http://www.w3.org/1999/xhtml">
234+
<head>
235+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
236+
<title>Webtrends jQuery Plugins</title>
237+
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
238+
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
239+
<script src="//localhost/MI/webtrends.js"></script>
240+
<script src="webtrends.jquery.v0.0.1.js"></script>
241+
<script>
242+
$(document).ready(function(){
243+
244+
/* $("#idLink").wt("apply",{
245+
246+
params: {
247+
"DCS.dcssip": "www.facebook.com",
248+
"WT.dl": "99"
249+
}
250+
,onDeepCopy : true
251+
});
252+
253+
254+
$(".nav").find("a").wt("apply");
255+
256+
257+
$(document).wt("showParams");
258+
259+
$.wt.open("callback",function(){
260+
alert(1);
261+
});*/
262+
263+
$.webtrendsSetup({
264+
parameters: {
265+
'DCS.dcssip': "www.helllo.com",
266+
'DCS.dcsuri':'/solutions/default.asp',
267+
'DCS.dcsqry':'tab=Products'
268+
},
269+
otherProperty: "newValue"
270+
});
271+
272+
273+
274+
275+
$("a").webtrends({
276+
property: "Hello I'll be replaced by callbacks",
277+
callback: function(){
278+
$.webtrendsSetup()[$(this).text()] = 1;
279+
$(this).webtrends({
280+
parameters :{ 'DCS.dcssip': $(this).text()}
281+
});
282+
283+
console.log("Webtrends current setup : " , $.webtrendsSetup());
284+
}
285+
286+
287+
});
288+
289+
290+
});
291+
</script>
292+
</head>
293+
294+
<body>
295+
<ul class="nav">
296+
<li><a href="#">Link one</a></li>
297+
<li><a href="#">Link two</a></li>
298+
<li><a href="#">Link three</a></li>
299+
<li><a href="#">Link four</a></li>
300+
</ul>
301+
<p>Link P</p>
302+
<br>
303+
<a href="#" id="idLink">Link by ID</a>
304+
</body>
305+
</html>
306+
307+
308+
309+
310+
311+
312+
313+
314+
315+
316+
317+
318+
319+
320+
321+
322+
323+
324+
325+
326+
327+
328+
329+
330+
331+
332+
333+

0 commit comments

Comments
 (0)