-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from DaniloNovakovic/v2
v2.3.0 - Bookmarks & Folders are now always sorted
- Loading branch information
Showing
11 changed files
with
159 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* Sorts children of html element with given `id` | ||
* @param {string} id - id of html element whose children will be sorted | ||
* @param {function(HTMLElement, HTMLElement)} callback - returns `true` if elements should swap, `false` if not (default: ascending) | ||
*/ | ||
export default function sortList(id, callback) { | ||
if (typeof id != 'string') { | ||
return console.warn( | ||
`failed to sort list ${id} (reason: invalid parameter listId)` | ||
); | ||
} | ||
var list, i, switching, b, shouldSwitch; | ||
list = document.getElementById(id); | ||
switching = true; | ||
|
||
while (switching) { | ||
switching = false; | ||
b = list.children; | ||
for (i = 0; i < b.length - 1; i++) { | ||
shouldSwitch = false; | ||
/* Check if the next item should | ||
switch place with the current item: */ | ||
if (typeof callback == 'function') { | ||
shouldSwitch = !!callback(b[i], b[i + 1]); | ||
} else { | ||
shouldSwitch = | ||
b[i].innerHTML.toLowerCase() > b[i + 1].innerHTML.toLowerCase(); | ||
} | ||
if (shouldSwitch) { | ||
break; | ||
} | ||
} | ||
|
||
if (shouldSwitch) { | ||
/* If a switch has been marked, make the switch | ||
and mark the switch as done: */ | ||
b[i].parentNode.insertBefore(b[i + 1], b[i]); | ||
switching = true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters