0
   

Conflict betwen Javascript

 
 
Reply Tue 28 Jul, 2015 02:32 am
I'm trying to add a buy tickets button to a pre existing site but the code clashes with two codes that add social sharing.

The ticket code is...

<div target="_blank" data-width="300" data-height="70" data-event-id="12" data-type="EVENT" href="#widget" id="jambolife-widget-container" >Fetching ticketing data...</div><div class="modal"></div><script>(function(d, t) { var g = d.createElement(t), s = d.getElementsByTagName(t)[0];g.src = 'http://jambolife.com/assets/sdk/jambolife.sdk.js'; s.parentNode.insertBefore(g, s); }(document, 'script')); window.addEventListener('message', function(e) { eval(e.data.js); $('.modal').html('<iframe src="'+e.data.url+'" width="100%" height="450px" frameBorder="0"></iframe>').removeClass("modal") });</script>

and the conflicting code:

<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&appId=244225212408966&version=v2.0";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>

if I can figure out why the two conflict and how to fix it I can then work on fixing the issue with the last one

http://w.sharethis.com/button/buttons.js

And some more in this code:

var SLIDESHOW_IX = 0, SLIDESHOW_INTERVAL;

$.fn.create = function(name) {
return $(document.createElement(name));
};

function adjust_layout(){
$("#images").animate({height:$("#images img").height()});

if(SLIDESHOW_INTERVAL){
window.clearInterval(SLIDESHOW_INTERVAL);
}

/* Make slideshow work with StackLayout by setting fixed widths and heights and making full slides absolute */

var $hhsc = $("#home-hot-small-container");
if($hhsc.length){

var indexOfCurrSlide = 0;
var thumbs = $('.home-hot-small-stack');
$(thumbs[indexOfCurrSlide]).hide();


var $hhs = $(".home-hot");
var noOfSlides = $hhs.length;
var $whc = $("#whats-hot-container");
var $hhsw = $("#home-hot-small-wrapper");
$hhs.css('width', 'auto').removeClass("absolute");
$whc.css("height", "auto").height($whc.height());
$hhs.width($hhs.width()).addClass("absolute").css({top:10, left:10});
$(".home-hot-small-stack").width($hhsw.width() / 4);
$hhsc.css({ width:10000, height: "auto" });
SLIDESHOW_INTERVAL = window.setInterval(function(){
indexOfCurrSlide++;
if (indexOfCurrSlide > noOfSlides) indexOfCurrSlide = 1;

thumbs.show();
$(thumbs[indexOfCurrSlide]).hide();

var $hhsc = $("#home-hot-small-container");
var $hhsw = $("#home-hot-small-wrapper");
var old_ix = SLIDESHOW_IX;
SLIDESHOW_IX += 1;
if( SLIDESHOW_IX == $(".home-hot").length){
SLIDESHOW_IX= 0;
}
$(".home-hot").eq(old_ix).fadeOut(300);
$(".home-hot").eq(SLIDESHOW_IX).fadeIn(300);
var ml = parseInt($hhsc.css("marginLeft").replace("px", ""),10) - $hhsw.width() / 4;
$hhsc.animate({
marginLeft: ml
}, 300, function(){
$("#home-hot-small-container .image-wrapper").eq(0).removeClass("current");
$("#home-hot-small-container .image-wrapper").eq(1).addClass("current");
$("#home-hot-small-container").append($(".home-hot-small-stack").eq(0).remove());
$hhsc.css({ marginLeft: ml + $hhsw.width() / 4});
});
}, 4000);
}
}

/* Custom Map plugin */

