Make import/export compatible with IE/Edge
This commit is contained in:
		
							parent
							
								
									6e27927194
								
							
						
					
					
						commit
						a83d415f48
					
				| 
						 | 
					@ -17,13 +17,18 @@ function showBookmarkData() {
 | 
				
			||||||
	openDBRequest.onsuccess = function (openEvt) {
 | 
						openDBRequest.onsuccess = function (openEvt) {
 | 
				
			||||||
		var db = openEvt.target.result;
 | 
							var db = openEvt.target.result;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		db.transaction("Groups").objectStore("Groups").getAll().onsuccess = function (getAllEvt) {
 | 
							var bookmarkList = [];
 | 
				
			||||||
			var res = getAllEvt.target.result;
 | 
							db.transaction("Groups").objectStore("Groups").openCursor().onsuccess = function (cursorEvt) {
 | 
				
			||||||
			var data = JSON.stringify(res, null, 4);
 | 
								var cursor = cursorEvt.target.result;
 | 
				
			||||||
			$("#exportText").val(data);
 | 
								if (cursor) {
 | 
				
			||||||
 | 
									bookmarkList.push(cursor.value);
 | 
				
			||||||
 | 
									cursor.continue();
 | 
				
			||||||
 | 
								} else {
 | 
				
			||||||
 | 
									var data = JSON.stringify(bookmarkList, null, 4);
 | 
				
			||||||
 | 
									$("#exportText").val(data);
 | 
				
			||||||
 | 
									db.close();
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					 | 
				
			||||||
		db.close();
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -48,15 +53,14 @@ function setList(data) {
 | 
				
			||||||
	// empty the DB and fill it with the new data
 | 
						// empty the DB and fill it with the new data
 | 
				
			||||||
	var openDBRequest = window.indexedDB.open("bookmarks");
 | 
						var openDBRequest = window.indexedDB.open("bookmarks");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	openDBRequest.onsuccess = function (e) {
 | 
						openDBRequest.onsuccess = function (openEvt) {
 | 
				
			||||||
		db = e.target.result;
 | 
							db = openEvt.target.result;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		var groupStore = db.transaction("Groups", "readwrite").objectStore("Groups");
 | 
							var groupStore = db.transaction("Groups", "readwrite").objectStore("Groups");
 | 
				
			||||||
		groupStore.clear();
 | 
							groupStore.clear();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// create the object stores
 | 
							for (var i = 0; i < data.length; i++) {
 | 
				
			||||||
		for (let group of data) {
 | 
								groupStore.add(data[i]);
 | 
				
			||||||
			groupStore.add(group);
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$("#importExportModal").modal("hide");
 | 
							$("#importExportModal").modal("hide");
 | 
				
			||||||
| 
						 | 
					@ -66,7 +70,10 @@ function setList(data) {
 | 
				
			||||||
		loadBookmarks();
 | 
							loadBookmarks();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	openDBRequest.onerror = function (err) { console.error(err); }
 | 
						openDBRequest.onerror = function (err) {
 | 
				
			||||||
 | 
							console.error(err);
 | 
				
			||||||
 | 
							window.alert("Error importing bookmarks");
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function validateBookmarks(bookmarks) {
 | 
					function validateBookmarks(bookmarks) {
 | 
				
			||||||
| 
						 | 
					@ -110,8 +117,8 @@ function validateBookmarks(bookmarks) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function arrayContains(array, searchFor) {
 | 
					function arrayContains(array, searchFor) {
 | 
				
			||||||
	for (let item of array) {
 | 
						for (var i = 0; i < array.length; i++) {
 | 
				
			||||||
		if (item == searchFor)
 | 
							if (array[i] == searchFor)
 | 
				
			||||||
			return true;
 | 
								return true;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue