Commit 4a6a65c779a4de11f79fe871193188df6fd3f833

Authored by Fabio Teixeira
Committed by Gabriela Navarro
1 parent 0b5a684a

Execute download block javascript only when needed

lib/software_communities_plugin.rb
... ... @@ -126,9 +126,9 @@ class SoftwareCommunitiesPlugin < Noosfero::Plugin
126 126 views/create-institution.js
127 127 views/complete-registration.js
128 128 views/search-software-catalog.js
  129 + blocks/software-download.js
129 130 initializer.js
130 131 app.js
131   - mpog-download-block.js
132 132 )
133 133 end
134 134  
... ...
public/blocks/software-download.js 0 → 100644
... ... @@ -0,0 +1,46 @@
  1 +modulejs.define('SoftwareDownload', ['jquery'], function($) {
  2 + 'use strict';
  3 +
  4 + function add_new_link(){
  5 + var newDownload = $(window.download_list_template);
  6 + newDownload.attr('data-counter-id', 1);
  7 + $("#droppable-list-downloads").append(newDownload);
  8 + }
  9 +
  10 +
  11 + function delete_link(add_element){
  12 + var deleteDownload = $(add_element).parent().parent().parent();
  13 + deleteDownload.remove();
  14 + }
  15 +
  16 +
  17 + function get_download_list_template() {
  18 + var blockTemplate = sessionStorage.getItem('download_list_block_template');
  19 +
  20 + if(blockTemplate && blockTemplate.length > 0) {
  21 + window.download_list_template = blockTemplate;
  22 + } else {
  23 + $.get('/plugin/software_communities/get_block_template', function(response) {
  24 + window.download_list_template = response;
  25 + sessionStorage.setItem('download_list_block_template', response);
  26 + });
  27 + }
  28 + }
  29 +
  30 +
  31 + return {
  32 + isCurrentPage: function() {
  33 + return $('.download-block').length !== 0;
  34 + },
  35 +
  36 +
  37 + init: function() {
  38 + window.add_new_link = add_new_link;
  39 + window.delete_link = delete_link;
  40 +
  41 + if( window.download_list_template === undefined ) {
  42 + get_download_list_template();
  43 + }
  44 + }
  45 + }
  46 +});
... ...
public/initializer.js
1   -var dependencies = [
2   - 'ControlPanel',
3   - 'EditSoftware',
4   - 'NewSoftware',
5   - 'UserEditProfile',
6   - 'CreateInstitution',
7   - 'CompleteRegistration',
8   - 'SearchSoftwareCatalog'
9   -];
  1 +(function() {
  2 + 'use strict';
10 3  
  4 + var dependencies = [
  5 + 'ControlPanel',
  6 + 'EditSoftware',
  7 + 'NewSoftware',
  8 + 'UserEditProfile',
  9 + 'CreateInstitution',
  10 + 'CompleteRegistration',
  11 + 'SearchSoftwareCatalog',
  12 + 'SoftwareDownload'
  13 + ];
11 14  
12   -modulejs.define('Initializer', dependencies, function() {
13   - 'use strict';
14 15  
15   - var __dependencies = arguments;
  16 + modulejs.define('Initializer', dependencies, function() {
  17 + var __dependencies = arguments;
16 18  
17 19  
18   - function call_dependency(dependency) {
19   - if( dependency.isCurrentPage() ) {
20   - dependency.init();
  20 + function call_dependency(dependency) {
  21 + if( dependency.isCurrentPage() ) {
  22 + dependency.init();
  23 + }
21 24 }
22   - }
23 25  
24 26  
25   - return {
26   - init: function() {
27   - for(var i=0, len = __dependencies.length; i < len; i++) {
28   - call_dependency(__dependencies[i]);
  27 + return {
  28 + init: function() {
  29 + for(var i=0, len = __dependencies.length; i < len; i++) {
  30 + call_dependency(__dependencies[i]);
  31 + }
29 32 }
30   - }
31   - };
32   -});
  33 + };
  34 + });
  35 +})();
... ...
public/mpog-download-block.js
... ... @@ -1,38 +0,0 @@
1   -(function($) {
2   - 'use strict';
3   -
4   - function add_new_link(){
5   - var newDownload = $(window.download_list_template);
6   - newDownload.attr('data-counter-id', 1);
7   - $("#droppable-list-downloads").append(newDownload);
8   - }
9   -
10   -
11   - function delete_link(add_element){
12   - var deleteDownload = $(add_element).parent().parent().parent();
13   - deleteDownload.remove();
14   - }
15   -
16   -
17   - function get_download_list_template() {
18   - var blockTemplate = sessionStorage.getItem('download_list_block_template');
19   -
20   - if(blockTemplate && blockTemplate.length > 0) {
21   - window.download_list_template = blockTemplate;
22   - } else {
23   - $.get('/plugin/software_communities/get_block_template', function(response) {
24   - window.download_list_template = response;
25   - sessionStorage.setItem('download_list_block_template', response);
26   - });
27   - }
28   - }
29   -
30   - $(document).ready(function() {
31   - window.add_new_link = add_new_link;
32   - window.delete_link = delete_link;
33   -
34   - if( window.download_list_template === undefined ) {
35   - get_download_list_template();
36   - }
37   - });
38   -})(jQuery);