Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change fancybox close button title/tooltip

Is there a way to translate the tooltips in fancybox, e.g. the tooltip on the close button?

I have done this in the afterShow callback to change the value to Danish and seems to work.. or is there a better way to change it?

<script type="text/javascript">
      $(document).ready(function() {
        $("a.mapoverlay").fancybox({
          width : '90%',
          height : '90%',
          fixed: false,
          autoSize : false,
          autoCenter : true,
          afterLoad  :  function() {
        loadMap();
          },
          afterShow  :  function() {
        $("a.fancybox-close").attr("title", "Luk");
          }
        });
      });
</script>

Edit: This code seems to work fine.

I got a syntax error when writing this.. I think you missed something? SyntaxError: Unexpected token }

I saw this post here: https://github.com/fancyapps/fancyBox/issues/7

<script type="text/javascript">
      $(document).ready(function() {
        $("a.mapoverlay").fancybox({
          width : '90%',
          height : '90%',
          fixed: false,
          autoSize : false,
          autoCenter : true,
          afterLoad  :  function() {
        loadMap();
          },
          tpl: { 
        closeBtn: '<div title="Test" class="fancybox-item fancybox-close"></div>' 
          }
        });
      });
</script>
like image 576
bjarne_f Avatar asked Dec 26 '22 17:12

bjarne_f


1 Answers

You can use the .tpl option:

$(document).ready(function() {
  $("a.mapoverlay").fancybox({
    width : '90%',
    height : '90%',
    fixed: false,
    autoSize : false,
    autoCenter : true,
    afterLoad :  function() {
      loadMap();
    },
    tpl: {
        '<a title="Your title here!" class="fancybox-item fancybox-close" href="javascript:;"></a>'
    }
  });
});

EDIT : the correct format for the tpl option is

tpl : {
 closeBtn : '<a title="Close" class="fancybox-item fancybox-close" href="javascript:;"></a>'
}
like image 169
scumah Avatar answered Jan 14 '23 17:01

scumah