Skip to content

Instantly share code, notes, and snippets.

View LucasCalazans's full-sized avatar
:octocat:
jQuery > JS

Lucas Calazans LucasCalazans

:octocat:
jQuery > JS
View GitHub Profile
@LucasCalazans
LucasCalazans / cc-utils.js
Last active June 5, 2020 17:51
Verify the CC brand
export const CC_BRAND_ELO = 'elo';
export const CC_BRAND_VISA = 'visa';
export const CC_BRAND_MASTER = 'master';
export const CC_BRAND_AMEX = 'amex';
export const CC_BRAND_DISCOVER = 'discover';
export const CC_BRAND_DINERS = 'diners';
export const CC_BRAND_HIPER = 'hiper';
const REPEATED_NUMBERS = 'not-valid';
export const getCardBrand = number => {
@LucasCalazans
LucasCalazans / README.md
Last active November 25, 2024 11:23
Magento - KnockoutJS (Add masks to all fields in the store)
@LucasCalazans
LucasCalazans / default.xml
Last active June 19, 2018 15:02
Add "sticky-header" class to body
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<link src="js/sticky-header.js" type="application/javascript" />
</head>
</page>
@LucasCalazans
LucasCalazans / checkout_cart_index.xml
Last active July 24, 2018 15:17
Magento 2 - Remove all Gift references including KnockoutJS components.
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="checkout.cart.giftcardaccount" remove="true" />
<referenceBlock name="checkout.cart.order.actions.gift_options" remove="true" />
<referenceBlock name="checkout.cart.item.renderers.simple.actions.gift_options" remove="true" />
<referenceBlock name="checkout.cart.item.renderers.default.actions.gift_options" remove="true" />
<referenceBlock name="checkout.cart.item.renderers.bundle.actions.gift_options" remove="true" />
<referenceBlock name="checkout.cart.item.renderers.configurable.actions.gift_options" remove="true" />
<referenceBlock name="checkout.cart.item.renderers.giftcard.actions.gift_options" remove="true" />
@LucasCalazans
LucasCalazans / trigger.js
Last active May 11, 2020 20:20
Trigger function without jQuery
const trigger = (element, eventName) => {
let event;
if (document.createEvent) {
event = document.createEvent("HTMLEvents");
event.initEvent(eventName, true, true);
} else {
event = document.createEventObject();
event.eventType = eventName;
}
@LucasCalazans
LucasCalazans / browser.js
Last active May 11, 2020 20:16
Force Magento 2 to update the js-translation.json when some .csv is changed
// Run this code on your browser console
localStorage.removeItem("mage-translation-file-version")
@LucasCalazans
LucasCalazans / Success.php
Last active July 24, 2018 14:03
Changing this file will give the possibility of update many times the success page, useful to front-enders.
<?php
// vendor/magento/module-checkout/Controller/Onepage/Success.php
// or app/code/Magento/Checkout/Controller/Onepage/Success.php
// Comment the follow line
$session->clearQuote();
@LucasCalazans
LucasCalazans / Action.php
Last active August 1, 2018 22:55
Simulate Magento messages, useful to front-enders.
<?php
// Edit the follow file: vendor/magento/framework/App/Action/Action.php
public function __construct(Context $context)
{
// ... //
$this->messageManager->addError(__('Error message.'));
$this->messageManager->addSuccessMessage(__('Success message.'));
$this->messageManager->addWarning(__('Warning message.'));
}
# Editor configuration, see https://editorconfig.org
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true
@LucasCalazans
LucasCalazans / no-usememo-form.js
Last active May 28, 2019 19:02
Form validation without useMemo
const rules = [
'8 characteres',
'lowercase word',
'uppercase word',
];
// Lista de erros
const Errors = ({ active }) => {
return active && (
<ul>