(function($){
var KBMap = function(element, options){
var settings = $.extend({
base_url: window.location.href,
start_ix:1,
lat:0,
lng:0,
map_attribution: 'Map Data © OpenStreetMap, Tiles © MapQuest',
single_marker: false,
zoom:11
}, options || {});

var obj = this;
var $e = $(element);
$e.height($e.width());

this.map = L.map(element).setView([settings.lat, settings.lng], settings.zoom);

var layer = L.tileLayer('http://otile{s}.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.jpg', {
subdomains: ['1','2','3','4'],
attribution: settings.map_attribution,
maxZoom: 18
});

layer.addTo(this.map);

this.load_data = function(ix){
function setHeader(xhr){
xhr.setRequestHeader('Accept', 'application/json');
}
$.ajax({
url: settings.base_url + '?page=' + ix,
type: 'GET',
dataType: 'json',
success: function(data) {
$map_items = $("#map-items");
var l = data.length;
for(var i = 0; i < l; i++) {
var v = data;
var f = v.fields;
var e = v.extras;
var popup = '<a href="' + e.get_absolute_url + '">' + f.name + '</a>';
L.marker([f.latitude, f.longitude])
.bindPopup(popup)
.addTo(obj.map);

$map_items.append(
'<li><a class="' + (i % 2 ? 'odd' : 'even') + '" href="#map-item-' + v.pk + '" data-popup="' + escape(popup) + '" data-longitude="' + f.longitude + '" data-latitude="' + f.latitude + '">' + f.name + '</a></li>'
);
}
$map_items.on('click', 'a', function(evt){
evt.preventDefault();
var lat = parseFloat($(this).attr('data-latitude'));
var lng = parseFloat($(this).attr('data-longitude'));
L.popup()
.setLatLng([lat, lng])
.setContent(unescape($(this).attr('data-popup')))
.openOn(obj.map);
});
},
error: function() {},
beforeSend: setHeader
});
};
if(settings.single_marker){
L.marker([settings.lat, settings.lng])
.bindPopup(settings.single_marker)
.addTo(this.map);
} else {
this.load_data(settings.start_ix);
}
};

$.fn.kbmap = function(options) {
return this.each(function() {
var $e = $(this);
if ($e.data('kbmap')) {
return;
}
var kbm = new KBMap(this, options);
$e.data('kbmap', kbm);
});
};
})(jQuery);

var button_animation;

function start_button_animation(el){
el.data('initial', el.val());
el.val('-');
button_animation = window.setInterval(function(){
el.val(el.val() + '-');
if(el.val().length == 10){
el.val('-');
}
}, 500)
}

function stop_button_animation(el){
if(button_animation){
window.clearInterval(button_animation)
}
el.val(el.data('initial'))
}

