Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transfer js code in archive.html into separate .js file #1182

Closed
5 tasks
segun-codes opened this issue Oct 18, 2022 · 10 comments · Fixed by #1282
Closed
5 tasks

Transfer js code in archive.html into separate .js file #1182

segun-codes opened this issue Oct 18, 2022 · 10 comments · Fixed by #1282

Comments

@segun-codes
Copy link
Collaborator

segun-codes commented Oct 18, 2022

Hi, this is a first-timers-only issue. This means we've worked to make it more legible to folks who either haven't contributed to our codebase before, or even folks who haven't contributed to open source before.

If that's you, we're interested in helping you take the first step and can answer questions and help you out as you do. Note that we're especially interested in contributions from people from underrepresented groups in free and open-source software!

We know that the process of creating a pull request is one of the biggest barriers for new contributors. This issue is for you 💝

If you have contributed before, consider leaving this one for someone new, and looking through our general help wanted issues. Thanks!

🤔 What you will need to know.

Nothing. This issue is meant to welcome you to Open Source :) We are happy to walk you through the process.

📋 Step by Step

  • 🙋 Claim this issue: Claim the issue by commenting. If someone else has claimed it, ask if they've opened a pull request already and if they're stuck -- maybe you can help them solve a problem or move it along!
💡 Learn how to claim 🙋

Claiming an issue

Unless the issue is marked as reserved for someone, you can just say "I'd like to try this!" and then you've claimed it - no need to wait for someone to assign it to you. Just be sure you link your pull request (PR) to this issue so we can see where your solution is.

And open one early if possible - even before you've completed it with additional commits - and others can help you figure out any issues you may face.

  • 📝 Update the file archive.html in the https://github.com/publiclab/Leaflet.DistortableImage repository (press the little pen Icon) and edit the line as shown below.

See this page for some help in taking your first steps!

Below is a "diff" showing in red (and a -) which lines to remove, and in green (and a +) which lines to add:
In file archive.html insert the code <script src="./js/archive.js" defer></script> in the header section, then apply the diff below.

- <script>
-   let map;
-   let welcomeModal = document.getElementById('welcomeModal');
-   let sidebar = document.getElementById('offcanvasRight');
-   let form = document.getElementById('form');
-   let input = document.getElementById('input');
-   let responseText = document.getElementById('response');
-   let imageContainer = document.getElementById('imgContainer');
-
-   const setupMap = () => {
-     map = L.map('map').setView([51.505, -0.09], 13);
-
-     map.attributionControl.setPosition('bottomleft');
-
-     map.addGoogleMutant();
-
-     map.whenReady(() => {
-       new bootstrap.Modal(welcomeModal).show();
-     });
-   };
-
-   const setupCollection = () => {
-     map.imgGroup = L.distortableCollection().addTo(map);
-   };
-
-   setupMap();
-   setupCollection();
-
-   form.addEventListener('submit', (event) => {
-     event.preventDefault();
-     const url = input.value.replace('details', 'metadata');
-     let fetchedFrom
-     axios.get(url)
-        .then((response) => {
-         if (response.data.files && response.data.files.length != 0) {
-           let imageCount = 0;
-           response.data.files.forEach(file => {
-             if (file.format === 'PNG' || file.format === 'JPEG'){
-               let imageRow = document.createElement('div');
-               let image = new Image(150, 150);
-               let placeButton = document.createElement('a');
-               fetchedFrom = document.createElement('p');
-               fetchedFromUrl = document.createElement('a');
-               fetchedFromUrl.setAttribute('href', input.value);
-               fetchedFromUrl.setAttribute('target', '_blank');
-               fetchedFromUrl.innerHTML = 'this Internet Archive Collection';
-               fetchedFrom.appendChild(fetchedFromUrl)
-
-               placeButton.classList.add('btn', 'btn-sm', 'btn-outline-secondary', 'place-button');
-               placeButton.innerHTML = 'Place on map ';
-
-               placeButton.addEventListener('click', (event) => {
-                 if(!placeButton.getElementsByClassName('fa-spinner')[0]){
-                   const spinner = document.createElement('i')
-                   spinner.setAttribute('class', "fa fa-spinner fa-spin")
-                   spinner.setAttribute('font-family', 'font awesome')
-
-                   placeButton.appendChild(spinner)
-
-                   let imageURL = event.target.previousElementSibling.src;
-                   let image = L.distortableImageOverlay(imageURL);
-                   map.imgGroup.addLayer(image)
-
-                   image.addEventListener('load', () => {
-                     placeButton.removeChild(spinner)
-                   })
-                 }
-               })
-
-               image.src = `${url.replace('metadata', 'download')}/${file.name}`;
-
-               imageRow.classList.add('d-flex', 'justify-content-between', 'align-items-center', 'mb-4', 'pe-5');
-               imageRow.append(image, placeButton);
-
-               imageContainer.appendChild(imageRow);
-               imageCount++;
-             }
-           });
-           responseText.innerHTML = imageCount ? `${imageCount} image(s) fetched successfully from ${fetchedFrom.innerHTML}.` : 'No images found in the link provided...'
-         } else {
-           responseText.innerHTML = 'No images found in the link provided...'
-         }
-       })
-       .catch((error) => {
-          responseText.innerHTML = 'Uh-oh! Something\'s not right with the link provided!'
-       })
-       .finally(() => {
-         bootstrap.Modal.getInstance(welcomeModal).hide();
-       });
-   });
-
-   welcomeModal.addEventListener('hidden.bs.modal', (event) => {
-     new bootstrap.Offcanvas(sidebar).show();
-   });
-
- </script>

Create file archive.js in folder /examples/js, then apply the diff below. That is, you will simply copy the code below and past same in the newly created file.

+     let map;
+     let welcomeModal = document.getElementById('welcomeModal');
+     let sidebar = document.getElementById('offcanvasRight');
+     let form = document.getElementById('form');
+     let input = document.getElementById('input');
+     let responseText = document.getElementById('response');
+     let imageContainer = document.getElementById('imgContainer');
+
+     const setupMap = () => {
+       map = L.map('map').setView([51.505, -0.09], 13);
+
+       map.attributionControl.setPosition('bottomleft');
+
+       map.addGoogleMutant();
+
+       map.whenReady(() => {
+         new bootstrap.Modal(welcomeModal).show();
+       });
+     };
+
+     const setupCollection = () => {
+       map.imgGroup = L.distortableCollection().addTo(map);
+     };
+
+     setupMap();
+     setupCollection();
+
+     form.addEventListener('submit', (event) => {
+       event.preventDefault();
+       const url = input.value.replace('details', 'metadata');
+       let fetchedFrom
+       axios.get(url)
+          .then((response) => {
+           if (response.data.files && response.data.files.length != 0) {
+             let imageCount = 0;
+             response.data.files.forEach(file => {
+               if (file.format === 'PNG' || file.format === 'JPEG'){
+                 let imageRow = document.createElement('div');
+                 let image = new Image(150, 150);
+                 let placeButton = document.createElement('a');
+                 fetchedFrom = document.createElement('p');
+                 fetchedFromUrl = document.createElement('a');
+                 fetchedFromUrl.setAttribute('href', input.value);
+                 fetchedFromUrl.setAttribute('target', '_blank');
+                 fetchedFromUrl.innerHTML = 'this Internet Archive Collection';
+                 fetchedFrom.appendChild(fetchedFromUrl)
+
+                 placeButton.classList.add('btn', 'btn-sm', 'btn-outline-secondary', 'place-button');
+                 placeButton.innerHTML = 'Place on map ';
+
+                 placeButton.addEventListener('click', (event) => {
+                   if(!placeButton.getElementsByClassName('fa-spinner')[0]){
+                     const spinner = document.createElement('i')
+                     spinner.setAttribute('class', "fa fa-spinner fa-spin")
+                     spinner.setAttribute('font-family', 'font awesome')
+
+                     placeButton.appendChild(spinner)
+
+                     let imageURL = event.target.previousElementSibling.src;
+                     let image = L.distortableImageOverlay(imageURL);
+                     map.imgGroup.addLayer(image)
+
+                     image.addEventListener('load', () => {
+                       placeButton.removeChild(spinner)
+                     })
+                   }
+                 })
+
+                 image.src = `${url.replace('metadata', 'download')}/${file.name}`;
+
+                 imageRow.classList.add('d-flex', 'justify-content-between', 'align-items-center', 'mb-4', 'pe-5');
+                 imageRow.append(image, placeButton);
+
+                 imageContainer.appendChild(imageRow);
+                 imageCount++;
+               }
+             });
+             responseText.innerHTML = imageCount ? `${imageCount} image(s) fetched successfully from ${fetchedFrom.innerHTML}.` : 'No images found in the link provided...'
+           } else {
+             responseText.innerHTML = 'No images found in the link provided...'
+           }
+         })
+         .catch((error) => {
+            responseText.innerHTML = 'Uh-oh! Something\'s not right with the link provided!'
+         })
+         .finally(() => {
+           bootstrap.Modal.getInstance(welcomeModal).hide();
+         });
+     });
+
+     welcomeModal.addEventListener('hidden.bs.modal', (event) => {
+       new bootstrap.Offcanvas(sidebar).show();
+     });
+
  • 💾 Commit your changes

  • 🔀 Start a Pull Request. There are two ways how you can start a pull request:

  1. If you are familiar with the terminal or would like to learn it, here is a great tutorial on how to send a pull request using the terminal.

  2. You can also edit files directly in your browser and open a pull request from there.

  • 🏁 Done Ask in comments for a review :)

🤔❓ Questions?

Leave a comment below!

Is someone else already working on this?

We encourage you to link to this issue by mentioning the issue # in your pull request, so we can see if someone's already started on it. If someone seem stuck, offer them some help! Otherwise, take a look at some other issues you can help with. Thanks!

(This issue was created by First-Timers-Bot.)

@7malikk
Copy link
Collaborator

7malikk commented Oct 18, 2022

@segun-codes do you think this issue could be a good FTO? or it should be left for those who have completed an FTO?
@jywarren

@7malikk
Copy link
Collaborator

7malikk commented Oct 18, 2022

@AndroGenius-codes most of us including @segun-codes and I are working on the archive page right now, it'll be better to leave the task for those who haven't gotten either an FTO or a task after their FTOs. Just a thought.

@segun-codes
Copy link
Collaborator Author

segun-codes commented Oct 21, 2022

Hi @TildaDares, based on your advice, I have now reworked into a first-timers-only issue. I did same thing for issues #1183 to #1185. You may want to apply the FTO label on this (and the other issues mentioned). Many thanks to you @TildaDares @jywarren.

@TildaDares
Copy link
Member

Hi @segun-codes, please add a link to the file and the name of the repo in the issue description above. This also applies to the other issues. Thank you!

@segun-codes
Copy link
Collaborator Author

segun-codes commented Oct 21, 2022

Hi @segun-codes, please add a link to the file and the name of the repo in the issue description above. This also applies to the other issues. Thank you!

Hi @TildaDares, I have done as you advised for this and the other three issues (i.e., issues #1183 to #1185). As a reminder, kindly note that issues #1183 and #1185 are yet to be assigned. Thank you for your patience.

@Favour-Cay
Copy link

can i be assigned one of the issues ? cos i havent been assigned an FTO yet

@Aarav238
Copy link
Contributor

Aarav238 commented Dec 2, 2022

I am working on it as right now is working on it

@Aarav238
Copy link
Contributor

Aarav238 commented Dec 2, 2022

I'd like to try this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
@segun-codes @TildaDares @7malikk @Aarav238 @Favour-Cay and others