Return folders + files using Javascript - javascript
I'm trying to make this javascript code (made by Esailija) to write folders as well
http://jsfiddle.net/JwgqC/
Currently it only shows files, not folders.. Folders appear as dots..
Here's my mod
http://jsfiddle.net/JwgqC/46/
function selectFolder(e) {
var theFiles = e.target.files;
for (var i=0, file; file=theFiles[i]; i++) {
document.body.innerHTML+="<li>" + file.webkitRelativePath;
}
}
document.querySelector("input").onchange = function() {
[].slice.call( this.files ).forEach( function(selectFolder) {
$("body").append("<div>"+v.name+"</div>" );
});
};
But i can't get the folders to show up..
Mind pointing me which part is incorrect?
My background isn't exactly programing so it's kinda difficult for me
Thanks
If you would like to display the folders only:
http://jsfiddle.net/F6yEW/
function isFolder(x) {
if (x.name == "." && x.type == "") {
return true;
} else {
return false;
}
}
document.querySelector("input").onchange = function () {
[].slice.call(this.files).forEach(function (v) {
var folderName = "";
var path = v.webkitRelativePath.replace("/.", "");
if (isFolder(v)) {
folderName = path.match(/([^\/]*)\/*$/)[1];
$("body").append("<div>" + folderName + "</div>");
}
});
};
If you would like to display folders + files: http://jsfiddle.net/K22RT/
function isFolder(x) {
if (x.name == "." && x.type == "") {
return true;
} else {
return false;
}
}
document.querySelector("input").onchange = function () {
[].slice.call(this.files).forEach(function (v) {
var displayName = v.name;
var path = v.webkitRelativePath.replace("/.", "");
if (isFolder(v)) {
displayName = path.match(/([^\/]*)\/*$/)[1];
$("body").append("<div>folder: " + displayName + "</div>");
} else {
$("body").append("<div>file: " + displayName + "</div>");
}
});
};
I hope this solution can help you out :)
Related
want to display duplicate ranks selected along with exactly which ranks are duplicated using javascript/ jquery
Here we added the logic to display which ranks are duplicated but I also want to display exactly which rank is duplicated. Ranks are from 0 to 18. function validate(sdd_ejrp_form) { var duplicateRanksDetected = false; var validate_rank_str = ","; jq("\[data-dom-id=gsc-containers\]").find("\[data-dom-id=gsc-container\]").each(function (index) { var jqThis = jq(this); var gsc_uri = jqThis.attr("data-gsc-data-gsc-uri"); var prof_lvl_rank = jqThis.find("select\[name='prof-lvl-rank'\]").val(); jqThis.find("\[data-dom-id=proficiency-level\]").each(function (index2) { var btn = jq(this); if (btn.hasClass("active")) { if (validate_rank_str.indexOf("," + prof_lvl_rank + ",") != -1) { duplicateRanksDetected = true; return false; } else { validate_rank_str += prof_lvl_rank + ","; } } }); }); if (duplicateRanksDetected == true) { // here I want to display exactly which rank is duplicated alert("Duplicate ranks detected!"); return false; } } }
It's easy as 3 modifications: function validate(sdd_ejrp_form) { var duplicateRanksDetected = []; //create an array here var validate_rank_str = ","; jq("\[data-dom-id=gsc-containers\]").find("\[data-dom-id=gsc-container\]").each(function(index) { var jqThis = jq(this); var gsc_uri = jqThis.attr("data-gsc-data-gsc-uri"); var prof_lvl_rank = jqThis.find("select\[name='prof-lvl-rank'\]").val(); jqThis.find("\[data-dom-id=proficiency-level\]").each(function(index2) { var btn = jq(this); if (btn.hasClass("active")) { if (validate_rank_str.indexOf("," + prof_lvl_rank + ",") != -1) { duplicateRanksDetected.push(prof_lvl_rank); // fill the array here return false; } else { validate_rank_str += prof_lvl_rank + ","; } } }); }); if (duplicateRanksDetected.length > 0) { // here I want to display exactly which rank is duplicated alert( "Duplicate ranks detected: " + duplicateRanksDetected.join(', ') // display the result here ); return false; } }
How can I delete Items from json string without using $.grep
I have a cart variable and I am storing the cart inside it like this. [{"course_id":"24","doc_id":"211","doc_title":"PDF Notes","doc_price":"500"},{"course_id":"25","doc_id":"217","doc_title":"PDF Notes","doc_price":"500"},{"course_id":"25","doc_id":"218","doc_title":"PDF Solved Past Papers","doc_price":"500"},{"course_id":"26","doc_id":"224","doc_title":"PDF Solved Past Papers","doc_price":"595"}] I created a RemoveFromCart function. It works in simple JQUERY But it is not working in Framework 7 because of $.grep. Is there any other way I can do it without using $.grep? This is my Function function removeFromCart(course_id, doc_id) { var x = confirm("Are you sure you want to remove this item from your cart?"); if (x) { $$('#cart_body').html(''); existing_cart = localStorage.getItem("cart"); if (existing_cart == '') { existing_cart = []; } else { existing_cart = JSON.parse(existing_cart); } existing_cart = $.grep(existing_cart, function (data, index) { return data.doc_id != doc_id }); ex_cart = JSON.stringify(existing_cart); localStorage.setItem('cart', ex_cart); existing_cart = localStorage.getItem("cart"); if (existing_cart == '') { existing_cart = []; } else { existing_cart = JSON.parse(existing_cart); } if (existing_cart !== null && existing_cart.length > 0) { var total = ''; $$('#cart_div').show(); existing_cart.forEach(function (arrayItem) { var text = ''; text = '<li class="item-content"><div class="item-inner"><div class="item-title">' + arrayItem.doc_title + '</div><div class="item-after">' + arrayItem.course_id + '</div><div class="item-after">' + arrayItem.doc_price + '</div><div class="item-after"><i class="icon icon-cross" onclick="removeFromCart(' + arrayItem.course_id + ',' + arrayItem.doc_id + ')"></i></div></div></li>'; total = Number(total) + Number(arrayItem.doc_price); $$('#cart_body').append(text); }); text = '<tr><td></td><td class="text-center"><b>Total: </b></td><td class="text-center">' + total + '</td><td></td></tr>'; $$('#cart_body').append(text); } else { $$('#cart_div').hide(); text = '<p>Your cart is empty.</p>'; $$('#cart_body').append(text); } } else { return false; } }
Instead of: $.grep(existing_cart, function ... You can use: existing_cart.filter(function ...
var new_courses = existing_cart.map( v=> { if(v.doc_id != doc_id) return v }).filter( v=> {return v}) // new_courses does not contain the course with doc_id map loops through each member of an array. filter removes members not returned in map.
element null in Magento
I upgrade magento from 1.8.1 to 1.9.0, and I have a problem with one js file: TypeError: $(...) is null $('product_addtocart_form').getElements().each(function(el) { simple_product_pricing.js (line 1131, col 5) I think this file is related to the Ayasoftware_SimpleProductPricing, maybe someone can help me to solve this. Before upgrade in 1.8.1 version everything was fine, in 1.9.0 version I have this error. I will add here the entire js: /* Some of these override earlier varien/product.js methods, therefore varien/product.js must have been included prior to this file. some of these functions were initially written by Matt Dean ( http://organicinternet.co.uk/ ) */ Product.Config.prototype.getMatchingSimpleProduct = function(){ var inScopeProductIds = this.getInScopeProductIds(); if ((typeof inScopeProductIds != 'undefined') && (inScopeProductIds.length == 1)) { return inScopeProductIds[0]; } return false; }; /* Find products which are within consideration based on user's selection of config options so far Returns a normal array containing product ids allowedProducts is a normal numeric array containing product ids. childProducts is a hash keyed on product id optionalAllowedProducts lets you pass a set of products to restrict by, in addition to just using the ones already selected by the user */ Product.Config.prototype.getInScopeProductIds = function(optionalAllowedProducts) { var childProducts = this.config.childProducts; var allowedProducts = []; if ((typeof optionalAllowedProducts != 'undefined') && (optionalAllowedProducts.length > 0)) { allowedProducts = optionalAllowedProducts; } for(var s=0, len=this.settings.length-1; s<=len; s++) { if (this.settings[s].selectedIndex <= 0){ break; } var selected = this.settings[s].options[this.settings[s].selectedIndex]; if (s==0 && allowedProducts.length == 0){ allowedProducts = selected.config.allowedProducts; } else { allowedProducts = allowedProducts.intersect(selected.config.allowedProducts).uniq(); } } //If we can't find any products (because nothing's been selected most likely) //then just use all product ids. if ((typeof allowedProducts == 'undefined') || (allowedProducts.length == 0)) { productIds = Object.keys(childProducts); } else { productIds = allowedProducts; } return productIds; }; Product.Config.prototype.getProductIdOfCheapestProductInScope = function(priceType, optionalAllowedProducts) { var childProducts = this.config.childProducts; var productIds = this.getInScopeProductIds(optionalAllowedProducts); var minPrice = Infinity; var lowestPricedProdId = false; //Get lowest price from product ids. for (var x=0, len=productIds.length; x<len; ++x) { var thisPrice = Number(childProducts[productIds[x]][priceType]); if (thisPrice < minPrice) { minPrice = thisPrice; lowestPricedProdId = productIds[x]; } } return lowestPricedProdId; }; Product.Config.prototype.getProductIdOfMostExpensiveProductInScope = function(priceType, optionalAllowedProducts) { var childProducts = this.config.childProducts; var productIds = this.getInScopeProductIds(optionalAllowedProducts); var maxPrice = 0; var highestPricedProdId = false; //Get highest price from product ids. for (var x=0, len=productIds.length; x<len; ++x) { var thisPrice = Number(childProducts[productIds[x]][priceType]); if (thisPrice >= maxPrice) { maxPrice = thisPrice; highestPricedProdId = productIds[x]; } } return highestPricedProdId; }; Product.OptionsPrice.prototype.updateSpecialPriceDisplay = function(price, finalPrice) { var prodForm = $('product_addtocart_form'); jQuery('p.msg').hide(); jQuery('div.price-box').show(); var specialPriceBox = prodForm.select('p.special-price'); var oldPricePriceBox = prodForm.select('p.old-price, p.was-old-price'); var magentopriceLabel = prodForm.select('span.price-label'); if (price == finalPrice) { //specialPriceBox.each(function(x) {x.hide();}); magentopriceLabel.each(function(x) {x.hide();}); oldPricePriceBox.each(function(x) { x.hide(); // x.removeClassName('old-price'); // x.addClassName('was-old-price'); }); jQuery('.product-shop').removeClass('sale-product') ; }else{ specialPriceBox.each(function(x) {x.show();}); magentopriceLabel.each(function(x) {x.show();}); oldPricePriceBox.each(function(x) { x.show(); x.removeClassName('was-old-price'); x.addClassName('old-price'); }); jQuery('.product-shop').addClass('sale-product') ; } }; //This triggers reload of price and other elements that can change //once all options are selected Product.Config.prototype.reloadPrice = function() { var childProductId = this.getMatchingSimpleProduct(); var childProducts = this.config.childProducts; var usingZoomer = false; if(this.config.imageZoomer){ usingZoomer = true; } if(childProductId){ var price = childProducts[childProductId]["price"]; var finalPrice = childProducts[childProductId]["finalPrice"]; optionsPrice.productPrice = finalPrice; optionsPrice.productOldPrice = price; optionsPrice.reload(); optionsPrice.reloadPriceLabels(true); optionsPrice.updateSpecialPriceDisplay(price, finalPrice); if(this.config.updateShortDescription) { this.updateProductShortDescription(childProductId); } if(this.config.updateDescription) { this.updateProductDescription(childProductId); } if(this.config.updateProductName) { this.updateProductName(childProductId); } if(this.config.customStockDisplay) { this.updateProductAvailability(childProductId); } this.showTierPricingBlock(childProductId, this.config.productId); if (usingZoomer) { this.showFullImageDiv(childProductId, this.config.productId); } else { if(this.config.updateproductimage) { this.updateProductImage(childProductId); } } } else { var cheapestPid = this.getProductIdOfCheapestProductInScope("finalPrice"); var price = childProducts[cheapestPid]["price"]; var finalPrice = childProducts[cheapestPid]["finalPrice"]; optionsPrice.productPrice = finalPrice; optionsPrice.productOldPrice = price; optionsPrice.reload(); optionsPrice.reloadPriceLabels(false); if(this.config.updateProductName) { this.updateProductName(false); } if(this.config.updateShortDescription) { this.updateProductShortDescription(false); } if(this.config.updateDescription) { this.updateProductDescription(false); } if(this.config.customStockDisplay) { this.updateProductAvailability(false); } optionsPrice.updateSpecialPriceDisplay(price, finalPrice); this.showTierPricingBlock(false); this.showCustomOptionsBlock(false, false); if (usingZoomer) { this.showFullImageDiv(false, false); } else { if(this.config.updateproductimage) { this.updateProductImage(false); } } } }; Product.Config.prototype.updateProductImage = function(productId) { var imageUrl = this.config.imageUrl; if(productId && this.config.childProducts[productId].imageUrl) { imageUrl = this.config.childProducts[productId].imageUrl; } if (!imageUrl) { return; } if($('image')) { $('image').src = imageUrl; } else { $$('#product_addtocart_form p.product-image img').each(function(el) { var dims = el.getDimensions(); el.src = imageUrl; el.width = dims.width; el.height = dims.height; }); } }; Product.Config.prototype.updateProductName = function(productId) { var productName = this.config.productName; if (productId && this.config.ProductNames[productId].ProductName) { productName = this.config.ProductNames[productId].ProductName; } $$('#product_addtocart_form div.product-name h1').each(function(el) { el.innerHTML = productName; }); var productSku = this.config.sku ; if (productId && this.config.childProducts[productId].sku) { productSku = this.config.childProducts[productId].sku ; } jQuery('.sku span').text(productSku) ; var productDelivery = this.config.delivery; if (productId && this.config.childProducts[productId].delivery) { productDelivery = this.config.childProducts[productId].delivery ; } jQuery('.delivery-info').html(productDelivery) ; var productReturns = this.config.returns; if (productId && this.config.childProducts[productId].returns) { productReturns = this.config.childProducts[productId].returns ; } jQuery('.returns-info').html(productReturns) ; var productDownloads = this.config.downloads; if (productId && this.config.childProducts[productId].downloads) { productDownloads = this.config.childProducts[productId].downloads; } if (productDownloads) jQuery('.downloads-info').html(productDownloads) ; else jQuery('.downloads-info').html('There are no downloads for this product') ; var productAttribs = this.config.attributesTable; if (productId && this.config.childProducts[productId].attributesTable) { productAttribs = this.config.childProducts[productId].attributesTable ; } jQuery('.attribs-info').html(productAttribs) ; decorateTable('product-attribute-specs-table') ; if (productId && this.config.childProducts[productId].isNew) { jQuery('.product-image .new-label').show() ; } else { jQuery('.product-image .new-label').hide() ; } if (productId && this.config.childProducts[productId].isOnSale) { jQuery('.product-image .sale-label').show() ; } else { jQuery('.product-image .sale-label').hide() ; } if (productId) jQuery('input[name="pid"]').val(productId) ; }; Product.Config.prototype.updateProductAvailability = function(productId) { var stockInfo = this.config.stockInfo; var is_in_stock = false; var stockLabel = ''; if (productId && stockInfo[productId]["stockLabel"]) { stockLabel = stockInfo[productId]["stockLabel"]; stockQty = stockInfo[productId]["stockQty"]; is_in_stock = stockInfo[productId]["is_in_stock"]; } $$('#product_addtocart_form p.availability span').each(function(el) { if(is_in_stock) { $$('#product_addtocart_form p.availability').each(function(es) { es.removeClassName('availability out-of-stock'); es.addClassName('availability in-stock'); }); el.innerHTML = /*stockQty + ' ' + */stockLabel; } else { $$('#product_addtocart_form p.availability').each(function(ef) { ef.removeClassName('availability in-stock'); ef.addClassName('availability out-of-stock'); }); el.innerHTML = stockLabel; } }); }; Product.Config.prototype.updateProductShortDescription = function(productId) { var shortDescription = this.config.shortDescription; if (productId && this.config.shortDescriptions[productId].shortDescription) { shortDescription = this.config.shortDescriptions[productId].shortDescription; } $$('#product_addtocart_form div.short-description div.std').each(function(el) { el.innerHTML = shortDescription; }); }; Product.Config.prototype.updateProductDescription = function(productId) { var description = this.config.description; if (productId && this.config.Descriptions[productId].Description) { description = this.config.Descriptions[productId].Description; } $$('#product_tabs_description_tabbed_contents div.std').each(function(el) { el.innerHTML = description; }); }; Product.Config.prototype.updateProductAttributes = function(productId) { var productAttributes = this.config.productAttributes; if (productId && this.config.childProducts[productId].productAttributes) { productAttributes = this.config.childProducts[productId].productAttributes; } //If config product doesn't already have an additional information section, //it won't be shown for associated product either. It's too hard to work out //where to place it given that different themes use very different html here console.log(productAttributes) ; $$('div.product-collateral div.attribs-info').each(function(el) { el.innerHTML = productAttributes; decorateTable('product-attribute-specs-table'); }); }; Product.Config.prototype.showCustomOptionsBlock = function(productId, parentId) { var coUrl = this.config.ajaxBaseUrl + "co/?id=" + productId + '&pid=' + parentId; var prodForm = $('product_addtocart_form'); if ($('SCPcustomOptionsDiv')==null) { return; } Effect.Fade('SCPcustomOptionsDiv', { duration: 0.5, from: 1, to: 0.5 }); if(productId) { //Uncomment the line below if you want an ajax loader to appear while any custom //options are being loaded. //$$('span.scp-please-wait').each(function(el) {el.show()}); //prodForm.getElements().each(function(el) {el.disable()}); new Ajax.Updater('SCPcustomOptionsDiv', coUrl, { method: 'get', evalScripts: true, onComplete: function() { $$('span.scp-please-wait').each(function(el) {el.hide()}); Effect.Fade('SCPcustomOptionsDiv', { duration: 0.5, from: 0.5, to: 1 }); //prodForm.getElements().each(function(el) {el.enable()}); } }); } else { $('SCPcustomOptionsDiv').innerHTML = ''; try{window.opConfig = new Product.Options([]);} catch(e){} } }; Product.OptionsPrice.prototype.reloadPriceLabels = function(productPriceIsKnown) { var priceFromLabel = ''; var prodForm = $('product_addtocart_form'); if (!productPriceIsKnown && typeof spConfig != "undefined") { priceFromLabel = spConfig.config.priceFromLabel; } var priceSpanId = 'configurable-price-from-' + this.productId; var duplicatePriceSpanId = priceSpanId + this.duplicateIdSuffix; if($(priceSpanId) && $(priceSpanId).select('span.configurable-price-from-label')) $(priceSpanId).select('span.configurable-price-from-label').each(function(label) { label.innerHTML = priceFromLabel; }); if ($(duplicatePriceSpanId) && $(duplicatePriceSpanId).select('span.configurable-price-from-label')) { $(duplicatePriceSpanId).select('span.configurable-price-from-label').each(function(label) { label.innerHTML = priceFromLabel; }); } }; //SCP: Forces the 'next' element to have it's optionLabels reloaded too Product.Config.prototype.configureElement = function(element) { this.reloadOptionLabels(element); if(element.value){ this.state[element.config.id] = element.value; if(element.nextSetting){ element.nextSetting.disabled = false; this.fillSelect(element.nextSetting); this.reloadOptionLabels(element.nextSetting); this.resetChildren(element.nextSetting); } } else { this.resetChildren(element); } this.reloadPrice(); }; //SCP: Changed logic to use absolute price ranges rather than price differentials Product.Config.prototype.reloadOptionLabels = function(element){ var selectedPrice; var childProducts = this.config.childProducts; var stockInfo = this.config.stockInfo; //Don't update elements that have a selected option if(element.options[element.selectedIndex].config){ return; } for(var i=0;i<element.options.length;i++){ if(element.options[i].config){ var cheapestPid = this.getProductIdOfCheapestProductInScope("finalPrice", element.options[i].config.allowedProducts); var mostExpensivePid = this.getProductIdOfMostExpensiveProductInScope("finalPrice", element.options[i].config.allowedProducts); var cheapestFinalPrice = childProducts[cheapestPid]["finalPrice"]; var mostExpensiveFinalPrice = childProducts[mostExpensivePid]["finalPrice"]; var stock = ''; if(cheapestPid == mostExpensivePid ){ if(stockInfo[cheapestPid]["stockLabel"] != '') { stock = '( ' +stockInfo[cheapestPid]["stockLabel"] + ' )'; } } if (this.config.showOutOfStock){ if(this.config.disable_out_of_stock_option ) { if(!stockInfo[cheapestPid]["is_in_stock"] ) { if(cheapestPid == mostExpensivePid ){ element.options[i].disabled=true; var stock = '( ' +stockInfo[cheapestPid]["stockLabel"] + ' )'; } } } } var tierpricing = childProducts[mostExpensivePid]["tierpricing"]; element.options[i].text = this.getOptionLabel(element.options[i].config, cheapestFinalPrice, mostExpensiveFinalPrice, stock , tierpricing); } } }; Product.Config.prototype.showTierPricingBlock = function(productId, parentId) { var coUrl = this.config.ajaxBaseUrl + "co/?id=" + productId + '&pid=' + parentId; var prodForm = $('product_addtocart_form'); if(productId) { new Ajax.Updater('sppTierPricingDiv', coUrl, { method: 'get', evalScripts: true, onComplete: function() { $$('span.scp-please-wait').each(function(el) {el.hide()}); } }); } else { $('sppTierPricingDiv').innerHTML = ''; } }; //SCP: Changed label formatting to show absolute price ranges rather than price differentials Product.Config.prototype.getOptionLabel = function(option, lowPrice, highPrice, stock, tierpricing){ var str = option.label; if(tierpricing > 0 && tierpricing < lowPrice) { var tierpricinglowestprice = ': As low as (' + this.formatPrice(tierpricing,false) + ')'; } else { var tierpricinglowestprice = ''; } if (!this.config.showPriceRangesInOptions) { return str; } if (!this.config.showOutOfStock){ stock = ''; } lowPrices = this.getTaxPrices(lowPrice); highPrices = this.getTaxPrices(highPrice); if (this.config.hideprices) { if (this.config.showOutOfStock){ return str + ' ' + stock + ' '; } else { return str; } } var to = ' ' + this.config.rangeToLabel + ' '; var separator = ': ( '; if(lowPrice && highPrice){ if (this.config.showfromprice) { this.config.priceFromLabel = this.config.priceFromLabel; //'From: '; } if (lowPrice != highPrice) { if (this.taxConfig.showBothPrices) { str+= separator + this.formatPrice(lowPrices[2], false) + ' (' + this.formatPrice(lowPrices[1], false) + ' ' + this.taxConfig.inclTaxTitle.replace('Tax','VAT') + ')'; str+= to + this.formatPrice(highPrices[2], false) + ' (' + this.formatPrice(highPrices[1], false) + ' ' + this.taxConfig.inclTaxTitle.replace('Tax','VAT') + ')'; str += " ) "; } else { str+= separator + this.formatPrice(lowPrices[0], false); str+= to + this.formatPrice(highPrices[0], false); str += " ) "; } } else { if (this.taxConfig.showBothPrices) { str+= separator + this.formatPrice(lowPrices[2], false) + ' (' + this.formatPrice(lowPrices[1], false) + ' ' + this.taxConfig.inclTaxTitle.replace('Tax','VAT') + ')'; str += " ) "; str += stock; str += tierpricinglowestprice; } else { if(tierpricing == 0 ) { str+= separator + this.formatPrice(lowPrices[0], false); str += " ) "; } str += tierpricinglowestprice; str += ' ' + stock; } } } return str; }; //SCP: Refactored price calculations into separate function Product.Config.prototype.getTaxPrices = function(price) { var price = parseFloat(price); if (this.taxConfig.includeTax) { var tax = price / (100 + this.taxConfig.defaultTax) * this.taxConfig.defaultTax; var excl = price - tax; var incl = excl*(1+(this.taxConfig.currentTax/100)); } else { var tax = price * (this.taxConfig.currentTax / 100); var excl = price; var incl = excl + tax; } if (this.taxConfig.showIncludeTax || this.taxConfig.showBothPrices) { price = incl; } else { price = excl; } return [price, incl, excl]; }; //SCP: Forces price labels to be updated on load //so that first select shows ranges from the start document.observe("dom:loaded", function() { //Really only needs to be the first element that has configureElement set on it, //rather than all. if (typeof opConfig != "undefined") { spConfig.reloadPrice(); } $('product_addtocart_form').getElements().each(function(el) { if(el.type == 'select-one') { if(el.options && (el.options.length > 1)) { el.options[0].selected = true; spConfig.reloadOptionLabels(el); } } }); }); Thank you
The version 1.5.11 is not compatible w/ Magento 1.9 according to the extension version on Magento connect. Please obtain the newest version of the extension and/or ask the creator to give you support. As far as I can see 1.9 support is support with 1.11.6, released 11th March 2015. The infos on their homepage and Magento connect are different - not good. On the homepage it says Works with Magento 1.9.0.X . tested 15 May 2014.
SyntaxError: let is a reserved identifier on firefox
I am using those code below 'use strict'; jQuery(document).ready(function($) { function CMB2ConditionalsInit(context) { if(typeof context === 'undefined') { context = 'body'; } $('[data-conditional-id]', context).each(function(i, e) { var $e = $(e), id = $e.data('conditional-id'), value = $e.data('conditional-value'); var $element = $('[name="' + id + '"]'), $parent = $e.parents('.cmb-row:first').hide(); $e.data('conditional-required', $e.prop('required')).prop('required', false); $element .on('change', function(evt){ let conditionValue = CMB2ConditionalsStringToUnicode(evt.currentTarget.value); if(typeof value === 'undefined') { CMB2ConditionalToggleRows('[data-conditional-id="' + id + '"]', ($element.val() ? true : false)); } else { CMB2ConditionalToggleRows('[data-conditional-id="' + id + '"]:not([data-conditional-value="' + conditionValue + '"])', false); CMB2ConditionalToggleRows('[data-conditional-id="' + id + '"][data-conditional-value="' + conditionValue + '"]', true); CMB2ConditionalToggleRows('[data-conditional-id="' + id + '"][data-conditional-value*=\'"' + conditionValue + '"\']', true); } }); if($element.length === 1) { $element.trigger('change'); } else { $element.filter(':checked').trigger('change'); } }); } function CMB2ConditionalsStringToUnicode(string){ let result = '', map = ["Á", "Ă","Ắ","Ặ","Ằ","Ẳ","Ẵ","Ǎ","Â","Ấ","Ậ","Ầ","Ẩ","Ẫ","Ä","Ǟ","Ȧ","Ǡ","Ạ","Ȁ","À","Ả","Ȃ","Ā","Ą","Å","Ǻ","Ḁ","Ⱥ","Ã","Ꜳ","Æ","Ǽ","Ǣ","Ꜵ","Ꜷ","Ꜹ","Ꜻ","Ꜽ","Ḃ","Ḅ","Ɓ","Ḇ","Ƀ","Ƃ","Ć","Č","Ç","Ḉ","Ĉ","Ċ","Ƈ","Ȼ","Ď","Ḑ","Ḓ","Ḋ","Ḍ","Ɗ","Ḏ","Dz","Dž","Đ","Ƌ","DZ","DŽ","É","Ĕ","Ě","Ȩ","Ḝ","Ê","Ế","Ệ","Ề","Ể","Ễ","Ḙ","Ë","Ė","Ẹ","Ȅ","È","Ẻ","Ȇ","Ē","Ḗ","Ḕ","Ę","Ɇ","Ẽ","Ḛ","Ꝫ","Ḟ","Ƒ","Ǵ","Ğ","Ǧ","Ģ","Ĝ","Ġ","Ɠ","Ḡ","Ǥ","Ḫ","Ȟ","Ḩ","Ĥ","Ⱨ","Ḧ","Ḣ","Ḥ","Ħ","Í","Ĭ","Ǐ","Î","Ï","Ḯ","İ","Ị","Ȉ","Ì","Ỉ","Ȋ","Ī","Į","Ɨ","Ĩ","Ḭ","Ꝺ","Ꝼ","Ᵹ","Ꞃ","Ꞅ","Ꞇ","Ꝭ","Ĵ","Ɉ","Ḱ","Ǩ","Ķ","Ⱪ","Ꝃ","Ḳ","Ƙ","Ḵ","Ꝁ","Ꝅ","Ĺ","Ƚ","Ľ","Ļ","Ḽ","Ḷ","Ḹ","Ⱡ","Ꝉ","Ḻ","Ŀ","Ɫ","Lj","Ł","LJ","Ḿ","Ṁ","Ṃ","Ɱ","Ń","Ň","Ņ","Ṋ","Ṅ","Ṇ","Ǹ","Ɲ","Ṉ","Ƞ","Nj","Ñ","NJ","Ó","Ŏ","Ǒ","Ô","Ố","Ộ","Ồ","Ổ","Ỗ","Ö","Ȫ","Ȯ","Ȱ","Ọ","Ő","Ȍ","Ò","Ỏ","Ơ","Ớ","Ợ","Ờ","Ở","Ỡ","Ȏ","Ꝋ","Ꝍ","Ō","Ṓ","Ṑ","Ɵ","Ǫ","Ǭ","Ø","Ǿ","Õ","Ṍ","Ṏ","Ȭ","Ƣ","Ꝏ","Ɛ","Ɔ","Ȣ","Ṕ","Ṗ","Ꝓ","Ƥ","Ꝕ","Ᵽ","Ꝑ","Ꝙ","Ꝗ","Ŕ","Ř","Ŗ","Ṙ","Ṛ","Ṝ","Ȑ","Ȓ","Ṟ","Ɍ","Ɽ","Ꜿ","Ǝ","Ś","Ṥ","Š","Ṧ","Ş","Ŝ","Ș","Ṡ","Ṣ","Ṩ","Ť","Ţ","Ṱ","Ț","Ⱦ","Ṫ","Ṭ","Ƭ","Ṯ","Ʈ","Ŧ","Ɐ","Ꞁ","Ɯ","Ʌ","Ꜩ","Ú","Ŭ","Ǔ","Û","Ṷ","Ü","Ǘ","Ǚ","Ǜ","Ǖ","Ṳ","Ụ","Ű","Ȕ","Ù","Ủ","Ư","Ứ","Ự","Ừ","Ử","Ữ","Ȗ","Ū","Ṻ","Ų","Ů","Ũ","Ṹ","Ṵ","Ꝟ","Ṿ","Ʋ","Ṽ","Ꝡ","Ẃ","Ŵ","Ẅ","Ẇ","Ẉ","Ẁ","Ⱳ","Ẍ","Ẋ","Ý","Ŷ","Ÿ","Ẏ","Ỵ","Ỳ","Ƴ","Ỷ","Ỿ","Ȳ","Ɏ","Ỹ","Ź","Ž","Ẑ","Ⱬ","Ż","Ẓ","Ȥ","Ẕ","Ƶ","IJ","Œ","ᴀ","ᴁ","ʙ","ᴃ","ᴄ","ᴅ","ᴇ","ꜰ","ɢ","ʛ","ʜ","ɪ","ʁ","ᴊ","ᴋ","ʟ","ᴌ","ᴍ","ɴ","ᴏ","ɶ","ᴐ","ᴕ","ᴘ","ʀ","ᴎ","ᴙ","ꜱ","ᴛ","ⱻ","ᴚ","ᴜ","ᴠ","ᴡ","ʏ","ᴢ","á","ă","ắ","ặ","ằ","ẳ","ẵ","ǎ","â","ấ","ậ","ầ","ẩ","ẫ","ä","ǟ","ȧ","ǡ","ạ","ȁ","à","ả","ȃ","ā","ą","ᶏ","ẚ","å","ǻ","ḁ","ⱥ","ã","ꜳ","æ","ǽ","ǣ","ꜵ","ꜷ","ꜹ","ꜻ","ꜽ","ḃ","ḅ","ɓ","ḇ","ᵬ","ᶀ","ƀ","ƃ","ɵ","ć","č","ç","ḉ","ĉ","ɕ","ċ","ƈ","ȼ","ď","ḑ","ḓ","ȡ","ḋ","ḍ","ɗ","ᶑ","ḏ","ᵭ","ᶁ","đ","ɖ","ƌ","ı","ȷ","ɟ","ʄ","dz","dž","é","ĕ","ě","ȩ","ḝ","ê","ế","ệ","ề","ể","ễ","ḙ","ë","ė","ẹ","ȅ","è","ẻ","ȇ","ē","ḗ","ḕ","ⱸ","ę","ᶒ","ɇ","ẽ","ḛ","ꝫ","ḟ","ƒ","ᵮ","ᶂ","ǵ","ğ","ǧ","ģ","ĝ","ġ","ɠ","ḡ","ᶃ","ǥ","ḫ","ȟ","ḩ","ĥ","ⱨ","ḧ","ḣ","ḥ","ɦ","ẖ","ħ","ƕ","í","ĭ","ǐ","î","ï","ḯ","ị","ȉ","ì","ỉ","ȋ","ī","į","ᶖ","ɨ","ĩ","ḭ","ꝺ","ꝼ","ᵹ","ꞃ","ꞅ","ꞇ","ꝭ","ǰ","ĵ","ʝ","ɉ","ḱ","ǩ","ķ","ⱪ","ꝃ","ḳ","ƙ","ḵ","ᶄ","ꝁ","ꝅ","ĺ","ƚ","ɬ","ľ","ļ","ḽ","ȴ","ḷ","ḹ","ⱡ","ꝉ","ḻ","ŀ","ɫ","ᶅ","ɭ","ł","lj","ſ","ẜ","ẛ","ẝ","ḿ","ṁ","ṃ","ɱ","ᵯ","ᶆ","ń","ň","ņ","ṋ","ȵ","ṅ","ṇ","ǹ","ɲ","ṉ","ƞ","ᵰ","ᶇ","ɳ","ñ","nj","ó","ŏ","ǒ","ô","ố","ộ","ồ","ổ","ỗ","ö","ȫ","ȯ","ȱ","ọ","ő","ȍ","ò","ỏ","ơ","ớ","ợ","ờ","ở","ỡ","ȏ","ꝋ","ꝍ","ⱺ","ō","ṓ","ṑ","ǫ","ǭ","ø","ǿ","õ","ṍ","ṏ","ȭ","ƣ","ꝏ","ɛ","ᶓ","ɔ","ᶗ","ȣ","ṕ","ṗ","ꝓ","ƥ","ᵱ","ᶈ","ꝕ","ᵽ","ꝑ","ꝙ","ʠ","ɋ","ꝗ","ŕ","ř","ŗ","ṙ","ṛ","ṝ","ȑ","ɾ","ᵳ","ȓ","ṟ","ɼ","ᵲ","ᶉ","ɍ","ɽ","ↄ","ꜿ","ɘ","ɿ","ś","ṥ","š","ṧ","ş","ŝ","ș","ṡ","ṣ","ṩ","ʂ","ᵴ","ᶊ","ȿ","ɡ","ᴑ","ᴓ","ᴝ","ť","ţ","ṱ","ț","ȶ","ẗ","ⱦ","ṫ","ṭ","ƭ","ṯ","ᵵ","ƫ","ʈ","ŧ","ᵺ","ɐ","ᴂ","ǝ","ᵷ","ɥ","ʮ","ʯ","ᴉ","ʞ","ꞁ","ɯ","ɰ","ᴔ","ɹ","ɻ","ɺ","ⱹ","ʇ","ʌ","ʍ","ʎ","ꜩ","ú","ŭ","ǔ","û","ṷ","ü","ǘ","ǚ","ǜ","ǖ","ṳ","ụ","ű","ȕ","ù","ủ","ư","ứ","ự","ừ","ử","ữ","ȗ","ū","ṻ","ų","ᶙ","ů","ũ","ṹ","ṵ","ᵫ","ꝸ","ⱴ","ꝟ","ṿ","ʋ","ᶌ","ⱱ","ṽ","ꝡ","ẃ","ŵ","ẅ","ẇ","ẉ","ẁ","ⱳ","ẘ","ẍ","ẋ","ᶍ","ý","ŷ","ÿ","ẏ","ỵ","ỳ","ƴ","ỷ","ỿ","ȳ","ẙ","ɏ","ỹ","ź","ž","ẑ","ʑ","ⱬ","ż","ẓ","ȥ","ẕ","ᵶ","ᶎ","ʐ","ƶ","ɀ","ff","ffi","ffl","fi","fl","ij","œ","st","ₐ","ₑ","ᵢ","ⱼ","ₒ","ᵣ","ᵤ","ᵥ","ₓ"]; for(let i = 0; i < string.length; i++){ if(jQuery.inArray(string[i], map) === -1) { result += string[i] } else { result += "\\\\u" + ("000" + string[i].charCodeAt(0).toString(16)).substr(-4); } } return result; }; function CMB2ConditionalToggleRows(obj, showOrHide){ var $elements = (obj instanceof jQuery) ? obj : $(obj); return $elements.each(function(i, e) { let $e = $(e); $e.prop('required', showOrHide && $e.data('conditional-required')); $e.parents('.cmb-row:first').toggle(showOrHide); }); } CMB2ConditionalsInit('#post'); }); But it is giving me error below After searched stackoverflow, I got that it will not work on firefox. Is there any way to fix it? BTW, other browser working fine. Thanks in advance.
As you can see the let keyword isn't supported on FF yet: https://kangax.github.io/compat-table/es6/ You will need to change it to var, or transpile your code with babel
How to convert a repetitive block of code to a function
I've got a sequence of code that will be run for the large majority of input items in a contact form; for the sake of lines of code, I want to have this operate as a function. Here is an example of the block: $('#country_code').blur(function() { var countryCode = $('#country_code').val(); if(validateNumber(countryCode) == true) { if(countryCode.lastIndexOf('+') != 0) { countryCode = countryCode.replace('+', ''); $('#country_code').val('+' + countryCode); } } else { countryCode = ''; $('#country_code').val(countryCode); } }); And I want to create a function like the following: function validateElements(elementName, variableName, validationFunction, indexValue, indexPosition) { $(elementName).blur(function() { var variableName = $(elementName).val(); if(validationFunction(variableName) == true) { if(variableName.lastIndexOf(indexValue) != indexPosition) { variableName = variableName.replace(indexValue, ''); $(elementName).val(indexValue + variableName); } } else { variableName = ''; $(elementname).val(variableName); } }); } In which I'd call the function like follows: validateElements('#country_code', 'countryCode', 'validateNumber', '+', 0);
Try changing it so that you call your function as follows: validateElements($('#country_code'), 'countryCode', 'validateNumber', '+', 0); And the change your function: function validateElements(obj, variableName, validationFunction, indexValue, indexPosition) { obj.blur(function() { var variableName = obj.val(); if(validationFunction(variableName) == true) { if(variableName.lastIndexOf(indexValue) != indexPosition) { variableName = variableName.replace(indexValue, ''); obj.val(indexValue + variableName); } } else { variableName = ''; obj.val(variableName); } }); }