(function() { "use strict"; // data for global market share var int_share_keys = { 'us': 0.2270987442, 'zh': 0.1241140727, 'ja': 0.0662590262, 'de': 0.0491509802, 'fr': 0.0370037111, 'uk': 0.0342784775, 'br': 0.0303189537, 'ru': 0.0286312555, 'it': 0.0280087370, 'in': 0.0252875047, 'ca': 0.0246716911, 'au': 0.0203483703, 'es': 0.0183667632, 'mx': 0.0170130277, 'kr': 0.0165163350, 'id': 0.0117643981, 'tr': 0.0111822309, 'nl': 0.0108145137, 'sa': 0.0100746181, 'ch': 0.0087977191, 'se': 0.0075422192, 'pl': 0.0069770306, 'no': 0.0069111167, 'be': 0.0068476901, 'tw': 0.0066131930, 'ar': 0.0065996749, 'at': 0.0056149275, 'ae': 0.0053563142, 'th': 0.0052335840, 'co': 0.0051614789, 've': 0.0050554435, 'ir': 0.0049510979, 'za': 0.0047418389, 'dk': 0.0044738981, 'my': 0.0042234767, 'sg': 0.0039978744, 'il': 0.0039405039, 'ng': 0.0038725083, 'cl': 0.0037441546, 'hk': 0.0036993154, 'ph': 0.0036771458, 'eg': 0.0036691566, 'fi': 0.0034730777, 'gr': 0.0032686041, 'pk': 0.0032272524, 'iq': 0.0031000478, 'kz': 0.0029786560, 'pt': 0.0029735867, 'ie': 0.0029453611, 'pe': 0.0027920397, 'dz': 0.0027859971, 'qa': 0.0027382244, 'cz': 0.0026807863, 'ro': 0.0025638149, 'kw': 0.0025051466, 'nz': 0.0024512233, 'ua': 0.0024039642, 'vn': 0.0023057017, 'bd': 0.0019097588, 'hu': 0.0017901378, 'ao': 0.0016451976, 'ma': 0.0014207578, 'sk': 0.0012950943, 'ec': 0.0012726408, 'om': 0.0010891607, 'az': 0.0009940749, 'by': 0.0009693775, 'sd': 0.0009479785, 'ly': 0.0009141158, 'lk': 0.0008899321, 'do': 0.0008214227, 'lu': 0.0008088915, 'hr': 0.0007848294, 'zu': 0.0007634439, 'mm': 0.0007625247, 'uy': 0.0007616731, 'gt': 0.0007351507, 'bg': 0.0007170771, 'cr': 0.0006707779, 'et': 0.0006508253, 'lt': 0.0006429172, 'tn': 0.0006412815, 'si': 0.0006333329, 'ke': 0.0006094195, 'lb': 0.0005990918, 'gh': 0.0005978076, 'rs': 0.0005748540, 'tm': 0.0005484127, 'pa': 0.0005451684, 'ye': 0.0005292577, 'jo': 0.0004577203, 'tz': 0.0004398224, 'bh': 0.0004354831, 'lv': 0.0004184234, 'cd': 0.0004141787, 'bo': 0.0004028641, 'py': 0.0003830062, 'ci': 0.0003823979, 'cm': 0.0003779234, 'tt': 0.0003744898, 'sv': 0.0003313538, 'ee': 0.0003309753, 'ug': 0.0003116310, 'zm': 0.0003030200, 'cy': 0.0002950579, 'af': 0.0002802962, 'np': 0.0002614521, 'ga': 0.0002599246, 'hn': 0.0002543146, 'ba': 0.0002409993, 'bn': 0.0002191812, 'ge': 0.0002184783, 'pg': 0.0002159234, 'kh': 0.0002116787, 'gq': 0.0002105297, 'mz': 0.0002072178, 'sn': 0.0002048521, 'bw': 0.0002005669, 'is': 0.0001981202, 'jm': 0.0001931455, 'cg': 0.0001862919, 'ss': 0.0001856565, 'td': 0.0001812902, 'zw': 0.0001750719, 'al': 0.0001737066, 'na': 0.0001665150, 'bf': 0.0001655552, 'mu': 0.0001612700, 'mn': 0.0001556736, 'ni': 0.0001523752, 'mg': 0.0001515370, 'ml': 0.0001496445, 'am': 0.0001425746, 'mk': 0.0001383975, 'la': 0.0001352073, 'mt': 0.0001290295, 'tj': 0.0001148626, 'ht': 0.0001143354, 'bs': 0.0001131053, 'bj': 0.0001123348, 'md': 0.0001072655, 'rw': 0.0001004524, 'ne': 0.0000994791, 'kg': 0.0000976677, 'gn': 0.0000849202, 'tl': 0.0000830953, 'sr': 0.0000683606, 'sl': 0.0000647243, 'me': 0.0000591684, 'tg': 0.0000589386, 'bb': 0.0000579112, 'mr': 0.0000566000, 'fj': 0.0000545723, 'mw': 0.0000515577, 'sz': 0.0000489352, 'er': 0.0000465561, 'gy': 0.0000401485, 'bi': 0.0000368096, 'ls': 0.0000307670, 'mv': 0.0000307670, 'bt': 0.0000268333, 'lr': 0.0000261303, 'cv': 0.0000259546, 'sm': 0.0000243595, 'bz': 0.0000216829, 'cf': 0.0000207907, 'dj': 0.0000196958, 'sc': 0.0000188982, 'lc': 0.0000178032, 'ag': 0.0000163838, 'sb': 0.0000148293, 'gm': 0.0000114903, 'gw': 0.0000114227, 'vu': 0.0000110983, 'gd': 0.0000110037, 'kn': 0.0000103683, 'vc': 0.0000097330, 'ws': 0.0000095302, 'km': 0.0000088138, 'dm': 0.0000067320, 'to': 0.0000064481, 'fm': 0.0000045015, 'st': 0.0000041636, 'pw': 0.0000033254, 'mh': 0.0000023657, 'ki': 0.0000023251, 'tv': 0.0000005137 }; function displayNumber(num, lang) { var result = Math.floor(num); var separator = " "; if (lang === 'en') { separator = ","; } var res_str = result.toString(); if (res_str.length > 3) { return displayNumber(res_str.substring(0,res_str.length-3), lang) + separator + res_str.substring(res_str.length-3); } else { return result; } } $.fn.pcomCalculator = function(data, options){ var default_options = { container: this, language: 'zh?pk_campaign=welcomepage_slider' }; // default plugin settings var settings = $.extend({ }, default_options, options); $("").appendTo('head'); var $wrapper = settings.container; $(function() { $wrapper.append("
"); var $wrapperForm = $wrapper.find('#mp-filter'); /** SELECTION FORM **/ var checkedCategoriesArray = []; var checkedCountriesArray = []; /* render categorie selection list possible categories: ship-building, electronics, plant-design, manufacturing, machine-design, architecture */ var category_select = "
"; $.each( data.categories, function(key,item) { category_select += "
"; if (checkedCategoriesArray.indexOf(item.id) >= 0) { category_select += ""; } else { category_select += ""; } category_select += "
"; category_select += "
"; category_select += ""; category_select += "
"; }); category_select += "
"; $wrapperForm.append(category_select); //render country selection list var country_select = "
"; $.each( data.countries, function(key,item) { if (item.id !== 'all') { country_select += "
"; if (checkedCountriesArray.indexOf(item.id) >= 0) { country_select += ""; } else { country_select += ""; } country_select += "
"; country_select += "
"; country_select += ""; country_select += "
"; } }); country_select += "
"; $wrapperForm.append(country_select); var show_all = "Show all"; $wrapperForm.append("
" + show_all + "
"); /** /SELECTION FORM **/ var share_links = "
"; var share_url = "https://www.cadenas.de/microsites/calculator/index.php?lang=zh?pk_campaign=welcomepage_slider"; share_links += ""; share_links += "
"; share_links += ""; share_links += ""; share_links += ""; share_links += ""; share_links += ""; share_links += ""; share_links += "
"; $wrapperForm.append(share_links); $wrapper.append("
"); /** ITEM LIST **/ var portal_list = "
"; $.each( data.items, function(key,item) { /* DATA: item.categories item.countries item.id item.nocalc item.name item.portal_preview item.portal_url item.preview item.usercount */ portal_list += "
"; var name= item.name.replace("\n", "
"); portal_list += "
"; portal_list += "" + name + ""; if (item.portal_preview !== "") { portal_list += ""; } portal_list += "
"; portal_list += "
"; portal_list += ""; portal_list += "
"; var categories = item.categories.split(" "); for(var i=0; i < categories.length; i++) { portal_list += ""; } portal_list += "
"; portal_list += "
"; var countries = item.countries.split(" "); for(var j=0; j < countries.length; j++) { portal_list += ""; } portal_list += "
"; portal_list += "
"; portal_list += ""; portal_list += "
"; }); portal_list += "
"; $wrapper.append(portal_list); $wrapper.find('a.portal-preview').lightcase( { width: 'auto', height: 'auto', maxWidth: 960, maxHeight: 720, showCaption: false, video: { width: 960, height: 540 }, iframe: { width: 960, height: 600 } }); /** /ITEM LIST **/ //add filter functions $("#mp-filter").find("input[name='category-selector'], input[name='country-selector']").change(update); $('#show-all').click(function(e) { e.preventDefault(); $("#mp-filter").find("input[name='category-selector'], input[name='country-selector']").prop('checked',false); update(); }); //initiate update(); }); // Show portals corresponding to selection function update() { $(".portal-list-item").addClass('not-visible'); var categorie_values = []; $("input[name='category-selector']:checked").each(function(i){ categorie_values[i] = $(this).val(); }); var country_values = ['all']; //add international/global portals by default $("input[name='country-selector']:checked").each(function(j){ country_values[j+1] = $(this).val(); }); //update share button var domainName = "https://www.cadenas.de"; var baseHref = '/microsites/calculator/index.php'; var query = { 'categories' : '', 'countries' : '' }; if ( $("input[name='category-selector']:checked").length > 0 ) { query['categories'] = ''; $("input[name='category-selector']:checked").each(function() { query['categories'] += $(this).val() + ','; }); } if ( $("input[name='country-selector']:checked").length > 0 ) { query['countries'] = ''; $("input[name='country-selector']:checked").each(function() { query['countries'] += $(this).val() + ','; }); } var queryString = '?lang=' + settings.language; var n=0; for( var key in query ) { query[key] = query[key].slice(0,-1); if ( query[key] != '' ) { queryString += '&' + key + '=' + query[key]; } } $('.portal-list-item').each(function() { var categorie_match = false; var country_match = false; //check countries var item_country_values = $(this).data('countries').split(" "); for(var i=0; i 0) { if (country_values.length > 1) { //filter by categorie & country selection if (country_match && categorie_match) { $(this).removeClass('not-visible'); } } else { //filter by categorie-selection only if (categorie_match) { $(this).removeClass('not-visible'); } } } else { if (country_values.length > 1) { //filter by country-selection only if (country_match) { $(this).removeClass('not-visible'); } } else { //no filter; show-all $(this).removeClass('not-visible'); } } }); var potential_data = calculateUsers(categorie_values, country_values); //update counter //lang: DE if (settings.language == 'de') { var categorie_fillin = ''; if (categorie_values.length >= 1) { categorie_fillin = 'aus dem Bereich '; categorie_values.forEach(function(e) { $.each(data.categories, function(key, item) { console.log(item.id); if (e.indexOf(item.id) >= 0) { categorie_fillin += item.name[settings.language] + ', '; } }); }); categorie_fillin = categorie_fillin.replace(/, $/, ""); } var country_fillin = ''; if (country_values.length >= 1) { country_fillin = 'In '; country_values.forEach(function(e) { $.each(data.countries, function(key, item) { console.log(item.id); if (e.indexOf(item.id) >= 0) { country_fillin += item.name[settings.language] + ', '; } }); }); country_fillin = country_fillin.replace(/, $/, ""); } if (categorie_values.length > 0 && country_values.length > 0) { $('.selection-counter').html(country_fillin + ' warten ' + displayNumber(potential_data[0], settings.language) + ' Ingenieure, Einkäufer, Planer und Architekten ' + categorie_fillin + ' in ' + potential_data[1] + ' Portalen und Marktplätzen auf Sie!'); } else if (categorie_values.length > 0) { $('.selection-counter').html('Es warten ' + displayNumber(potential_data[0], settings.language) + ' Ingenieure, Einkäufer, Planer und Architekten ' + categorie_fillin + ' in ' + potential_data[1] + ' Portalen und Marktplätzen auf Sie!'); } else if (country_values.length > 0) { $('.selection-counter').html(country_fillin + ' warten ' + displayNumber(potential_data[0], settings.language) + ' Ingenieure, Einkäufer, Planer und Architekten ' + categorie_fillin + ' in ' + potential_data[1] + ' Portalen und Marktplätzen auf Sie!'); } else { $('.selection-counter').html('There are '+ displayNumber(potential_data[0], settings.language) +' engineers, purchasers, planners and architects on '+ potential_data[1] + ' portals and market places waiting for you!'); } } //lang: EN else if (settings.language == 'en') { var categorie_fillin = ''; if (categorie_values.length >= 1) { categorie_fillin += 'from the area of '; categorie_values.forEach(function(e) { $.each(data.categories, function(key, item) { console.log(item.id); if (e.indexOf(item.id) >= 0) { categorie_fillin += item.name[settings.language] + ', '; } }); }); categorie_fillin = categorie_fillin.replace(/, $/, ""); } var country_fillin = ''; if (country_values.length >= 1) { country_fillin += 'From '; country_values.forEach(function(e) { $.each(data.countries, function(key, item) { console.log(item.id); if (e.indexOf(item.id) >= 0) { country_fillin += item.name[settings.language] + ', '; } }); }); country_fillin = country_fillin.replace(/, $/, ""); } // There are 16,088,700 engineers, purchasers, planners and architects on 87 portals and market places waiting for you! if (categorie_values.length > 0 && country_values.length > 0) { $('.selection-counter').html(country_fillin + ' there are ' + displayNumber(potential_data[0], settings.language) + ' engineers, purchasers, planners and architects ' + categorie_fillin + ' on ' + potential_data[1] + ' portals and market places waiting for you!!'); } else if (categorie_values.length > 0) { $('.selection-counter').html('There are ' + displayNumber(potential_data[0], settings.language) + ' engineers, purchasers, planners and architects ' + categorie_fillin + ' on ' + potential_data[1] + ' portals and market places waiting for you!'); } else if (country_values.length > 0) { $('.selection-counter').html(country_fillin + ' there are ' + displayNumber(potential_data[0], settings.language) + ' engineers, purchasers, planners and architects ' + categorie_fillin + ' on ' + potential_data[1] + ' portals and market places waiting for you!'); } else { $('.selection-counter').html('There are '+ displayNumber(potential_data[0], settings.language) +' engineers, purchasers, planners and architects on '+ potential_data[1] + ' portals and market places waiting for you!'); } } //fallback (no mentioning of selection) else { $('.selection-counter').html('There are '+ displayNumber(potential_data[0], settings.language) +' engineers, purchasers, planners and architects on '+ potential_data[1] + ' portals and market places waiting for you!'); } queryString += '&n=' + potential_data.join('|'); //update share url $('#share-selection').attr('href', baseHref + queryString); $('.share-link.facebook').attr('href', 'https://www.facebook.com/sharer/sharer.php?u=' + encodeURI(domainName + baseHref + queryString)); $('.share-link.linkedin').attr('href', 'https://www.linkedin.com/shareArticle?mini=true&url=' + encodeURI(domainName + baseHref + queryString) + '&source=CADENAS'); $('.share-link.xing').attr('href', 'https://www.xing.com/spi/shares/new?' + encodeURI(domainName + baseHref + queryString)); $('.share-link.twitter').attr('href', 'https://twitter.com/intent/tweet?url=' + encodeURI(domainName + baseHref + queryString)); $('.share-link.google-plus').attr('href', 'https://plus.google.com/share?url=' + encodeURI(domainName + baseHref + queryString)); $('.share-link.clipboard').attr({ 'href' : domainName + baseHref + queryString, 'data-clipboard-text' : domainName + baseHref + queryString }); new Clipboard('.share-link.clipboard'); } //Calculate users corresponding to global market share & portals and fill data into counter element function calculateUsers(categories, countries) { var portalcount = 0; var users = 0; countries.splice(0,1); //remove global items from selection $('.portal-list-item:visible').each(function() { var obj = $(this); if (!obj.hasClass('nocalc')) { if (countries.length > 0) { if(obj.data('countries') === 'all') { // count global share $.each(countries, function(key) { users += obj.data('users') * int_share_keys[countries[key]]; }); } else { // count full var item_countries = obj.data('countries').split(" "); var count_users = false; $.each(countries, function(key) { if ($.inArray(countries[key], item_countries ) !== -1) { count_users = true; } }); if (count_users) { users += obj.data('users'); } } } else { users += obj.data('users'); } } portalcount += 1; }); return new Array(users, portalcount); } }; // get total portal count $.fn.pcomCalculator.countPortals = function(data) { return data.items.length; }; // get total user count $.fn.pcomCalculator.countUsers = function(data, lang) { var users = 0; $.each( data.items, function(key, item) { if (item.nocalc !== "nocalc") { users += item.usercount; } }); return displayNumber(users, lang); }; }());