I have a big issue with JavaScript pop up modal windows displaying a YouTube iframe video! I've been spending already a week or even more to find a solution to this problem, on the internet but it seems that there are not many resources or answers and/or solutions to this problem I have, so I thought I should ask for your help on this.
=========================================================================
THE PROBLEM:
OK, I have an image on my offline website that when you click on it, it fires a pop up modal window in the browser, with a iframe YouTube video clip and when you click on it the YouTube video it plays as it should be. So far so good, all works fine until you close the window (by clicking anywhere outside of the video or on the X button, as usual!), however, the problem is that even the video closes, the sound still continues playing in the background as if the video is still there, even though the video is not as its been closed successfully.
By the way, this issue happens on all browsers.
This is the code, the same code you can find on the jsfiddle link below:
<!-- Button that triggers the popup -->
<button id="my-button"> Play video </button>
<!-- Element to pop up -->
<div id="element_to_pop_up">
<a class="b-close"> x <a/>
<iframe width="450" height="315" src="https://www.youtube.com/embed/Ev4zBCBEELQ" frameborder="0" allowfullscreen></iframe>
</div><!-- end of element_to_pup_up id -->
=========================================================================
#element_to_pop_up {
background-color:#fff;
border-radius:15px;
color:#000;
display:none;
padding:20px;
min-width:400px;
min-height: 180px;
}
.b-close {
cursor:pointer;
position:absolute;
right:10px;
top:5px;
}
=========================================================================
// Semicolon (;) to ensure closing of earlier scripting
// Encapsulation
// $ is assigned to jQuery
;
(function ($) {
// DOM Ready
$(function () {
// Binding a click event
// From jQuery v.1.7.0 use .on() instead of .bind()
$('#my-button').bind('click', function (e) {
// Prevents the default action to be triggered.
e.preventDefault();
// Triggering bPopup when click event is fired
$('#element_to_pop_up').bPopup();
});
});
})(jQuery);
(function (b) {
b.fn.bPopup = function (z, F) {
function K() {
a.contentContainer = b(a.contentContainer || c);
switch (a.content) {
case "iframe":
var h = b('<iframe class="b-iframe" ' + a.iframeAttr + "></iframe>");
h.appendTo(a.contentContainer);
r = c.outerHeight(!0);
s = c.outerWidth(!0);
A();
h.attr("src", a.loadUrl);
k(a.loadCallback);
break;
case "image":
A();
b("<img />").load(function () {
k(a.loadCallback);
G(b(this))
}).attr("src", a.loadUrl).hide().appendTo(a.contentContainer);
break;
default:
A(), b('<div class="b-ajax-wrapper"></div>').load(a.loadUrl, a.loadData, function () {
k(a.loadCallback);
G(b(this))
}).hide().appendTo(a.contentContainer)
}
}
function A() {
a.modal && b('<div class="b-modal ' + e + '"></div>').css({
backgroundColor: a.modalColor,
position: "fixed",
top: 0,
right: 0,
bottom: 0,
left: 0,
opacity: 0,
zIndex: a.zIndex + t
}).appendTo(a.appendTo).fadeTo(a.speed, a.opacity);
D();
c.data("bPopup", a).data("id", e).css({
left: "slideIn" == a.transition || "slideBack" == a.transition ? "slideBack" == a.transition ? g.scrollLeft() + u : -1 * (v + s) : l(!(!a.follow[0] && m || f)),
position: a.positionStyle || "absolute",
top: "slideDown" == a.transition || "slideUp" == a.transition ? "slideUp" == a.transition ? g.scrollTop() + w : x + -1 * r : n(!(!a.follow[1] && p || f)),
"z-index": a.zIndex + t + 1
}).each(function () {
a.appending && b(this).appendTo(a.appendTo)
});
H(!0)
}
function q() {
a.modal && b(".b-modal." + c.data("id")).fadeTo(a.speed, 0, function () {
b(this).remove()
});
a.scrollBar || b("html").css("overflow", "auto");
b(".b-modal." + e).unbind("click");
g.unbind("keydown." + e);
d.unbind("." + e).data("bPopup", 0 < d.data("bPopup") - 1 ? d.data("bPopup") - 1 : null);
c.undelegate(".bClose, ." + a.closeClass, "click." + e, q).data("bPopup", null);
H();
return !1
}
function G(h) {
var b = h.width(),
e = h.height(),
d = {};
a.contentContainer.css({
height: e,
width: b
});
e >= c.height() && (d.height = c.height());
b >= c.width() && (d.width = c.width());
r = c.outerHeight(!0);
s = c.outerWidth(!0);
D();
a.contentContainer.css({
height: "auto",
width: "auto"
});
d.left = l(!(!a.follow[0] && m || f));
d.top = n(!(!a.follow[1] && p || f));
c.animate(d, 250, function () {
h.show();
B = E()
})
}
function L() {
d.data("bPopup", t);
c.delegate(".bClose, ." + a.closeClass, "click." + e, q);
a.modalClose && b(".b-modal." + e).css("cursor", "pointer").bind("click", q);
M || !a.follow[0] && !a.follow[1] || d.bind("scroll." + e, function () {
B && c.dequeue().animate({
left: a.follow[0] ? l(!f) : "auto",
top: a.follow[1] ? n(!f) : "auto"
}, a.followSpeed, a.followEasing)
}).bind("resize." + e, function () {
w = y.innerHeight || d.height();
u = y.innerWidth || d.width();
if (B = E()) clearTimeout(I), I = setTimeout(function () {
D();
c.dequeue().each(function () {
f ? b(this).css({
left: v,
top: x
}) : b(this).animate({
left: a.follow[0] ? l(!0) : "auto",
top: a.follow[1] ? n(!0) : "auto"
}, a.followSpeed, a.followEasing)
})
}, 50)
});
a.escClose && g.bind("keydown." + e, function (a) {
27 == a.which && q()
})
}
function H(b) {
function d(e) {
c.css({
display: "block",
opacity: 1
}).animate(e, a.speed, a.easing, function () {
J(b)
})
}
switch (b ? a.transition : a.transitionClose || a.transition) {
case "slideIn":
d({
left: b ? l(!(!a.follow[0] && m || f)) : g.scrollLeft() - (s || c.outerWidth(!0)) - C
});
break;
case "slideBack":
d({
left: b ? l(!(!a.follow[0] && m || f)) : g.scrollLeft() + u + C
});
break;
case "slideDown":
d({
top: b ? n(!(!a.follow[1] && p || f)) : g.scrollTop() - (r || c.outerHeight(!0)) - C
});
break;
case "slideUp":
d({
top: b ? n(!(!a.follow[1] && p || f)) : g.scrollTop() + w + C
});
break;
default:
c.stop().fadeTo(a.speed, b ? 1 : 0, function () {
J(b)
})
}
}
function J(b) {
b ? (L(), k(F), a.autoClose && setTimeout(q, a.autoClose)) : (c.hide(), k(a.onClose), a.loadUrl && (a.contentContainer.empty(), c.css({
height: "auto",
width: "auto"
})))
}
function l(a) {
return a ? v + g.scrollLeft() : v
}
function n(a) {
return a ? x + g.scrollTop() : x
}
function k(a) {
b.isFunction(a) && a.call(c)
}
function D() {
x = p ? a.position[1] : Math.max(0, (w - c.outerHeight(!0)) / 2 - a.amsl);
v = m ? a.position[0] : (u - c.outerWidth(!0)) / 2;
B = E()
}
function E() {
return w > c.outerHeight(!0) && u > c.outerWidth(!0)
}
b.isFunction(z) && (F = z, z = null);
var a = b.extend({}, b.fn.bPopup.defaults, z);
a.scrollBar || b("html").css("overflow", "hidden");
var c = this,
g = b(document),
y = window,
d = b(y),
w = y.innerHeight || d.height(),
u = y.innerWidth || d.width(),
M = /OS 6(_\d)+/i.test(navigator.userAgent),
C = 200,
t = 0,
e, B, p, m, f, x, v, r, s, I;
c.close = function () {
a = this.data("bPopup");
e = "__b-popup" + d.data("bPopup") + "__";
q()
};
return c.each(function () {
b(this).data("bPopup") || (k(a.onOpen), t = (d.data("bPopup") || 0) + 1, e = "__b-popup" + t + "__", p = "auto" !== a.position[1], m = "auto" !== a.position[0], f = "fixed" === a.positionStyle, r = c.outerHeight(!0), s = c.outerWidth(!0), a.loadUrl ? K() : A())
})
};
b.fn.bPopup.defaults = {
amsl: 50,
appending: !0,
appendTo: "body",
autoClose: !1,
closeClass: "b-close",
content: "ajax",
contentContainer: !1,
easing: "swing",
escClose: !0,
follow: [!0, !0],
followEasing: "swing",
followSpeed: 500,
iframeAttr: 'scrolling="no" frameborder="0"',
loadCallback: !1,
loadData: !1,
loadUrl: !1,
modal: !0,
modalClose: !0,
modalColor: "#000",
onClose: !1,
onOpen: !1,
opacity: 0.7,
position: ["auto", "auto"],
positionStyle: "absolute",
scrollBar: !0,
speed: 250,
transition: "fadeIn",
transitionClose: !1,
zIndex: 9997
}
})(jQuery);
=========================================================================
Here I've created a JSFiddle link for all the code that is needed: https://jsfiddle.net/24A9b/13617/
obviously this modal is loading the video playing it, then when it's closed it's just being hidden, it's still in the DOM. You need to find a way of destroying this code that is brought into the DOM. You could use something like jQuery remove.
I had the same problem. Here's how I got around it:
https://jsfiddle.net/24A9b/14789/
HTML:
<!-- Button that triggers the popup -->
<button id="my-button"> Play video </button>
<!-- Element to pop up -->
<div id="element_to_pop_up" data-iframe-code="<iframe width='450' height='315' src='https://www.youtube.com/embed/Ev4zBCBEELQ' frameborder='0' allowfullscreen></iframe>">
<a class="b-close"> x <a/>
</div><!-- end of element_to_pop_up id -->
What I changed:
I took the iFrame code out of the DOM, and put it somewhere that it can be reused as often as we'd like. A data attribute probably isn't the best place to put it, but I was short on time and ideas. Comment if you can think of something better.
JS (Just the bPopup bit):
// Triggering bPopup when click event is fired
$('#element_to_pop_up').bPopup({
onOpen: function(){
$(this).append( $( $(this).data('iframe-code') ) );
},
onClose:function(){
$(this).find('iframe').remove();
}
});
What I changed:
Added an onOpen event to bPopup. When the popup opens, the iframe code gets added to the #element_to_pop_up div.
Added an onClose event, When the popup is closed, the iframe is deleted. Because it can't play in the background if it doesn't exist anymore.
You are writing a very big JS Code which I am not able to understand, just use this JSFiddle: http://jsfiddle.net/v95eg4h1/
I am using jQuery Library(1.11.0)
$(function(){
$("#showPopup").click(function(e){
e.stopPropagation();
$(".bg").toggle();
$(".popup").toggle();
});
$(".close").click(function() {
$('.modal').hide();
$("#arsha_video").attr('src','');
var video = $("#player").attr("src");
$("#player").attr("src","");
$("#player").attr("src",video);
});
$("body").click(function(){
$(".bg").toggle();
$(".popup").hide();
var video = $("#player").attr("src");
$("#player").attr("src","");
$("#player").attr("src",video);
});
});
.popup{
background-color:#E6E9F2;
position:absolute;
min-height:auto;
width:auto;
border: solid 2px #B9EAF0;
z-index: 1002;
}
.bg {
background-color:#111;
opacity: 0.65;
position:absolute;
z-index: 1000;
top:0px;
left:0px;
width:100%;
min-height:100%;
overflow:auto;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
CLICK
<div class="bg" style="display:none"></div>
<div class="popup" style="display:none">
<a class=".close"> x <a/>
<iframe id="player" width="560" height="315" src="https://www.youtube.com/embed/Ev4zBCBEELQ" frameborder="0" allowfullscreen></iframe>
</div>
if you didn't mind to change the approach then you can try colorbox. it is very good with popup with responsive design and easy to implement.
youtubevideo in iframe
Related
WP/Plug-in/Theme updates broke our site's "select a campus" button. It is a button that drops down a previously hidden carousel of campus images that scroll horizontally.
Clicking one redirects you. It is in the custom js of the theme, so that it is a sitewide header. The carousel is called "Advanced Carousel" built through the "Ultimate Addons for WPBakery"
I'm sorry, I have next to no web experience, and I was handed this website after someone else broke it. I am trying my best to learn as much as possible. Everything else now works but this part.
This is for a newly updated WP site, which hadn't been updated in years. When WP itself was updated, it broke all the sites and that's as far as the previous people got. I updated the plug-ins and themes and that fixed most the issues other than this carousel.
Here is the custom JS that is a part of the theme (should apply to every site's header I beleive).
jQuery(document).ready(function($){
$('.select-campus a').on('click', function(e) {
e.preventDefault();
$(this).toggleClass('active');
$('#select-a-campus').toggleClass('active');
});
});
(function (n) { n.fn.sticky = function (t) { var i = n.extend({}, {
topSpacing: 0, bottomSpacing: 0, debug: !1 }, t), r = function (t, r, u) { var o = u.offset(), e = n(window).scrollTop(), f = n(document).outerHeight() - i.bottomSpacing - i.topSpacing - t.outerHeight(); f <= 0 || t.height() <= 0 || (e > o.top - i.topSpacing && e < f ? (t.css("position") != "fixed" && (t.trigger("sticky-start"), t.css({ position: "fixed", top: i.topSpacing })), t.trigger("sticky-bottom-unreached")) : e > o.top - i.topSpacing && e >= f ? t.css("position") == "fixed" ? (t.trigger("sticky-bottom-reached"), t.css({ position: "absolute", top: f - r.offset().top + i.topSpacing + "px" })) : t.css("position") == "absolute" ? t.css({ top: f - r.offset().top + i.topSpacing + "px" }) : f > o.top && t.css({ position: "absolute", top: f - r.offset().top + i.topSpacing + "px" }) : ((t.css("position") == "fixed" || t.css("position") == "absolute") && t.trigger("sticky-end"), t.css({ position: "", top: "" }))) }; return this.each(function () { var t = n(this), u = t.offsetParent(), i; t.width(t.width()); i = n("<div class='sticky-holder' style='visibility: hidden;height:0;display:block'><\/div>").insertBefore(t); r(t, u, i); n(window).scroll(function () { r(t, u, i) }) }) } })(jQuery);
jQuery(document).ready(function ($) {
$('.vc_custom_1489943500023, .vc_custom_1489936456809').sticky( {topSpacing: 20,bottomSpacing:$("#page-section-40").outerHeight(true)} );
});
function myFunction() {
document.getElementById("myDropdown").classList.toggle("show");
}
// Close the dropdown menu if the user clicks outside of it
window.onclick = function(event) {
if (!event.target.matches('.dropbtn')) {
var dropdowns = document.getElementsByClassName("dropdown-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}
Please tell me if I can do anything else to help understanding. Sorry I don't know more. Any help is appreciated.
No error messages, however if you hover the mouse within a handful of pixels below the header, you are able to click some of the hidden campuses.
EDIT 1: here is the link to the html https://github.com/dtnieboer/sh-html/releases/tag/1.0
EDIT 2: Hey guys! An update- yes this job would be way too hard with my skill level. Going to get rid of the old code and rebuild a more simple button for now. Thanks for the help!
I am coding a website that lets you test typefaces and just like google fonts, the textarea in which you type should autogrow, when the user types in more text.
I tried this plugin by jaz303 and it works fine, if the font-size stays the same.
https://github.com/jaz303/jquery-grab-bag/blob/master/javascripts/jquery.autogrow-textarea.js
(function($) {
/**
* Auto-growing textareas; technique ripped from Facebook
*
*
* http://github.com/jaz303/jquery-grab-bag/tree/master/javascripts/jquery.autogrow-textarea.js
*/
$.fn.autogrow = function(options) {
return this.filter('textarea').each(function() {
var self = this;
var $self = $(self);
var minHeight = $self.height();
var noFlickerPad = $self.hasClass('autogrow-short') ? 0 : parseInt($self.css('lineHeight')) || 0;
var settings = $.extend({
preGrowCallback: null,
postGrowCallback: null
}, options);
var shadow = $('<div></div>').css({
position: 'absolute',
top: -10000,
left: -10000,
width: $self.width(),
fontSize: $self.css('fontSize'),
fontFamily: $self.css('fontFamily'),
fontWeight: $self.css('fontWeight'),
lineHeight: $self.css('lineHeight'),
resize: 'none',
'word-wrap': 'break-word'
}).appendTo(document.body);
var update = function(event) {
var times = function(string, number) {
for (var i = 0, r = ''; i < number; i++) r += string;
return r;
};
var val = self.value.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/\n$/, '<br/> ')
.replace(/\n/g, '<br/>')
.replace(/ {2,}/g, function(space) {
return times(' ', space.length - 1) + ' '
});
// Did enter get pressed? Resize in this keydown event so that the flicker doesn't occur.
if (event && event.data && event.data.event === 'keydown' && event.keyCode === 13) {
val += '<br />';
}
shadow.css('width', $self.width());
shadow.html(val + (noFlickerPad === 0 ? '...' : '')); // Append '...' to resize pre-emptively.
var newHeight = Math.max(shadow.height() + noFlickerPad, minHeight);
if (settings.preGrowCallback != null) {
newHeight = settings.preGrowCallback($self, shadow, newHeight, minHeight);
}
$self.height(newHeight);
if (settings.postGrowCallback != null) {
settings.postGrowCallback($self);
}
}
$self.change(update).keyup(update).keydown({
event: 'keydown'
}, update);
$(window).resize(update);
update();
});
};
However, I need the possibility for the user to change the font-size while testing and for some reason the autogrow doesn’t work anymore, as soon as I change the size.
Here is my Test jsFiddle:
http://jsfiddle.net/fquk6v3o/2/
The solution is to relaunch $("#autoGrowTextArea").autogrow(); when the slider value changes...
Sample code for doing this :
$("input[type='range']").change( function() {
$("#autoGrowTextArea").height("100px");
$("#autoGrowTextArea").autogrow();
});
New JSfiddle here : http://jsfiddle.net/newzy08/fquk6v3o/3/
You can achieve this with css as well using height and width in em units. Em means relative to the font-size of the element (2em means 2 times the size of the current font) w3schools.com/cssref/css_units.asp
I don't know if this works well together with the autogrowth plugin though.
$(document).ready(function(){
$("#font-small").click(function(){
$(".ta").css("font-size", "12px");
});
$("#font-big").click(function(){
$(".ta").css("font-size", "24px");
});
$("#font-huge").click(function(){
$(".ta").css("font-size", "36px");
});
});
.ta {
font-size: 12px;
height: 3em;
width: 10em;
resize: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
<textarea class="ta">test</textarea>
</div>
<div>
<button id="font-small">fontsmall</button>
<button id="font-big">fontbig</button>
<button id="font-huge">fonthuge</button>
</div>
I create a pop-up dialog box which lift up on left bottom while user scroll page.
You can see it live here- http://uposonghar.com/jobs/odesk/daniel/new/
My problem is it does not smoothly lift up first time, then it is ok. Anyone please suggest any idea to fix it. Need to make smoothly lift up.
My code
<div id="scrolltriggered" style="width: 310px; left: 10px; bottom: 10px;">
<div id="inscroll">
x<a href="http://www.google.com" target="_blank"><img src="images/buyersguide.png" alt="Free Resources" height="235" width="310">
</a>
</div>
</div>
<script type="text/javascript">
var stb = {
hascolsed: false,
cookieLife: 7,
triggerHeight: 30,
stbElement: ""
};
</script>
Javascript Code-
if (typeof stb === "undefined")
var stb = {};
jQuery(document).ready(function () {
jQuery("#closebox").click(function () {
jQuery('#scrolltriggered').stop(true, true).animate({ 'bottom':'-210px' }, 700, function () {
jQuery('#scrolltriggered').hide();
stb.hascolsed = true;
jQuery.cookie('nopopup', 'true', { expires: stb.cookieLife, path: '/' });
});
return false;
});
stb.windowheight = jQuery(window).height();
stb.totalheight = jQuery(document).height();
stb.boxOffset = '';
if (stb.stbElement != '') {
stb.boxOffset = jQuery(stb.stbElement).offset().top;
}
jQuery(window).resize(function () {
stb.windowheight = jQuery(window).height();
stb.totalheight = jQuery(document).height();
});
jQuery(window).scroll(function () {
stb.y = jQuery(window).scrollTop();
stb.boxHeight = jQuery('#scrolltriggered').outerHeight();
stb.scrolled = parseInt((stb.y + stb.windowheight) / stb.totalheight * 100);
if (stb.showBox(stb.scrolled, stb.triggerHeight, stb.y) && jQuery('#scrolltriggered').is(":hidden") && stb.hascolsed != true) {
jQuery('#scrolltriggered').show();
jQuery('#scrolltriggered').stop(true, true).animate({ 'bottom':'10px' }, 700, function () {
});
}
else if (!stb.showBox(stb.scrolled, stb.triggerHeight, stb.y) && jQuery('#scrolltriggered').is(":visible") && jQuery('#scrolltriggered:animated').length < 1) {
jQuery('#scrolltriggered').stop(true, true).animate({ 'bottom':-stb.boxHeight }, 700, function () {
jQuery('#scrolltriggered').hide();
});
}
});
jQuery('#stbContactForm').submit(function (e) {
e.preventDefault();
stb.data = jQuery('#stbContactForm').serialize();
jQuery.ajax({
url:stbAjax.ajaxurl,
data:{
action:'stb_form_process',
stbNonce:stbAjax.stbNonce,
data:stb.data
},
dataType:'html',
type:'post'
}).done(function (data) {
jQuery('#stbMsgArea').html(data).show('fast');
});
return false;
});
});
(function(stb_helpers) {
stb_helpers.showBox = function(scrolled, triggerHeight, y) {
if (stb.isMobile()) return false;
if (stb.stbElement == '') {
if (scrolled >= triggerHeight) {
return true;
}
}
else {
if (stb.boxOffset < (stb.windowheight + y)) {
return true;
}
}
return false;
};
stb_helpers.isMobile = function(){
if (navigator.userAgent.match(/Android/i)
|| navigator.userAgent.match(/webOS/i)
|| navigator.userAgent.match(/iPhone/i)
|| navigator.userAgent.match(/iPod/i)
|| navigator.userAgent.match(/BlackBerry/i)
) {
return true;
}
else return false;
}
})(stb);
i think you need css changes, copy paste the following in your aspx
<div style="width: 310px; left: 10px; bottom: -225px; display: none;" id="scrolltriggered">
Hope it Helps
All you need to do is add the following line to your document ready as the First line
$("#scrolltriggered").css({bottom: -235});
This will make sure that the popup is scrolled to the bottom by 235px. If you need it to scroll variably add the Elements height by using jquery selector.
See the Fiddle Here
I've been working on a little project and been trying to make my own debug console kinda thing, something that i can customize to what i need instead of using firebug.. so far i've got the two parts i need working but not togehter. I have a script that is going to report what the mouse enters and clicks on, it workded printing directly to the window DIV i have set up,, then yesterday ran across a JQuery console which i really liked, i cut out everything i didn't need and it works fine within its self, but not sure how to pass the data from my other method to that one,, i compiled the basic stuff to try to get it working... its probably something simple as ussual with me LOL and i could be confusing myself and making it harder then it needs to be
if anyone could help out that would be great
JsFiddle
after having a day off from work to sit down and actually mess with it for a while, reading Trip's comment LOL i decided to just go through the thing and clean it up as if it was working and took out a couple dozen un-needed functions and wrapped the main guts i was needing into one function that contained everything and made sure i wasn't using multiple variables to avoid conflict and some tweaking i got it to work.. so my conclusion from it there was to many functions leftover after i was deleting the stuff i didn't need. so heres the working code,, just incase someone is searching for something like this
JsFiddle
big thanks to Trip for point out all the Methods being used
function clock(){
var dayarray = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
var montharray = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
var suffix = "AM";
var currentTime = new Date();
var hours = currentTime.getHours();
var minutes = currentTime.getMinutes();
var mydate = new Date();
var year = mydate.getFullYear();
var day = mydate.getDay();
var month = mydate.getMonth();
var daym = mydate.getDate();
if(hours >= 12){
suffix = "PM";
hours = hours - 12;
}
if(hours == 0){
hours = 12;
}
if(minutes < 10){
minutes = "0" + minutes
}
if(daym<10){
daym="0"+daym
}
//alert(hours);
return [hours, minutes, suffix, month, day, year, dayarray, montharray];
}
$('#consolex').click(function() { loadConsole(); });
var xD;
function loadConsole(){
if (document.forms[0].console.checked) {
// if CHECKED than LOAD Console
if (window.twd_console) {
window.twd_console.toggle();
} else {
function init($) {
function HistoryManager() {
this.curr = -1;
this.entries = [];
};
HistoryManager.prototype = {
push: function(item) {
if (this.entries.length && this.entries[0] == item) return;
if (item.match(/^\s*$/)) return;
this.entries.unshift(item);
this.curr = -1;
},
scroll: function(direction) {
var moveTo = this.curr + (direction == 'prev' ? 1 : -1);
if (moveTo >= 0 && moveTo < this.entries.length) {
this.curr = moveTo;
return this.entries[this.curr];
} else if (moveTo == -1) {
this.curr = moveTo;
return '';
} else {
return null;
}
}
};
var toolbar = 'hello';
var context = {},
history = new HistoryManager(),
$drag = $('<div/>').css({
backgroundColor: '#e0e0e0',
border: '1px solid #a0a0a0',
fontSize: '11px',
fontFamily: 'sans-serif',
lineHeight: 1,
padding: '5px',
marginBottom: '7px',
cursor: 'pointer',
textAlign: 'right'
}).html(toolbar),
$log = $('<div/>').css({
fontSize: '11px',
fontFamily: 'monospace',
color: 'white',
marginBottom: '7px',
height: '155px',
overflow: 'auto',
border: '1px solid #a0a0a0',
padding: '5px',
textAlign: 'left'
}),
$dummy = $('<div/>');
xD = function append(text, act, tag, id, color) {
var aX = ' » ', // Bullet
bX = '['+ clock()[0]+':'+clock()[1]+':'+clock()[2]+'] ', // Timestamp
cX = ' ERROR ', //ERROR
dX = ' Location ', //Location of ERROR
eX = ' ID Location ', //ID Location
fX = ' Cause '; //Cause of ERROR
$log.append($('<div/>').css({
'color': color || 'black',
margin: 0,
padding: 0
}).text(aX).append(bX).append(text).append(act).append(tag).append(id));
$log[0].scrollTop = $log[0].scrollHeight;
};
$(document).mousemove(function(evt) {
if (dragging) $container.css({
left: evt.pageX - dragging[0],
top: evt.pageY - dragging[1]
});
});
var pos = ($.browser.msie && $.browser.version < 7) ? 'absolute' : 'fixed';
var $container = $('<div/>').css({
backgroundColor: 'white',
padding: '7px',
position: pos,
opacity: 0.9,
top: '10px',
right: '10px',
width: '550px',
height: '200px',
border: '1px solid #000',
zIndex: 99999
}).appendTo(document.body);
$container.append($drag).append($log);
//xD('jQuery initialised!', 'green');
//xD('(using jQuery version ' + $.fn.jquery + ')');
//xD('jQuery initialised!', 'green');
//xD('(using jQuery version ' + $.fn.jquery + ')');
//xD('jQuery initialised!', 'green');
//xD('(using jQuery version ' + $.fn.jquery + ')');
//xD('jQuery initialised!', 'green');
//xD('(using jQuery version ' + $.fn.jquery + ')');
window.twd_console = $container;
};
if (typeof jQuery == 'undefined' || !jQuery.fn.jquery.match(/^1\.7/)) {
var e = document.createElement('script'),
jq = null;
e.onload = function() {
jq = jQuery;
jQuery.noConflict(true);
init(jq);
};
e.setAttribute('type', 'text/javascript');
e.setAttribute('src', 'http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js');
document.body.appendChild(e);
} else {
init(jQuery);
}
}
} else if (!document.forms[0].console.checked) {
window.twd_console.hide();
}
mouse(true);
}
function mouse(bol){
var d = $("*", document.body);
if(bol){
// Cancel mousedown.
d.mousedown(function(event) {
var x = $(this).get(0),
y = x.tagName,
z = x.id;
switch (event.which) {
case 1:
//alert('Left mouse button click: ' + x.tagName);
xD(x.tagName, ' Left mouse button ',' '+ x.tagName+' ',' '+ x.id+' ', 'purple');
//xD(x.id, 'red');
break;
case 2:
//alert('Middle mouse button click: ' + x.tagName);
xD(x.tagName, ' Centermouse button ', x.tagName, x.id, 'purple');
break;
case 3:
//alert('Right mouse button click: ' + x.tagName);
xD(x.tagName, ' Right mouse button ', x.tagName, x.id, 'purple');
return null;
break;
default:
xD(x.tagName, ' mouse UNKNOWN ', x.tagName, x.id, 'purple');
}
});
// Transfer focus, if already open.
d.mouseenter(function(event) {
var x = $(this).get(0),
y = x.tagName,
z = x.id;
// $('#window').append('mouse entered' + x.tagName + '<br />');
try{
xD(y, ' Mouse Entered ', y, z, 'blue');
//xD(y, 'blue');
}catch(err){
alert(err);
}
});
}
};
This is my first time using JQuery in any of my projects.
I have implemented the superfish menu.
On some of my pages I have a horizontal scroll. I would like to make the menu float on the center of the page as the page is scrolled.
Also I need to make sure that the submenu on the far right hand side of the menu does not open up off the page. When I hover on the right most element it opens up half off the page.
Any ideas on how to fix these two things?
I'm perfectly willing to use a different Jquery menu if there is a better one that has these features built in...
Thanks!
javascrupt call in my page:
$(document).ready(function () {
$("ul.sf-menu").supersubs({
minWidth: 12, // minimum width of sub-menus in em units
maxWidth: 27, // maximum width of sub-menus in em units
extraWidth: 1 // extra width can ensure lines don't sometimes turn over
// due to slight rounding differences and font-family
}).superfish({ animation: { opacity: 'show', height: 'show' }, autoArrows: false }); // call supersubs first, then superfish, so that subs are
// not display:none when measuring. Call before initialising
// containing tabs for same reason.
I can post any more code that is needed, but there is quite a lot of code in the superfish files so i'm not sure what I should post.
I found this script and it works well, however when I scroll right the horizonal menu starts to stack so the menu items are side by side rather then vertical. I want to modify this to keep the menu horizonal...
<script type="text/javascript"><!--
var floatingMenuId = 'floatdiv';
var floatingMenu =
{
targetX: -1000,
targetY: 10,
hasInner: typeof (window.innerWidth) == 'number',
hasElement: document.documentElement
&& document.documentElement.clientWidth,
menu:
document.getElementById
? document.getElementById(floatingMenuId)
: document.all
? document.all[floatingMenuId]
: document.layers[floatingMenuId]
};
floatingMenu.move = function () {
if (document.layers) {
floatingMenu.menu.left = floatingMenu.nextX;
floatingMenu.menu.top = floatingMenu.nextY;
}
else {
floatingMenu.menu.style.left = floatingMenu.nextX + 'px';
floatingMenu.menu.style.top = floatingMenu.nextY + 'px';
}
}
floatingMenu.computeShifts = function () {
var de = document.documentElement;
floatingMenu.shiftX =
floatingMenu.hasInner
? pageXOffset
: floatingMenu.hasElement
? de.scrollLeft
: document.body.scrollLeft;
if (floatingMenu.targetX < 0) {
if (floatingMenu.hasElement && floatingMenu.hasInner) {
// Handle Opera 8 problems
floatingMenu.shiftX +=
de.clientWidth > window.innerWidth
? window.innerWidth
: de.clientWidth
}
else {
floatingMenu.shiftX +=
floatingMenu.hasElement
? de.clientWidth
: floatingMenu.hasInner
? window.innerWidth
: document.body.clientWidth;
}
}
floatingMenu.shiftY =
floatingMenu.hasInner
? pageYOffset
: floatingMenu.hasElement
? de.scrollTop
: document.body.scrollTop;
if (floatingMenu.targetY < 0) {
if (floatingMenu.hasElement && floatingMenu.hasInner) {
// Handle Opera 8 problems
floatingMenu.shiftY +=
de.clientHeight > window.innerHeight
? window.innerHeight
: de.clientHeight
}
else {
floatingMenu.shiftY +=
floatingMenu.hasElement
? document.documentElement.clientHeight
: floatingMenu.hasInner
? window.innerHeight
: document.body.clientHeight;
}
}
}
floatingMenu.doFloat = function () {
var stepX, stepY;
floatingMenu.computeShifts();
stepX = (floatingMenu.shiftX +
floatingMenu.targetX - floatingMenu.nextX) * .07;
if (Math.abs(stepX) < .5) {
stepX = floatingMenu.shiftX +
floatingMenu.targetX - floatingMenu.nextX;
}
stepY = (floatingMenu.shiftY +
floatingMenu.targetY - floatingMenu.nextY) * .07;
if (Math.abs(stepY) < .5) {
stepY = floatingMenu.shiftY +
floatingMenu.targetY - floatingMenu.nextY;
}
if (Math.abs(stepX) > 0 ||
Math.abs(stepY) > 0) {
floatingMenu.nextX += stepX;
floatingMenu.nextY += stepY;
floatingMenu.move();
}
setTimeout('floatingMenu.doFloat()', 20);
};
// addEvent designed by Aaron Moore
floatingMenu.addEvent = function (element, listener, handler) {
if (typeof element[listener] != 'function' ||
typeof element[listener + '_num'] == 'undefined') {
element[listener + '_num'] = 0;
if (typeof element[listener] == 'function') {
element[listener + 0] = element[listener];
element[listener + '_num']++;
}
element[listener] = function (e) {
var r = true;
e = (e) ? e : window.event;
for (var i = element[listener + '_num'] - 1; i >= 0; i--) {
if (element[listener + i](e) == false)
r = false;
}
return r;
}
}
//if handler is not already stored, assign it
for (var i = 0; i < element[listener + '_num']; i++)
if (element[listener + i] == handler)
return;
element[listener + element[listener + '_num']] = handler;
element[listener + '_num']++;
};
floatingMenu.init = function () {
floatingMenu.initSecondary();
floatingMenu.doFloat();
};
// Some browsers init scrollbars only after
// full document load.
floatingMenu.initSecondary = function () {
floatingMenu.computeShifts();
floatingMenu.nextX = floatingMenu.shiftX +
floatingMenu.targetX;
floatingMenu.nextY = floatingMenu.shiftY +
floatingMenu.targetY;
floatingMenu.move();
}
if (document.layers)
floatingMenu.addEvent(window, 'onload', floatingMenu.init);
else {
floatingMenu.init();
floatingMenu.addEvent(window, 'onload',
floatingMenu.initSecondary);
}
</script>
I'm not sure on how you mean centering, but if you mean horizontally centered:
Could you separate the main page (that horizontally overflows) and the menu into separate div's? e.g.
<div id="menu"><center><ul class="sf-menu">...</ul></center></div>
<div id="mainpage" style="overflow:auto;">Contents goes here</div>
(the <center> tag might have to be <div style="width:X;margin:0 auto;"> depending on how superfish works)
On the menu going over the page, sorry I'll have to defer to someone more knowable to answer that.