Skip to content

Instantly share code, notes, and snippets.

@micronax
Last active December 23, 2015 08:59
Show Gist options
  • Save micronax/6611783 to your computer and use it in GitHub Desktop.
Save micronax/6611783 to your computer and use it in GitHub Desktop.
Einen Gutschein-Code nach einer bestimmten Zeit in einem Online-Shop einblenden. (Bspw.: Shopware, Magento, ...) Support und Hilfe unter: www.fabian-golle.de/kontakt ---- Displaying a coupon code after a specific amount of time. Perfect for usage in online shops like Magento...
<!-- Include CSS -->
<link href="livecoupon.css" rel="stylesheet">
<!-- Include Javascript -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.1/jquery.min.js"></script>
<script src="livecoupon.js"></script>
<!-- LiveCoupon begin -->
<div id="liveCoupon">
<a href="#your_coupon_link"><img src="example_coupon_image.png" alt="Couponcode XYZ" /></a>
</div>
<!-- LiveCoupon end -->
#liveCoupon {
width:auto;
height:auto;
position: absolute;
bottom:10px;
left:10px;
display:none;
}
/*!
* LiveCoupon.js
* https://gist.github.com/micronax/6611783
*
* Copyright 2013 Fabian Golle <me@fabian-golle.de>
*/
$(document).ready(function() {
var TTL = 35; // Time in seconds until coupon is displayed
function fireCoupon() {
// Show discount / coupon code
$('#liveCoupon').fadeIn();
};
var expiration;
if ($.cookie('livecouponttl') == undefined) {
expiration = new Date(new Date().getTime() + TTL * 1000);
$.cookie('livecouponttl', expiration);
setTimeout('fireCoupon', TTL * 1000);
} else {
expiration = new Date($.cookie('livecouponttl'));
if (expiration.getTime() < new Date().getTime()) {
// Fire coupon
fireCoupon();
} else {
var diff = expiration.getTime() - new Date().getTime()
setTimeout('fireCoupon', diff);
}
}
});
/*!
* jQuery Cookie Plugin v1.3.1
* https://github.com/carhartl/jquery-cookie
*
* Copyright 2013 Klaus Hartl
* Released under the MIT license
*/
(function(e){if(typeof define==="function"&&define.amd){define(["jquery"],e)}else{e(jQuery)}})(function(e){function n(e){return e}function r(e){return decodeURIComponent(e.replace(t," "))}function i(e){if(e.indexOf('"')===0){e=e.slice(1,-1).replace(/\\"/g,'"').replace(/\\\\/g,"\\")}try{return s.json?JSON.parse(e):e}catch(t){}}var t=/\+/g;var s=e.cookie=function(t,o,u){if(o!==undefined){u=e.extend({},s.defaults,u);if(typeof u.expires==="number"){var a=u.expires,f=u.expires=new Date;f.setDate(f.getDate()+a)}o=s.json?JSON.stringify(o):String(o);return document.cookie=[s.raw?t:encodeURIComponent(t),"=",s.raw?o:encodeURIComponent(o),u.expires?"; expires="+u.expires.toUTCString():"",u.path?"; path="+u.path:"",u.domain?"; domain="+u.domain:"",u.secure?"; secure":""].join("")}var l=s.raw?n:r;var c=document.cookie.split("; ");var h=t?undefined:{};for(var p=0,d=c.length;p<d;p++){var v=c[p].split("=");var m=l(v.shift());var g=l(v.join("="));if(t&&t===m){h=i(g);break}if(!t){h[m]=i(g)}}return h};s.defaults={};e.removeCookie=function(t,n){if(e.cookie(t)!==undefined){e.cookie(t,"",e.extend({},n,{expires:-1}));return true}return false}})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment