Dźwiek na SB

Założony przez  qiu123.

Witam, mam mały problem z przyciskiem od wyłączania i włączania dźwięku na Shoutbox.
kod na Przycisk
<span style="float:left;"><strong>Dzwięk: <input id="odtwarzaj_dzwiek" type="checkbox"></strong></span>
Nie działa z tym id :/ Jakie ID tam dodać
Kod do dźwięku: http://wklej.to/oD0Sn
Jeśli zły dział proszę o przeniesienie :)
Łukasz napisał 14.02.2017, 20:35:
Kody podajemy w tagach [code] lub [php], poprawia to czytelność posta.
https://webboard.pl/thread-59625.html
Nie zrozumiałeś pytania :p
Chodzi żeby przez przycisk wyłączać i włączać dźwięk
https://webboard.pl/thread-62489.html
Cytat:w pół dnia stałeś się lepszym pytonistą niż kawenanowo kiedykolwiek programisto :3 ~ Riess 13.11.2018 16:28
Cytat:ale z tą nazwą to fyeem ma racje  ~ Divir 29.07.2019 16:08

$(document).ready(function() {
   // Get each div
   var url = window.location.search;

   if (url == '?tid=2137&pid=24269') {
       $('.post_body:eq( 0 )').each(function() {
           // Get the content
           var str = $(this).html();
           // Set the regex string
           var regex = /(https?:\/\/([-\w\.]+)+(:\d+)?(\/([\w\/_\.]*(\?\S+)?)?)?)/ig
               // Replace plain text links by hyperlinks
           var replaced_text = str.replace(regex, "<a href='$1' target='_blank'>$1</a>");
           // Echo link
           $(this).html(replaced_text);
       });
   }
});


$(function() {
   /* ~~ Enable and configure plugin for new titles ~~ */
   $('a').tipsy({
       fade: true,
       gravity: 'n',
       html: true,
       delayOut: 250
   });
   $('i').tipsy({
       fade: true,
       gravity: 'n'
   });
   $('span').tipsy({
       fade: true,
       gravity: 's'
   });
   $('label').tipsy({
       fade: true,
       gravity: 's'
   });

   /* ~~ Choose your own background ~~ */
   if ($.cookie('background')) {
       $("body").css("backgroundImage", "url(" + "images/" + $.cookie("background") + ".jpg)");
   };
   $(".bg_style").click(function() {
       $(".bg_preview").slideToggle('fast');
       return false;
   });
   $(".bg_preview a").click(function() {
       var bg_id = $(this).attr("id");
       $("body").css("backgroundImage", "url(" + "images/" + bg_id + ".jpg)");
       $.cookie('background', bg_id, {
           expires: 365,
           path: '/'
       });
   });

   /* ~~ Image MyCode - made for shoutbox, however, it works anywhere else as well  ~~ */
   $("body").on("click", ".img-spoiler", function() {
       $(this).children("img").toggle(250);
   });

   /* ~~ Tabs in members' profiles ~~ */
   $('.tab-container .tab').click(function() {

       var tabVal = $(this).attr('value');
       var panel = $('.panel' + ' #' + tabVal);
       var tabContent = $('.tab-content' + '#' + tabVal);


       if (tabContent.is(':hidden')) {
           tabContent.slideDown('200');
       } else {
           tabContent.slideUp('200');
       }

   });

   /* ~~ Show modal with emoticons (the one in shoutbox) ~~*/
   $('.show-modalEx').click(function(event) {
       event.preventDefault();
       $('.modalEx').css("display", "block");
   });
   $('.close-modalEx').click(function(event) {
       event.preventDefault();
       $('.modalEx').css("display", "none");
   })
   $('.smilie_dvz').click(function() {
       var smilie = $(this).attr("alt"),
           inputValue = $('#dvz_input').val();
       $('#dvz_input').val(inputValue + smilie);
   });

}); // <-- document ready end


/*
************ START *************
*** ~~ dvz_shoutbox stuff ~~ ***
********************************
*/

/* ~~ Play sound on new message ~~ */
/* ~~ Change website title on new message (just when window is inactive) ~~ */
var defaultTitle = $(document).find("title").text(),
   s = 0,
   sT = null;

function changeTitle() {
   if (document.hasFocus()) {
       document.title = defaultTitle;
   } else {
       s++;
       if (s > 2) {
           s = 1;
       }
       if (s == 1) {
           document.title = 'Nowa wiadomość w SB';
       }
       if (s == 2) {
           document.title = defaultTitle;
       }
       sT = setTimeout("changeTitle()", 2500);
   }
}


$(function() {
   var url = window.location.pathname;
   if (url == '/forum/index.php') {

       if ($.cookie('dvz_play') == 1) {
           $("input#sound_dvz").prop("checked", true);
       }

       $(document).on('change', '#sound_dvz', function() {
           if ($('#sound_dvz').is(':checked')) {
               $.cookie('dvz_play', '1', {
                   expires: 365,
                   path: '/'
               });
           } else {
               $.cookie('dvz_play', '0', {
                   expires: 365,
                   path: '/'
               });
           }
       });

       if ($.cookie('dvz_play') == 1) {
           dvz_shoutbox.callbacks['update'].push(function() {
               if ($('#shoutbox .entry.new').length) {
                   var audio = new Audio(rootpath + '/images/dvz_shoutbox.mp3');
                   audio.volume = 0.2;
                   audio.play();
               }
           });
       }

       //Check if window is inactive. If so, change the title
       $(window).blur(function() {
           dvz_shoutbox.callbacks['update'].push(function() {
               if ($('#shoutbox .entry.new').length) {
                   changeTitle();
               }
           });
       });
   }
});


/* ~~ Open Shoutbox' panel ~~ */
$('#tog_shoutbox_panel').click(function() {
   var sbPanel = $('#shoutbox_panel');

   if (sbPanel.css('display') == 'none') {
       sbPanel.slideDown();
   } else {
       sbPanel.slideUp();
   }
});
/*
************* END **************
*** ~~ dvz_shoutbox stuff ~~ ***
********************************
*/

/*
************ START ************
**** ~~ sidebar (aside) ~~ ****
*******************************
*/
var sidebox = $('aside'),
   toggleBox = $('#toggle-aside i'),
   forumBox = $("#forum-box");

function asideHidden() {
   sidebox.hide();
   toggleBox.toggleClass('fa-arrow-right fa-arrow-left');
   forumBox.css({
       width: "100%"
   });
   $.cookie('aside', '0', {
       expires: 365,
       path: '/'
   });
}

function asideVisible() {
   sidebox.fadeIn(250);
   toggleBox.toggleClass('fa-arrow-left fa-arrow-right');
   forumBox.css({
       width: "75%"
   });
   $.removeCookie('aside', {
       path: '/'
   });
}

if ($.cookie('aside')) {
   asideHidden();
};

$(function() {
   $("#toggle-aside").click(function() {
       if (sidebox.is(':hidden')) {
           asideVisible();
       } else {
           asideHidden();
       }
   });
});

<label original-title="Wymaga odświeżenia strony">
                Sound:
                <input type="checkbox" id="sound_dvz" name="sound">
            </label>

Możesz sobie wyciągnać z tego (szukaj dvz_sound).
Po zaznaczeniu boxa musisz odświeżyć stronę, aby działało poprawnie.
Kodowanie, edycja i tworzenie styli, for, stron, poszczególnych elementów - polecane szczególnie dla osób, które nie potrafią sobie poradzić z problemami.
Divir zrobiłem plik w folderze jscripts zrobiłem nowy plik o nazwie dvz_sound i Dodałem kod
$(document).ready(function() {
   // Get each div
   var url = window.location.search;

   if (url == '?tid=2137&pid=24269') {
       $('.post_body:eq( 0 )').each(function() {
           // Get the content
           var str = $(this).html();
           // Set the regex string
           var regex = /(https?:\/\/([-\w\.]+)+(:\d+)?(\/([\w\/_\.]*(\?\S+)?)?)?)/ig
               // Replace plain text links by hyperlinks
           var replaced_text = str.replace(regex, "<a href='$1' target='_blank'>$1</a>");
           // Echo link
           $(this).html(replaced_text);
       });
   }
});


$(function() {
   /* ~~ Enable and configure plugin for new titles ~~ */
   $('a').tipsy({
       fade: true,
       gravity: 'n',
       html: true,
       delayOut: 250
   });
   $('i').tipsy({
       fade: true,
       gravity: 'n'
   });
   $('span').tipsy({
       fade: true,
       gravity: 's'
   });
   $('label').tipsy({
       fade: true,
       gravity: 's'
   });

   /* ~~ Choose your own background ~~ */
   if ($.cookie('background')) {
       $("body").css("backgroundImage", "url(" + "images/" + $.cookie("background") + ".jpg)");
   };
   $(".bg_style").click(function() {
       $(".bg_preview").slideToggle('fast');
       return false;
   });
   $(".bg_preview a").click(function() {
       var bg_id = $(this).attr("id");
       $("body").css("backgroundImage", "url(" + "images/" + bg_id + ".jpg)");
       $.cookie('background', bg_id, {
           expires: 365,
           path: '/'
       });
   });

   /* ~~ Image MyCode - made for shoutbox, however, it works anywhere else as well  ~~ */
   $("body").on("click", ".img-spoiler", function() {
       $(this).children("img").toggle(250);
   });

   /* ~~ Tabs in members' profiles ~~ */
   $('.tab-container .tab').click(function() {

       var tabVal = $(this).attr('value');
       var panel = $('.panel' + ' #' + tabVal);
       var tabContent = $('.tab-content' + '#' + tabVal);


       if (tabContent.is(':hidden')) {
           tabContent.slideDown('200');
       } else {
           tabContent.slideUp('200');
       }

   });

   /* ~~ Show modal with emoticons (the one in shoutbox) ~~*/
   $('.show-modalEx').click(function(event) {
       event.preventDefault();
       $('.modalEx').css("display", "block");
   });
   $('.close-modalEx').click(function(event) {
       event.preventDefault();
       $('.modalEx').css("display", "none");
   })
   $('.smilie_dvz').click(function() {
       var smilie = $(this).attr("alt"),
           inputValue = $('#dvz_input').val();
       $('#dvz_input').val(inputValue + smilie);
   });

}); // <-- document ready end


/*
************ START *************
*** ~~ dvz_shoutbox stuff ~~ ***
********************************
*/

/* ~~ Play sound on new message ~~ */
/* ~~ Change website title on new message (just when window is inactive) ~~ */
var defaultTitle = $(document).find("title").text(),
   s = 0,
   sT = null;

function changeTitle() {
   if (document.hasFocus()) {
       document.title = defaultTitle;
   } else {
       s++;
       if (s > 2) {
           s = 1;
       }
       if (s == 1) {
           document.title = 'Nowa wiadomość w SB';
       }
       if (s == 2) {
           document.title = defaultTitle;
       }
       sT = setTimeout("changeTitle()", 2500);
   }
}


$(function() {
   var url = window.location.pathname;
   if (url == '/forum/index.php') {

       if ($.cookie('dvz_play') == 1) {
           $("input#sound_dvz").prop("checked", true);
       }

       $(document).on('change', '#sound_dvz', function() {
           if ($('#sound_dvz').is(':checked')) {
               $.cookie('dvz_play', '1', {
                   expires: 365,
                   path: '/'
               });
           } else {
               $.cookie('dvz_play', '0', {
                   expires: 365,
                   path: '/'
               });
           }
       });

       if ($.cookie('dvz_play') == 1) {
           dvz_shoutbox.callbacks['update'].push(function() {
               if ($('#shoutbox .entry.new').length) {
                   var audio = new Audio(rootpath + '/images/dvz_shoutbox.mp3');
                   audio.volume = 0.2;
                   audio.play();
               }
           });
       }

       //Check if window is inactive. If so, change the title
       $(window).blur(function() {
           dvz_shoutbox.callbacks['update'].push(function() {
               if ($('#shoutbox .entry.new').length) {
                   changeTitle();
               }
           });
       });
   }
});


/* ~~ Open Shoutbox' panel ~~ */
$('#tog_shoutbox_panel').click(function() {
   var sbPanel = $('#shoutbox_panel');

   if (sbPanel.css('display') == 'none') {
       sbPanel.slideDown();
   } else {
       sbPanel.slideUp();
   }
});
/*
************* END **************
*** ~~ dvz_shoutbox stuff ~~ ***
********************************
*/

/*
************ START ************
**** ~~ sidebar (aside) ~~ ****
*******************************
*/
var sidebox = $('aside'),
   toggleBox = $('#toggle-aside i'),
   forumBox = $("#forum-box");

function asideHidden() {
   sidebox.hide();
   toggleBox.toggleClass('fa-arrow-right fa-arrow-left');
   forumBox.css({
       width: "100%"
   });
   $.cookie('aside', '0', {
       expires: 365,
       path: '/'
   });
}

function asideVisible() {
   sidebox.fadeIn(250);
   toggleBox.toggleClass('fa-arrow-left fa-arrow-right');
   forumBox.css({
       width: "75%"
   });
   $.removeCookie('aside', {
       path: '/'
   });
}

if ($.cookie('aside')) {
   asideHidden();
};

$(function() {
   $("#toggle-aside").click(function() {
       if (sidebox.is(':hidden')) {
           asideVisible();
       } else {
           asideHidden();
       }
   });
});
A do szablonu dvz_shoubox dodałem to
<span style="float:left;"><label original-title="Wymaga odświeżenia strony">
                <strong>Dźwięk:</strong>
                    <input type="checkbox" id="sound_dvz" name="sound"></label></span>
I dalej nie działa :P
Nie widzę gdzie dołączasz ten plik i do odtworzenia tego jest potrzebne konto testowe. Poza tym nie masz dołączać tego całego kodu, a wyciągnąć sobie z niego fragment odpowiedzialny za dźwięk sb.


$(function() {
var url = window.location.pathname;
if (url == '/forum/index.php') {

if ($.cookie('dvz_play') == 1) {
$("input#sound_dvz").prop("checked", true);
}

$(document).on('change', '#sound_dvz', function() {
if ($('#sound_dvz').is(':checked')) {
$.cookie('dvz_play', '1', {
expires: 365,
path: '/'
});
} else {
$.cookie('dvz_play', '0', {
expires: 365,
path: '/'
});
}
});

if ($.cookie('dvz_play') == 1) {
dvz_shoutbox.callbacks['update'].push(function() {
if ($('#shoutbox .entry.new').length) {
var audio = new Audio(rootpath + '/images/dvz_shoutbox.mp3');
audio.volume = 0.2;
audio.play();
}
});
}
});

Poza tym musisz zmienić zmienną url, aby pasowała do twojego forum. Dla ciebie będzie odpowiendie samo /index.php.
Kodowanie, edycja i tworzenie styli, for, stron, poszczególnych elementów - polecane szczególnie dla osób, które nie potrafią sobie poradzić z problemami.



Użytkownicy przeglądający ten wątek:

1 gości