forked from bombledmonk/advancedsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdklib.js
1186 lines (1019 loc) · 47.8 KB
/
dklib.js
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(function($){
jQuery.fn.gmload = function( url, params, callback ) {
var rscript = /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi;
if ( typeof url !== "string" && _load ) {
return _load.apply( this, arguments );
}
// Don't do a request if no elements are being requested
if ( !this.length ) {
return this;
}
var selector, type, response,
self = this,
off = url.indexOf(" ");
if ( off >= 0 ) {
selector = url.slice( off, url.length );
url = url.slice( 0, off );
}
// If it's a function
if ( jQuery.isFunction( params ) ) {
// We assume that it's the callback
callback = params;
params = undefined;
// Otherwise, build a param string
} else if ( params && typeof params === "object" ) {
type = "POST";
}
GM_xmlhttpRequest({
method: "GET",
url: url,
headers: {
"User-Agent": "Mozilla/5.0", // If not specified, navigator.userAgent will be used.
"Accept": "text/xml" // If not specified, browser defaults will be used.
},
onload: function(response) {
var responseXML = null;
// Inject responseXML into existing Object (only appropriate for XML content).
if (!response.responseXML) {
responseXML = new DOMParser()
.parseFromString(response.responseText, "text/xml");
}
// See if a selector was specified
self.html( selector ?
// Create a dummy div to hold the results
jQuery("<div>")
// inject the contents of the document in, removing the scripts
// to avoid any 'Permission Denied' errors in IE
.append( response.responseText.replace( rscript, "" ) )
// Locate the specified elements
.find( selector ) :
// If not, just inject the full result
response.responseText );
callback();
}
});
};
})(jQuery);
$.extend($.expr[":"], {
exactly: function( element, index, details, collection ){
return $(element).text().trim() === details[3];
}
});
// // Loging function
// function _log(somestring, detailed_logging){
// if (detailed_logging == null) detailed_logging=true;
// try{
// if(detailed_logging == true){unsafeWindow.console.log((Date.now()-starttimestamp)+'ms '+(Date.now()-sincelast)+'[as] '+somestring);}
// sincelast = Date.now();
// }
// catch(err){}
// }
jQuery.expr.filters.offscreen = function(el) {
return (
(el.offsetLeft + el.offsetWidth) < 0 ||
(el.offsetTop + el.offsetHeight) < 0 ||
(el.offsetLeft > window.innerWidth || el.offsetTop > window.innerHeight)
);
};
(function($){
$.fn.lazybind = function(event, fn, timeout, abort){
var timer = null;
$(this).bind(event, function(){
timer = setTimeout(fn, timeout);
});
if(abort == undefined){
return;
}
$(this).bind(abort, function(){
if(timer != null){
clearTimeout(timer);
}
});
};
})(jQuery);
// Reusable generic function
function surroundMatchingText(textNode, regex, surrounderCreateFunc) {
var parent = textNode.parentNode;
var result, surroundingNode, matchedTextNode, matchLength, matchedText;
while ( textNode && (result = regex.exec(textNode.data)) ) {
matchedTextNode = textNode.splitText(result.index);
matchedText = result[0];
matchLength = matchedText.length;
textNode = (matchedTextNode.length > matchLength) ?
matchedTextNode.splitText(matchLength) : null;
surroundingNode = surrounderCreateFunc(matchedTextNode.cloneNode(true));
parent.insertBefore(surroundingNode, matchedTextNode);
parent.removeChild(matchedTextNode);
}
}
// This function does the surrounding for every matched piece of text
// and can be customized to do what you like
function createSpan(matchedTextNode) {
var el = document.createElement("span");
el.style.backgroundColor = "lightgreen";
el.appendChild(matchedTextNode);
return el;
}
// The main function
function wrapText(container, text) {
text = text.replace(/\W/gi,'');
var wordsToHighlight = text.trim().split(' ');
//_log(wordsToHighlight, DLOG);
for (var x=0; x < wordsToHighlight.length; x++){
surroundInElement(container, new RegExp(wordsToHighlight[x], "gi"), createSpan);
}
}
//Functions off of a stack exchange post
// Reusable generic function
function surroundInElement(el, regex, surrounderCreateFunc) {
// script and style elements are left alone
if (!/^(script|style)$/.test(el.tagName)) {
var child = el.lastChild;
while (child) {
if (child.nodeType == 1) {
surroundInElement(child, regex, surrounderCreateFunc);
} else if (child.nodeType == 3) {
surroundMatchingText(child, regex, surrounderCreateFunc);
}
child = child.previousSibling;
}
}
}
function askpermission(theversion){
if(localStorage.getItem('achoice') == undefined){
var conf = confirm('---- Message from advancedsearch Greasemonkey userscript author ----\n\n Can I collect some analytics to help improve this script? \n\n Please say yes (OK)... It will make a big difference in the future. To opt out click Cancel.\n\nYou can turn this on or off in the +controls+ menu at any point in the future.');
if (conf){
addpiwik(theversion);
localStorage.setItem('achoice', 1);
localStorage.setItem('analytics', 1);
$('#analytics').prop('checked', 1);
$('#analytics').val(1);
}else{
localStorage.setItem('achoice', 0);
}
}else if (localStorage.getItem('analytics') == 1){
addpiwik(theversion);
}else {}
}
function htmlEscape(str) {
return String(str)
.replace(/&/g, '&')
.replace(/"/g, '"')
.replace(/'/g, ''')
.replace(/</g, '<')
.replace(/>/g, '>');
}
function htmlUnescape(value){
return String(value)
.replace(/"/g, '"')
.replace(/'/g, "'")
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/&/g, '&');
}
function addpiwik(theversion){
// _log('addpiwik() Start',DLOG);
// console.log(version);
var theuid = getID();
var webref = document.referrer.toString();//.replace(/\&/g, '_');
var docloc = document.location.toString().replace(/\&/g, 'xxx');
var iview = 'c:'+localStorage.getItem('columnchooserstate') +
' q:' + localStorage.getItem('qfLocation')+
' w:' + localStorage.getItem('wrapFilters')+
' e:' + localStorage.getItem('exploremodecheckbox')+
' d:' + localStorage.getItem('datasheetchooserinput');
var cvar = '{"1":["version", "'+theversion+'"], "2":["iview", "'+iview+'"]}';
// var docloc = document.location.toString().replace(/\&/g, '&');
// _log(docloc, DLOG);
var imgsrc = ('https://he-st.com/p/piwik.php?idsite=1&rec=1'+
'&url='+ encodeURIComponent( docloc) +
'&_id='+ encodeURIComponent( theuid) +
// '&action_name='+ webref +
'&res='+ window.screen.availHeight + 'x' + window.screen.availWidth +
'&_cvar='+ encodeURIComponent(cvar)
);
$('body').append('<img src="'+imgsrc+'" style="border:0" alt="" />');
// _log('addpiwik() End',DLOG);
}
//change contains expression to case insensitive
jQuery.expr[':'].contains = function(a, i, m) {
return jQuery(a).text().toUpperCase().indexOf(m[3].toUpperCase()) >= 0;
};
function selectorEscape(str) {
//escapes special characters so a string can safely be used for class names and in selectors.
if (str){return str.replace(/([ #;?%&,.+*~\':"!^$[\]()=>|\/@])/g,'');}
return str;
}
function string2form(form, serializedStr) {// Unused
var fields = JSON.parse(serializedStr);
for(var i = 0; i < fields.length; i++) {
var controlName = fields[i].name;
var controlValue = fields[i].value;
form.find("[name='" + controlName + "']").val(controlValue);
}
}
function getID(){
// console.log('getid ', localStorage.getItem('uid').length, 'uid ', localStorage.getItem('uid'));
if (localStorage.getItem('uid') == null){
var y = '';
var possible = "ABCDEF0123456789";
for( var i=0; i < 16; i++ ){
y += possible.charAt(Math.floor(Math.random() * possible.length));
}
localStorage.setItem('uid', y);
return y;
}
else { return localStorage.getItem('uid'); }
}
//highlighting function
(function($) {
$.fn.highlight = function(str, className) {
str = str.replace(/\W/gi, '');
var regex = new RegExp(str, "gi");
return this.each(function() {
$(this).contents().filter(function() {
return this.nodeType == 3 && regex.test(this.nodeValue);
}).replaceWith(function() {
return(this.nodeValue || "").replace(regex, function(match) {
return "<span class=\"" + className + "\">" + match + "</span>";
});
});
});
};
})(jQuery);
function uniqueArray(ar) {
var f = {},
i = 0,
l = ar.length,
r = [];
while (i < l) {
!f[ar[i]] && r.push(ar[i]);
f[ar[i++]] = 1;
}
return r;
}
function trim (str) {
//TODO de-globalize
str = str.replace(/^\s\s*/, ''),
ws = /\s/,
i = str.length;
while (ws.test(str.charAt(--i)));
return str.slice(0, i + 1);
}
function getQuerystring(key, default_) {
if(default_ == null) default_ = "";
key = key.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + key + "=([^&#]*)", 'i');
var qs = regex.exec(window.location.href);
if(qs == null) return default_;
else return qs[1];
}
// ------------- Hibernating code -----------------
//function addProductDrawer(){//No longer used, but here for reference
// //localStorage.setItem('drawercontent', $(this).html());
// //$(this).remove();
// $('#content').after(
// '<div id=pDrawer class=container>'+
// '<div id=pDrawerCont style="float:left;" class="left"></div>'+
// '<div id=pDrawerHandle style="float:left" class="right">C</div>'+
// '</div>'
// );
// $('#pDrawer').append(localStorage.getItem('drawercontent'));
// $('#pDrawer').css({
// 'position': 'fixed',
// 'width': '340px',
// 'height': '100%',
// 'right': '0px',
// 'top': '50px',
// //'bottom': '50px',
// 'font-size': '15px',
// 'backgroundColor': '#CCC',
// 'border': '1px solid #CCC',
// "borderRadius": "5px 0px 0px 5px",
// 'padding': '5px',
// //'box-shadow': ' 1px 1px 2px #888',
// 'overflow': 'auto'
// });
// $('#pDrawerCont').css({
// //'float': 'left',
// 'width': $('#pDrawer').width()-10,
// });
// $('#pDrawerHandle').css({
// //'float': 'left',
// //'line-height': '100%',
// //'position': 'absolute',
// 'height' : '100%',
// 'background': 'white',
// 'width': '10px',
// "borderRadius": "5px 0px 0px 5px",
// 'cursor': "pointer"
// });
// $('#pDrawerHandle').click(function(){
// _log('sliding right');
// //$('#pDrawer').animate({'width':'10px'});
// // $('#pDrawer').toggle(
// // function(){
// // $(this).css({'overflow': ''});
// // $(this).animate({'width':'10px'});
// // }, function(){
// // $(this).css({'overflow': 'auto'});
// // $(this).animate({'width':'340px'});
// // });
// });
// // $('.clear').css({
// // 'clear': 'both',
// // });
// //GM_addStyle('.clearfix:after {visibility: hidden;display: block;font-size: 0;content: " ";clear: both;height: 0;} * html .clearfix { zoom: 1; } /* IE6 */ *:first-child+html .clearfix { zoom: 1; } /* IE7 */');
// $('.category').css({
// 'cursor': 'pointer',
// });
// $('.category').click(function(){
// //$('#pDrawerCont').find('ul').toggle(false);
// $('.category').not(this).next('ul').toggle(false);
// $('.category').not(this).find('.plus').toggle(true);
// $('.category').not(this).find('.minus').toggle(false);
// $(this).next('ul').toggle();
// $(this).find('.minus,.plus').toggle();
// // $(this).next('ul').toggle(
// // function(){
// // $(this).show().height('0%');
// // $(this).animate({'height': '100%'}, 200);
// // $(this).parent().find('.catexpandplus').hide();
// // $(this).parent().find('.catexpandminus').show();
// // },
// // function(){
// // $(this).parent().find('.catexpandplus').show();
// // $(this).parent().find('.catexpandminus').hide();
// // }
// // );
// //$(this).find('.catexpand').toggle();
// });
// }
// function updateProductDrawer(){//No longer used, but here for reference
// var d = new Date();
// localStorage.removeItem('drawerupdate');
// if (localStorage.getItem('drawerupdate')==null || localStorage.getItem('drawerupdate')+86400000 < d.getTime()){
// localStorage.setItem('drawerupdate', d.getTime());
// _log('drawer '+ localStorage.getItem('drawercontent')+ ' drawerupdate ' +localStorage.getItem('drawerupdate'));
// saveProductDrawer();
// }
// else if(localStorage.getItem('drawerupdate')+86400000 > d.getTime()){
// addProductDrawer();
// }
// //_log(d.getTime()+' drawer '+ localStorage.getItem('drawercontent').length+ ' drawerupdate ' +localStorage.getItem('drawerupdate'));
// }
// function saveProductDrawer(){//No longer used, but here for reference
// $('<div>').load('http://www.digikey.'+theTLD+'/product-search/en #content', function(){
// $(this).find('hr,h1,p,form').remove();
// $(this).find('#content').children().unwrap();
// $(this).html( $(this).html().replace(/h2/gi, 'div'));
// $(this).find('.catfiltertopitem').removeClass('catfiltertopitem').addClass('category');
// $(this).find('ul').css({
// 'display': 'none',
// });
// $(this).find('.category>a').each(function(){
// $(this).before('<span class="toggler plus">+ </span><span class="toggler minus" style="display:none">- </span>'+$(this).text()+' ');
// $(this).text('(link)');
// });
// localStorage.setItem('drawercontent', $(this).html());
// addProductDrawer();
// });
// }
// function processURL() {/* TODO UNUSED - functionality to parse the search string and preselect values in the drill down search*/
// _log(window.location.search);
// _log(decodeURIComponent(window.location.search));
// var searchString = decodeURIComponent(window.location.search);
// var fVOLT = rVOLT.exec(searchString)[0].replace('=', '');
// _log( fVOLT);
// if(fVOLT) {
// _log($('select[name="PV48"]').find('option:contains('+fVOLT+')').size());
// vopt = $('select[name="PV48"]').find('option:contains(' + fVOLT + ')');
// _log(vopt.size());
// var x = 0;
// for(x; x < vopt.size(); x++) {
// var myregex = new RegExp('([^.\d])(' + fVOLT + '|' + fVOLT.replace(/\s/g, '') + ')', 'i');
// if((/(\b|[^.])5v/i).test(vopt[x].text)) {
// _log(vopt[x].text.replace(/\s/g,''));
// }
// }
// }
// }
// function sortingExample(){ //unused keep for example
// var ind = $(this).index();
// var rows = $('#productTable>tbody>tr').sort(function(a,b){
// var atext = $(a).find('td').eq(ind).text();
// var btext = $(b).find('td').eq(ind).text();
// var anum = parseFloat(atext);
// var bnum = parseFloat(btext)
// //console.log(anum , bnum);
// if(isNaN(anum-bnum)) {
// return (isNaN(anum)) ? 1 : 0;
// }
// else{
// return parseFloat(atext) - parseFloat(btext);
// }
// });
// $('#productTable>tbody').append(rows);
// }
// extra regexs to save for later
//frnum = /(\W|\b)([0-9]+)(\.)?[0-9]*[\s\+]?/; // fractional number
//VOLT = /\s?(volts?|voltage|v-?ac|v-?dc|v)\b/;
//rVOLT = new RegExp(frnum.source + VOLT.source, 'i');
// AMP = /\s?(amps?|a)\\b/i;
// VOLTAMP = /\s?(va)\\b/i;
// OHM = /\s?(ohms?|meg|resistors?|res|pot)\\b/i;
// CAP = /\s?(farads?|f|cap(acitor)?)\\b/i;
// INDUCTOR = /\s?(henry|h)\\b/i;
// MEMORY = /\s?(byte|b)\\b/i;
// METER = /\s?(meters?|m)\\b/i;
// INCH = /[\s]?(inches|inch|(?<![a-z])in|\")\\b/i;
// FOOT = /\s?(feet|foot|ft|\')\\b/i;
// HERTZ = /\s?(hertz|hz)\\b/i;
// TEMP = /\s?(degrees\s[fc]|deg\s[fc])\\b/i;
// SECOND = /\s?(second|sec|s)\\b/i;
// function getFamilyLinkOLD(){
// _log('getFamilyLink() Start',DLOG);
// var myhref = $('h1.seohtagbold').find('a:last').attr('href').split('?')[0];
// var myhtml = $('h1.seohtagbold').html();
// var thesplit = myhtml.split(/>/g);
// var mypop = thesplit.pop();
// var modifiers = $('#mainform input[type=checkbox], #mainform input[name=quantity], #mainform input[name=ColumnSort]').serialize()+'&akamai-feo=off';
// //this needs to remain in this logical order of replacement to get desired results. Do not combine.
// var finalhref = myhref+'/'+mypop.toLowerCase().trim()
// .replace(' ','')
// .replace('\/', '-')
// .replace(/-\s/,'')
// .replace(/[,\(\)]/g,'')
// .replace(/ |\s/g,'-')
// .replace('---','-')+
// '?'+modifiers;
// _log('getFamilyLink() End',DLOG);
// return finalhref;
// }
//No longer used, but here for reference
//SAVE FOR REFERENCE
// var tablelen = $('#mainform>th').length;
// var maxHeight = Math.max.apply(null, $('#mainform>table>tbody').map(function (){
// return $(this).height();
// }).get());
// function addDocRetrieve(){//No longer used, but here for reference
// $('#productTable tr a').find('img[src*="8S0j5"],img[src*="datasheet.gif"]').parent().parent()
// .append('<br><div class="documentation pointer" style="margin-top:3px; line-height:10px">more v</div>');
// $('.documentation').each(function(){
// var mylink = $(this).closest('tr').find('a[href*=-ND]:first').attr('href');
// });
// var docConfig = {
// id:'docHover',
// title : 'More Related Documents',
// message : 'Loading....',
// hoverOver : $('.documentation'),
// //height : '220px',
// width :'400px',
// interactive : true,
// my : 'left top',
// at : 'right top',
// offset :'5 -35',
// someFunc : loadDocs
// };
// createHoverWindow(docConfig);
// }
// function loadDocs($hoveredObj){//No longer used, but here for reference
// $('#docHoverContent').text('Loading....');
// var mylink = $hoveredObj.closest('tr').find('a[href*=-ND]:first').attr('href');
// $('#docHoverContent').load(mylink+ ' table:contains("Datasheets"):first', function(){
// $(this).find('tr')
// .not(':contains(Datasheets)')
// .not(':contains("Product Training")')
// .not(':contains("Reference Design Library")')
// .not(':contains("Reference Design Library")')
// .hide();
// $(this).find('td .beablock').hide();
// });
//buglist
//http://www.digikey.com/product-detail/en/TEACL-PIC-LV/658-1020-5-ND/1687139
// }
// // associated parts function.
// var apOld = (function(){
// var columnList = [
// {'name':'Image', 'f': detailPageInfo.getImage,},
// {'name':'Manufacturer Part Number', 'f':detailPageInfo.getMPN},
// {'name':'Manufacturer', 'f':detailPageInfo.getManufacturer},
// {'name':'Description', 'f':detailPageInfo.getDescription},
// {'name':'Packaging', 'f':detailPageInfo.getPackaging},
// {'name':'Unit Price', 'f':detailPageInfo.getUnitPrice},
// {'name':'Quantity Available', 'f':detailPageInfo.getQuantityAvailable},
// {'name':'Min Quantity', 'f':detailPageInfo.getMinQuantity}
// ];
// var cLen = columnList.length;
// var perPage = 5;
// var buildProductViewerBox = function(item){
// var firstRowHTML = '';
// for (var z=0; z<columnList.length; z++){
// firstRowHTML = firstRowHTML+ '<th>' + columnList[z].name + '</th>';
// }
// var allRows = ''
// for(var z=0; z<item.list.length; z++){
// allRows = allRows + buildRowHTML(item.list[z]);
// }
// var itemSel = selectorEscape(item.title)
// $('#additional-product-options-section').append(
// '<div id="asd-id-'+itemSel+'" class="asd-containerOld panel panel-default">'+
// '<div class="asd-title panel-heading">'+item.title+' ('+ item.list.length +')</div>'+
// '<div class="asd-content panel-body">'+
// '<table id="table-'+itemSel+'" class="asd-table tstripe"> '+
// '<thead><tr>'+firstRowHTML+'</tr></thead>'+
// '<tbody>'+allRows+'</tbody>'+
// '</table>'+
// '</div>'+
// '</div>'
// );
// $('#asd-id-'+itemSel).data('itemlist', item.list);
// $('#table-'+itemSel).find('tbody tr').each(function(ind){
// $(this).data('linkobj',item.list[ind]);
// $(this).data('boxSel', $('#asd-id-'+itemSel));
// });
// $('#table-'+ itemSel).find('tbody>tr').slice(perPage).hide();
// if (item.list.length > perPage){
// addPageination(itemSel, item.list.length);
// }
// addFilterAllForm($('#asd-id-'+itemSel));
// var listlength = (item.list.length >= perPage) ? perPage :item.list.length;
// for(var z=0; z<listlength; z++){
// getDetailPage(item.list[z], $('#asd-id-'+itemSel));
// }
// },
// addPageination = function (itemSel, listLen) {
// $('#asd-id-'+itemSel).find('.asd-content').append('<div class="pagination page-'+itemSel+'">'+
// '<a href="#" class="first" data-action="first">«</a>'+
// '<a href="#" class="previous" data-action="previous">‹</a>'+
// '<input type="text" readonly="readonly" data-max-page="'+Math.ceil(listLen/perPage)+'" />'+
// '<a href="#" class="next" data-action="next">›</a>'+
// '<a href="#" class="last" data-action="last">»</a>'+
// '</div>');
// $('.page-'+itemSel).jqPagination({
// paged: function(page) {
// var $rows = $('#table-'+itemSel+' tbody > tr')
// $rows.hide()// do something with the page variable
// var $showing = $rows.slice((page*5 - 5),(page * 5)).show()// do something with the page variable
// $showing.not('.filled').each(function(){
// getDetailPage($(this).data('linkobj'), $(this).data('boxSel'));
// })
// }
// });
// }
// buildRowHTML = function(pnlinkobj){
// var row = "";
// for (var i = 0; i < columnList.length; i++) {
// row = row + '<td class="col-'+selectorEscape(columnList[i].name)+'"></td>';
// };
// row = '<tr class="'+selectorEscape(pnlinkobj.pn)+'">' + row + '</tr>'
// return row;
// },
// getDetailPage = function (pnlinkobj, $boxSel){
// var jqxhr = $.get(pnlinkobj.href)
// .done(function(data){
// var $d = $(data);
// fillRow($d, pnlinkobj, $boxSel)
// })
// .fail(function(){console.log(pnlinkobj, ' failed');})
// .always(function(){});
// },
// fillRow = function ($DetailPageContent, pnlinkobj, $boxSel){
// var rowSel = selectorEscape(pnlinkobj.pn);
// var row = $('.'+rowSel);
// for (var x=0; x<cLen; x++){
// row.not('.filled').find('.col-'+selectorEscape(columnList[x].name)).append(columnList[x].f($DetailPageContent));
// if (x < 2){ row.find('.col-'+selectorEscape(columnList[x].name)).contents().wrap('<a href="'+pnlinkobj.href+'" />') ; }
// }
// row.addClass('filled');
// console.log('addrowdone');
// },
// getAssociationListFromElem = function (parentElem){
// var pnlinkarray = []
// parentElem.find('.more-expander-item').each(function(){
// pnlinkarray.push({
// 'href': $(this).find('a:first').attr('href'),
// 'pn': $(this).find('a:first').text()
// });
// });
// //console.log(pnlinkarray);
// return pnlinkarray;
// },
// addFilterAllForm = function($boxSel){
// var pnlist = '';
// var itemlist = $boxSel.data('itemlist');
// itemlist.forEach(function(x){ pnlist = pnlist+'<input type=hidden name="part" value="'+x.pn+'">'});
// console.log(pnlist);
// var formHTML = '<div style="float:right;"><div style="clear:both; margin:0px 15px 1px 0px;"><form action="/scripts/DkSearch/dksus.dll" method=get>'+
// '<input type=submit value="View All '+itemlist.length+'">'+ '<input id="associatedInStock" type="checkbox" class="css-checkbox"><label class="css-label" for="associatedInStock">In Stock</label>'+
// pnlist+
// '</form></div></div><div style="clear:both;"></div>';
// $boxSel.find('.asd-content').append(formHTML);
// },
// addAssociatedImageHover = function(){
// _log('associatedImageHover() Start',DLOG);
// $('body').append('<img border="0/" src="" style="heightdisplay: none; height:200px; width:200px; box-shadow: 0 0 10px 5px #888; position:absolute;" class="pszoomie2 psshadow" id="pszoomie2">');
// $('.asd-containerOld').hoverIntent({
// over: function () {
// $('#pszoomie2').attr('src','');
// $('#pszoomie2')
// .attr('src', $(this).attr('src'))
// .show('fade', 200)
// .position({
// my : 'right middle',
// at : 'left middle',
// of: $(this),
// offset : '-10 0',
// collision : 'fit fit'
// });
// },
// out: function () {
// $('.pszoomie2').fadeOut(100);
// },
// 'selector': '.col-Image img'
// }
// );
// _log('associatedImageHover() End',DLOG);
// },
// addAssociatedProductViewer = function (){
// var boxDataArray = [];
// // $('.expander-div-10').each(function(){
// // boxDataArray.push({
// // 'title': $(this).closest('tr').find('th').text(),
// // 'list':getAssociationListFromElem($(this))
// // });
// // $(this).closest('tr').hide()
// // });
// $('.expander-div-5').each(function(){
// if($(this).find('.product-details-also-evaluated').length < 1){
// boxDataArray.push({
// 'title': $(this).parent().find('.bota-headline').text().split('\n')[0],
// 'list':getAssociationListFromElem($(this))
// });
// }
// });
// $('#additional-product-options-section .bota').hide();
// for (var i=0; i<boxDataArray.length; i++){
// buildProductViewerBox(boxDataArray[i]);
// }
// addAssociatedImageHover();
// };
// return {'addAssociatedProductViewer': addAssociatedProductViewer};
// })();
// var ap= (function(){
// var columnList = [
// {'name':'Image', 'f': detailPageInfo2.getImage,},
// {'name':'Manufacturer Part Number', 'f':detailPageInfo2.getMPN},
// {'name':'Manufacturer', 'f':detailPageInfo2.getManufacturer},
// {'name':'Description', 'f':detailPageInfo2.getDescription},
// // {'name':'Packaging', 'f':detailPageInfo2.getPackaging},
// {'name':'Unit Price', 'f':detailPageInfo2.getUnitPrice},
// {'name':'Quantity Available', 'f':detailPageInfo2.getQuantityAvailable},
// // {'name':'Min Quantity', 'f':detailPageInfo2.getMinQuantity}
// ];
// var assTypes = [
// "MatingProducts",
// "AssociatedProduct"
// ];
// // reference: description, detailLink, imageLink, manufacturer, manufacturerPartNumber, minimumOrderQuantity,
// // nonStock, packageType, quantityAvailable, reportPartNumber, unitPrice
// var cLen = columnList.length;
// var perPage = 5;
// var buildProductViewerBox = function(associationSet){
// var firstRowHTML = '';
// for (var z=0; z<columnList.length; z++){
// firstRowHTML = firstRowHTML+ '<th>' + columnList[z].name + '</th>';
// }
// var allRows = '';
// for(var z=0; z<associationSet.list.length; z++){
// allRows = allRows + buildRowHTML(associationSet.list[z]);
// }
// var escTitle = selectorEscape(associationSet.title);
// $('#additional-product-options-section').append(
// '<div id="asd-id-'+escTitle+'" class="asd-container panel panel-default">'+
// '<div class="asd-title panel-heading">'+associationSet.title+' ('+ associationSet.list.length +')</div>'+
// '<div class="asd-content panel-body">'+
// '<table id="table-'+escTitle+'" class="asd-table tstripe"> '+
// '<thead><tr>'+firstRowHTML+'</tr></thead>'+
// '<tbody>'+allRows+'</tbody>'+
// '</table>'+
// '</div>'+
// '</div>'
// );
// $('#asd-id-'+escTitle).data('associationSetlist', associationSet.list);
// $('#table-'+escTitle).find('tbody tr').each(function(ind){
// $(this).data('linkobj',associationSet.list[ind]);
// $(this).data('boxSel', $('#asd-id-'+escTitle));
// });
// $('#table-'+ escTitle).find('tbody>tr').slice(perPage).hide();
// if (associationSet.list.length > perPage){
// addPageination(escTitle, associationSet.list.length);
// }
// addFilterAllForm($('#asd-id-'+escTitle), associationSet.viewAllLink, associationSet.list.length); //addback
// var listlength = (associationSet.list.length >= perPage) ? perPage :associationSet.list.length;
// for(var z=0; z<listlength; z++){
// var associationSetData = $('#table-'+escTitle).find('.'+selectorEscape(associationSet.list[z].manufacturerPartNumber)).data('linkobj');
// var $boxSel = $('#table-'+escTitle).find('.'+selectorEscape(associationSet.list[z].manufacturerPartNumber)).data('boxSel');
// fillRow(associationSetData , $boxSel);
// }
// },
// fillRow = function (itemData, $boxSel){
// var rowSel = selectorEscape(itemData.manufacturerPartNumber);
// var row = $('.'+rowSel);
// for (var x=0; x<cLen; x++){
// row.not('.filled').find('.col-'+selectorEscape(columnList[x].name)).append(columnList[x].f(itemData));
// if (x < 2){ row.find('.col-'+selectorEscape(columnList[x].name)).contents().wrap('<a href="'+itemData.detailLink+'" />') ; }
// }
// row.addClass('filled');
// },
// addPageination = function (itemSel, listLen) {
// $('#asd-id-'+itemSel).find('.asd-content').append('<div class="pagination page-'+itemSel+'">'+
// '<a href="#" class="first" data-action="first">«</a>'+
// '<a href="#" class="previous" data-action="previous">‹</a>'+
// '<input type="text" readonly="readonly" data-max-page="'+Math.ceil(listLen/perPage)+'" />'+
// '<a href="#" class="next" data-action="next">›</a>'+
// '<a href="#" class="last" data-action="last">»</a>'+
// '</div>');
// $('.page-'+itemSel).jqPagination({
// paged: function(page) {
// var $rows = $('#table-'+itemSel+' tbody > tr');
// $rows.hide()// do something with the page variable
// var $showing = $rows.slice((page*5 - 5),(page * 5)).show()// do something with the page variable
// $showing.not('.filled').each(function(){
// var itemData = $(this).data('linkobj');
// var $boxSel = $(this).data('boxSel');
// fillRow(itemData, $boxSel)
// // getDetailPage($(this).data('linkobj'), $(this).data('boxSel'));
// })
// }
// });
// },
// buildRowHTML = function(item){
// var row = "";
// for (var i = 0; i < columnList.length; i++) {
// row = row + '<td class="col-'+selectorEscape(columnList[i].name)+'"></td>';
// };
// row = '<tr class="'+selectorEscape(item.manufacturerPartNumber)+'">' + row + '</tr>'
// return row;
// },
// getAssociationListFromElem = function (parentElem){
// var pnlinkarray = []
// parentElem.find('.more-expander-item').each(function(){
// pnlinkarray.push({
// 'href': $(this).find('a:first').attr('href'),
// 'pn': $(this).find('a:first').text()
// });
// });
// console.log('>>>>>>>>>>>',pnlinkarray);
// return pnlinkarray;
// },
// addFilterAllForm = function($boxSel,viewAllLink,listlength){
// var pnlist = '';
// // var itemlist = $boxSel.data('itemlist');
// // itemlist.forEach(function(x){ pnlist = pnlist+'<input type=hidden name="part" value="'+x.pn+'">'});
// // console.log(pnlist);
// var formHTML = '<div style="float:right;" id="'+$boxSel.attr('id')+'-link""><div style="clear:both; margin:0px 15px 1px 0px;">'+
// '<a id="'+$boxSel.attr('id')+'-link"" href="'+viewAllLink+'" target="_blank">View All <span>'+listlength+'</span> </a>'+ '<input id="'+$boxSel.attr('id')+'-stock" type="checkbox" class="css-checkbox"><label class="css-label" for="'+$boxSel.attr('id')+'-stock">In Stock</label>'+
// '</div></div><div style="clear:both;"></div>';
// $boxSel.find('.asd-content').append(formHTML);
// $('#'+$boxSel.attr('id')+'-stock').data('allstocklink', viewAllLink)
// $('#'+$boxSel.attr('id')+'-stock').click(function(){
// if($(this).prop('checked') == true ){
// console.log('ischecked')
// $('#'+$boxSel.attr('id')+'-link a').attr('href', $(this).data('allstocklink')+'&stock=1')
// }else{
// console.log('is not checked')
// $('#'+$boxSel.attr('id')+'-link a').attr('href', $(this).data('allstocklink'))
// }
// $(this).parent().parent().find('span').load($('#'+$boxSel.attr('id')+'-link a').attr('href')+' .matching-records:first', function(){
// $(this).text($('.matching-records').text().split(':')[1])
// })
// });
// },
// addAssociatedImageHover = function(){
// _log('associatedImageHover() Start',DLOG);
// $('body').append('<img border="0/" src="" style="display: none; height:200px; width:200px; box-shadow: 0 0 10px 5px #888; position:absolute;" class="pszoomie2 psshadow" id="pszoomie2">');
// $('.asd-container').hoverIntent({
// over: function () {
// $('#pszoomie2').attr('src','');
// $('#pszoomie2')
// .attr('src', $(this).attr('src').replace('_tmb', '_sml'))
// .show('fade', 200)
// .position({
// my : 'right middle',
// at : 'left middle',
// of: $(this),
// offset : '-10 0',
// collision : 'fit fit'
// });
// },
// out: function () {
// $('.pszoomie2').fadeOut(100);
// },
// 'selector': '.col-Image img'
// }
// );
// _log('associatedImageHover() End',DLOG);
// },
// addAssociatedProductViewer = function (){
// var boxDataArray = [];
// boxDataArray = getAllAssociations();
// for (var i=0; i<boxDataArray.length; i++){
// buildProductViewerBox(boxDataArray[i]);
// console.log('**********************************', boxDataArray[i])
// }
// addAssociatedImageHover();
// $('.additional-interested').insertAfter('#bottomhalf');
// // handleExpanderDiv5();
// };
// return {'addAssociatedProductViewer': addAssociatedProductViewer};
// })();
// function getAssociationNames(){
// var names = [];
// $('.expander-div-5').each(function(){
// if($(this).find('.product-details-suggested-subs').length == 1){
// names.push('Direct Subs')
// $(this).parent('.bota').detach();
// }else if ($(this).find('.product-details-alternate-packaging').length ==1){
// names.push('AlternatePackaging');
// $(this).parent('.bota').detach();
// }
// })
// $('.expander-div-10').each(function(){
// names.push($(this).closest('tr').find('th').text());
// $(this).closest('tr').hide();
// });
// return names;
// }
// function getAssociationDataFromPageByType(assType){
// var escaped = selectorEscape(assType);
// return (window.eval(escaped));
// }
// function getAllAssociations(){
// var assocationData = [];
// var names = getAssociationNames();
// names.forEach(function(el,idx,arr){
// var escaped = selectorEscape(el);
// var alldata = window.eval(escaped);
// console.log(escaped, 'escaped eval', alldata[0]);
// assocationData.push({
// 'title': el,
// 'list': (alldata[0].showAllLink != undefined) ? alldata.slice(1) : alldata.slice(0),
// 'viewAllLink': (alldata[0].showAllLink != undefined) ? alldata[0].showAllLink : 'none'
// }) ;
// });
// console.log('associatione data', assocationData);
// return assocationData;
// }