From fe920000dc1315e290eb66fa5f7eeedc96a60ad8 Mon Sep 17 00:00:00 2001 From: Gergely POLONKAI Date: Thu, 16 Aug 2012 10:01:48 +0200 Subject: [PATCH] Moved as much main page Javascripts to a separate file as possible Signed-off-by: Gergely POLONKAI --- .../Resources/public/js/kekrozsak.js | 92 +++++++++++++++++++ .../views/Default/main_template.html.twig | 87 +----------------- 2 files changed, 95 insertions(+), 84 deletions(-) create mode 100644 src/KekRozsak/FrontBundle/Resources/public/js/kekrozsak.js diff --git a/src/KekRozsak/FrontBundle/Resources/public/js/kekrozsak.js b/src/KekRozsak/FrontBundle/Resources/public/js/kekrozsak.js new file mode 100644 index 0000000..fa802b3 --- /dev/null +++ b/src/KekRozsak/FrontBundle/Resources/public/js/kekrozsak.js @@ -0,0 +1,92 @@ +function doPopup(title, content, url, w, h, callback) +{ + $('#popup-title').html(title); + $('#popup-content').html(content); + $('#popup-container').css('width', w + 'px'); + $('#popup-container').css('height', h + 'px'); + $('#popup-inside').css('width', (w - 8) + 'px'); + $('#popup-inside').css('height', (h - 8) + 'px'); + $('#popup-scrollable').css('width', (w - 8) + 'px'); + $('#popup-scrollable .viewport').css('width', (w - 28) + 'px'); + $('#popup-scrollable .viewport').css('height', (h - 54) + 'px'); + $('#popup-container').center(); + $('#popup-container').fadeIn(); + $.ajax({ + method: 'GET', + url: url + }).done(function(data) + { + $('#popup-content').html(data); + $('#popup-scrollable').tinyscrollbar(); + $('.userdata').cluetip(); + + if (callback != null) { + callback(); + } + }).error(function() + { + $('#popup-content').html('Nem sikerült betölteni a könyv adatait.'); + }); +} + +function resizeBoxes() +{ + bottomLineTop = $('#bottom-line').position().top; + contentOutlineTop = $('#content-outline').position().top; + contentHeight = $('#content-outline').outerHeight(); + newsHeight = $('#hirek').outerHeight(); + minHeight = bottomLineTop - contentOutlineTop; + // TODO: Resize content to its original small size if news is hidden + + height = Math.max(contentHeight, newsHeight, minHeight); + if ($('#content-outline').outerHeight() < height) { + $('#content-outline').css('height', height + 'px'); + } + if ($('#hirek').is(':visible') && ($('#hirek').outerHeight() < height)) { + $('#hirek').css('height', height + 'px'); + } +} + +jQuery.fn.center = function() { + this.css('top', Math.max(0, (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop()) + 'px'); + this.css('left', Math.max(0, (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft()) + 'px'); + return this; +}; + +$(document).ready(function() { + // Resize news and content boxes to correctly fill the page + resizeBoxes(); + + $('#popup-close').click(function() { $('#popup-container').fadeOut(); }); + $('#popup-scrollable').tinyscrollbar(); + + $('#news-button').click(function() + { + $('#news-button').hide(); + $('#content-outline').css('width', '740px'); + $('#hirek').show(); + $('#news-list').html('Betöltés...'); + + $.ajax({ + method: 'GET', + url: Routing.generate('KekRozsakFrontBundle_newsSideList') + }).done(function(data) + { + $('#news-list').html(data); + resizeBoxes(); + }).error(function() + { + $('#news-list').html('Nem sikerült betölteni a híreket!'); + resizeBoxes(); + }); + }); + + $('#news-close-button').click(function() + { + $('#news-content').html(''); + $('#hirek').hide(); + $('#content-outline').css('width', '960px'); + $('#news-button').show(); + resizeBoxes(); + }); +}); diff --git a/src/KekRozsak/FrontBundle/Resources/views/Default/main_template.html.twig b/src/KekRozsak/FrontBundle/Resources/views/Default/main_template.html.twig index 9de3460..067d42d 100644 --- a/src/KekRozsak/FrontBundle/Resources/views/Default/main_template.html.twig +++ b/src/KekRozsak/FrontBundle/Resources/views/Default/main_template.html.twig @@ -16,6 +16,9 @@ +{% javascripts 'bundles/kekrozsakfront/js/*' output='js/kekrozsak.js' %} + +{% endjavascripts %} {% block additional_js %}{% endblock %} @@ -134,90 +137,6 @@ } }); {% endif %} - jQuery.fn.center = function() { - this.css('top', Math.max(0, (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop()) + 'px'); - this.css('left', Math.max(0, (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft()) + 'px'); - return this; - }; - - $('#popup-close').click(function() { $('#popup-container').fadeOut(); }); - $('#popup-scrollable').tinyscrollbar(); - function doPopup(title, content, url, w, h, callback) - { - $('#popup-title').html(title); - $('#popup-content').html(content); - $('#popup-container').css('width', w + 'px'); - $('#popup-container').css('height', h + 'px'); - $('#popup-inside').css('width', (w - 8) + 'px'); - $('#popup-inside').css('height', (h - 8) + 'px'); - $('#popup-scrollable').css('width', (w - 8) + 'px'); - $('#popup-scrollable .viewport').css('width', (w - 28) + 'px'); - $('#popup-scrollable .viewport').css('height', (h - 54) + 'px'); - $('#popup-container').center(); - $('#popup-container').fadeIn(); - $.ajax({ - method: 'GET', - url: url - }).done(function(data) { - $('#popup-content').html(data); - $('#popup-scrollable').tinyscrollbar(); - $('.userdata').cluetip(); - if (callback != null) { - callback(); - } - }).error(function() { - $('#popup-content').html('Nem sikerült betölteni a könyv adatait.'); - }); - } - - function resizeBoxes() - { - bottomLineTop = $('#bottom-line').position().top; - contentOutlineTop = $('#content-outline').position().top; - contentHeight = $('#content-outline').outerHeight(); - newsHeight = $('#hirek').outerHeight(); - minHeight = bottomLineTop - contentOutlineTop; - // TODO: Resize content to its original small size if news is - // hidden - - height = Math.max(contentHeight, newsHeight, minHeight); - if ($('#content-outline').outerHeight() < height) { - $('#content-outline').css('height', height + 'px'); - } - if ($('#hirek').is(':visible') && ($('#hirek').outerHeight() < height)) { - $('#hirek').css('height', height + 'px'); - } - } - - $(document).ready(function() { - resizeBoxes(); - - $('#news-button').click(function() { - $('#news-button').hide(); - $('#content-outline').css('width', '740px'); - $('#hirek').show(); - $('#news-list').html('Betöltés...'); - - $.ajax({ - method: 'GET', - url: Routing.generate('KekRozsakFrontBundle_newsSideList') - }).done(function(data) { - $('#news-list').html(data); - resizeBoxes(); - }).error(function() { - $('#news-list').html('Nem sikerült betölteni a híreket!'); - resizeBoxes(); - }); - }); - - $('#news-close-button').click(function() { - $('#news-content').html(''); - $('#hirek').hide(); - $('#content-outline').css('width', '960px'); - $('#news-button').show(); - resizeBoxes(); - }); - }); {% block bottomscripts %}{% endblock %}