Skip to content

Instantly share code, notes, and snippets.

View raihan004's full-sized avatar
🏠
Working from home

MH Raihan raihan004

🏠
Working from home
View GitHub Profile
@raihan004
raihan004 / blob-filereader-localStorage.js
Created November 15, 2020 00:00 — forked from robnyman/blob-filereader-localStorage.js
Get file as a blob, read through FileReader and save in localStorage
// Getting a file through XMLHttpRequest as an arraybuffer and creating a Blob
var rhinoStorage = localStorage.getItem("rhino"),
rhino = document.getElementById("rhino");
if (rhinoStorage) {
// Reuse existing Data URL from localStorage
rhino.setAttribute("src", rhinoStorage);
}
else {
// Create XHR and FileReader objects
var xhr = new XMLHttpRequest(),
@raihan004
raihan004 / shopify-money.js
Created August 27, 2019 17:01 — forked from stewartknapman/shopify-money.js
The Shopify.formatMoney method extracted from option_selection.js for stand-alone purposes.
var Shopify = Shopify || {};
// ---------------------------------------------------------------------------
// Money format handler
// ---------------------------------------------------------------------------
Shopify.money_format = "${{amount}}";
Shopify.formatMoney = function(cents, format) {
if (typeof cents == 'string') { cents = cents.replace('.',''); }
var value = '';
var placeholderRegex = /\{\{\s*(\w+)\s*\}\}/;
var formatString = (format || this.money_format);
@raihan004
raihan004 / jquery.shopify-ajax-cart.js
Created July 17, 2019 03:28 — forked from schmoove/jquery.shopify-ajax-cart.js
A handy jQuery plugin for updating the Shopify Cart via their AJAX API
/*
* Project: Shopify AJAX Cart Plugin
* Description: Provides AJAX cart functionality for interacting with the Shopify AJAX API so you don't need an "Update Cart" button
* Dependency: jQuery 1.6+
* Author: Ryan Marshall (ryan@schmoove.co.nz)
* License: Free
* Usage:
*
* $('#cart-form').shopifyAJAXCart({
* item: '.line-item-container',
@raihan004
raihan004 / gulpfile.js
Created November 9, 2018 17:26 — forked from derekmorash/gulpfile.js
Gulp task to compile Shopify Liquid tags in SASS with Autoprefixer
var gulp = require('gulp');
var sass = require('gulp-sass');
var replace = require('gulp-replace');
var autoprefixer = require('gulp-autoprefixer');
var concat = require('gulp-concat');
gulp.task('compilesass', function() {
// root SASS file (contains all your includes)
return gulp.src('./sass/style.scss')
// compile SASS to CSS
@raihan004
raihan004 / bootstrap-pagination.liquid
Last active August 14, 2018 23:44 — forked from kyleaparker/gist:7588995
Shopify: Show all numbers in pagination
<nav aria-label="Page navigation example">
<ul class="pagination">
<li class="page-item {% unless paginate.previous.is_link %} disabled {% endunless %}">
<a class="page-link" href="{{ paginate.previous.url }}" aria-label="Previous">
<span aria-hidden="true">&laquo;</span>
<span class="sr-only">{{ 'general.pagination.previous' | t }}</span>
</a>
</li>
{% assign count = paginate.pages %}
{% for part in paginate.parts %}
@raihan004
raihan004 / random.js
Created July 11, 2018 18:47 — forked from kerimdzhanov/random.js
JavaScript: get a random number from a specific range
/**
* Get a random floating point number between `min` and `max`.
*
* @param {number} min - min number
* @param {number} max - max number
* @return {number} a random floating point number
*/
function getRandomFloat(min, max) {
return Math.random() * (max - min) + min;
}
@raihan004
raihan004 / index.html
Created June 24, 2018 20:56 — forked from cole007/index.html
Shopify API filter for product prices
<!DOCTYPE html>
<html class="no-js">
<head>
<meta charset="utf-8">
<title>Shopify filtering Boilerplate</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="_assets/css/style.css">
</head>
<body>
@raihan004
raihan004 / available-colors.liquid
Created June 18, 2018 01:19 — forked from carolineschnapp/available-colors.liquid
Snippet that says 'also available in colors x and y' on the collection page when a product is available in more than 1 color. To include in product-loop.liquid, or product-grid-item.liquid.
{% comment %}
Do we have a Color option?
If so, is it the first, second or third option of that product?
We will need to access values so we need that color index.
{% endcomment %}
{% assign has_color = false %}
{% assign color_option_index = 0 %}
{% for option in product.options %}
{% assign downcased_option = option | downcase %}
@raihan004
raihan004 / gist:133b534a15ac07d2ee488140267bea14
Created April 30, 2018 12:33 — forked from kyleaparker/gist:5949872
Shopify - Show total savings on cart page
{% assign total_saving = 0 %}
{% for item in cart.items %}
{% if item.variant.compare_at_price > item.variant.price %}
{% capture saving %}{{ item.variant.compare_at_price | minus: item.variant.price }}{% endcapture %}
{% assign total_saving = saving | plus: total_saving %}
{% endif %}
...rest of cart code within for loop
{% endfor %}
Display saving:
@raihan004
raihan004 / remove-empty-p.js
Created April 14, 2018 09:09 — forked from MichaelVanDenBerg/remove-empty-p.js
Remove empty <p> tags with jQuery.
/**
* Remove empty <p> tags.
*
* See: http://stackoverflow.com/questions/27781798/wordpress-retain-formatting-when-calling-extended-content#comment43990361_27782619
* This seems to be the easiest solution. Remove this function if this ever gets fixed.
* Credits: http://stackoverflow.com/questions/6092855/how-do-i-remove-empty-p-tags-with-jquery
*/
( function( $ ) {
$( 'p' ).each( function() {