$(document).ready(function(){

/* Toggles input type between text and password to be able to display 'password' if empty */

function toggle_password_input(e){
var $pc = $("#id_password").clone();
var t = $pc.attr('type').toLowerCase();
if(t == 'password'){
if($pc.val()){
return;
}
$pc.val('password').attr('type', 'text');
$("#id_password").replaceWith($pc);
} else {
$pc.val('').attr('type', 'password');
$("#id_password").replaceWith($pc);
$pc.focus();
}
$("#id_password").on('blur focus', toggle_password_input);
}
if($("#id_password").length){
toggle_password_input();
}

/* Default input values back if input left empty */
$("#id_q, #id_em, #id_username").focus(function(){
var $q = $(this);
var v = $q.val();
if(v == 'search kenya buzz' || v == 'your email' || v == 'user name'){
$q.data('initial', v);
$q.val('');
}
});
$("#id_q, #id_em, #id_username").blur(function(){
var $q = $(this);
var v = $q.val();
if(v == ''){
$q.val($q.data('initial'));
}
});

/* List filters */
$("body").click(function(evt){
$(".filter > ul").slideUp(150);
});

$(".filter").not('.clickable').click(function(evt){
evt.stopPropagation();
evt.preventDefault();
$filter = $(this);
$(".filter > ul").not($filter).slideUp(150);
if($filter.find("> ul:visible").length){
$filter.find("> ul").slideUp(250);
} else {
$filter.find("> ul").slideDown(250);
}
});

$(".filter-button-child").mouseover(function(evt){
$btn = $(this);
$ul = $btn.next(".filter-children");
if($ul.length){
$btn.parents(".filter-main").find(".filter-children").not($ul).slideUp();
$ul.slideDown();
}
});

$(".filter ul a ").click(function(evt){
evt.stopPropagation();
});

/* Mini slideshow navigation on detail */
$(".thumbnail").click(function(e){
e.preventDefault();
var $this = $(this);
var $thumbs = $(".thumbnail");
var ix = $.inArray(this, $thumbs);
$thumbs.not($this).removeClass("current");
$this.addClass("current");
$("#images img:visible").stop(true, true).fadeOut(300);
$("#images img").stop(true, true).eq(ix).fadeIn(300);
});

/* Make flash clickable */
$("object").parents('.info').css('cursor', 'pointer').on('mousedown', function(e){
window.location = $(this).find('a').attr("href");
});

/* Whole div clickable */
$(".home-hot").click(function(){
window.location = $(this).find("a").attr("href");
});

/* Calendar navigation */
$("#calendar-container").on('click', '.calendar-nav', function(e){
e.preventDefault();
$("#calendar-container").load($(this).attr('href'));
});

/* Home page named anchor navigation */
$(".home-quick-nav .filter-button").click(function(e){
e.preventDefault();
$("html, body").stop(true, true).animate({
scrollTop:$($(this).attr("href")).position().top - 69
}, 350);
});

/* Fancybox! */

$(".fancy").fancybox();
$(".fancy-inline").fancybox({
maxWidth : 400,
maxHeight : 300,
width : '75%',
height : '75%',
fitToView : false,
autoSize : false,
closeClick : false,
openEffect : 'none',
closeEffect : 'none',
afterShow : function(c, p){
$('.fancy-content').find('form').submit(function(){
var f = $(this);
var fld = f.find("input.valid");
if(fld.length){
var s = fld[0].name;
var r = s.split("").reverse().join("");
fld[0].value = r;
}
start_button_animation(f.find(".button"));
$.post(f.attr("action"),
f.serialize(),
function(data) {
f.find("input, textarea, select").removeClass("error").attr("title", "");
f.find("p.error").remove();
stop_button_animation(f.find(".button"));
if(data.type == 'error'){
for(k in data.msg){
$("[for='id_" + k + "']")
.after('<p class="stackContent error">' + data.msg[k] + '</p>')
}
}
else
{
$.fancybox(data.msg, {
maxWidth : 400,
maxHeight : 200,
width : '75%',
height : '75%',
fitToView : false,
autoSize : false,
closeClick : false,
openEffect : 'none',
closeEffect : 'none'
});
}
},
'json'
);
return false;
});
}
});

/* Pop newsletter if #newsletter in url "as" hash */

if(window.location.hash == '#newsletter') {
var $div = $('#newsletter');
$div.find("a").click();
}
});

$(window).load(function(){
adjust_layout();

/* Facebook like widget last as it is pretty slooow */
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1&appId=418739634841448";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
});

/* Timer for layout adjustments after window resize.
* Has a delay in order not to fire too manu events
*/

var pause_timer;

$(window).resize(function() {
if (pause_timer) {
window.clearTimeout(pause_timer);
}
pause_timer = window.setTimeout(function() {
pause_timer = null;
adjust_layout();
}, 250);
});


$(document).ready(function(){

// footer slider

$('#footer-gallery')
.css('display', 'inline-block')
.microfiche({
bullets: false,
cyclic: true,
autoplay: 5,
autopause: true,
prevButtonLabel : '◀',
nextButtonLabel : '▶'
});

// search
$('#search-form .icon-search').click(function(e){
$('#search-form').submit();
});


});


Email an idea to [email protected]
  • Topic Stats
  • Top Replies
  • Link to this Topic
Type: Question • Score: 0 • Views: 1,012 • Replies: 0
No top replies

 
 

Related Topics

 
  1. Forums
  2. » Conflict betwen Javascript
Copyright © 2024 MadLab, LLC :: Terms of Service :: Privacy Policy :: Page generated in 0.04 seconds on 04/25/2024 at 04:22:13