diff options
Diffstat (limited to 'js')
| -rw-r--r-- | js/redirectorpage.js | 26 | ||||
| -rw-r--r-- | js/util.js | 8 | 
2 files changed, 26 insertions, 8 deletions
diff --git a/js/redirectorpage.js b/js/redirectorpage.js index f82b0b7..1cad8a8 100644 --- a/js/redirectorpage.js +++ b/js/redirectorpage.js @@ -23,7 +23,7 @@ function saveChanges() {  		}  	});  } -		 +  function toggleSyncSetting() {  	chrome.runtime.sendMessage({type:"toggle-sync", isSyncEnabled: !options.isSyncEnabled}, function(response) {  		if(response.message === "sync-enabled"){ @@ -60,16 +60,16 @@ function renderRedirects() {  }  function renderSingleRedirect(node, redirect, index) { -	 +  	//Add extra props to help with rendering...  	if (index === 0) {  		redirect.$first = true;  	}  	if (index === REDIRECTS.length - 1) {  		redirect.$last = true; -	}  +	}  	redirect.$index = index; -	 +  	dataBind(node, redirect);  	node.setAttribute('data-index', index); @@ -134,11 +134,25 @@ function moveDown(index) {  	saveChanges();  } +function moveUpTop(index) { +	let top = REDIRECTS[0]; +	move(REDIRECTS, index, top); +	updateBindings(); +	saveChanges(); +} + +function moveDownBottom(index) { +	let bottom = REDIRECTS.length - 1; +	move(REDIRECTS, index, bottom); +	updateBindings(); +	saveChanges(); +} +  //All the setup stuff for the page  function pageLoad() {  	template = el('#redirect-row-template');  	template.parentNode.removeChild(template); -	 +  	//Need to proxy this through the background page, because Firefox gives us dead objects  	//nonsense when accessing chrome.storage directly.  	chrome.runtime.sendMessage({type: "get-redirects"}, function(response) { @@ -169,7 +183,7 @@ function pageLoad() {  			));  		}  		renderRedirects(); -	});  +	});  	chrome.storage.local.get({isSyncEnabled:false}, function(obj){  		options.isSyncEnabled = obj.isSyncEnabled; @@ -36,12 +36,12 @@ function dataBind(el, dataObject) {  		}  	}  	for (let tag of el.querySelectorAll('[data-show]')) { -		let shouldShow = boolValue(tag.getAttribute('data-show'));	 +		let shouldShow = boolValue(tag.getAttribute('data-show'));  		tag.style.display = shouldShow ? '' : 'none';  	}  	for (let tag of el.querySelectorAll('[data-disabled]')) {  		let isDisabled = boolValue(tag.getAttribute('data-disabled')); -		 +  		if (isDisabled) {  			tag.classList.add('disabled');  			tag.setAttribute('disabled', 'disabled'); @@ -82,6 +82,10 @@ function showForm(selector, dataObject) {  	show(selector);  } +function move(arr, from, to) { +    arr.splice(to, 0, arr.splice(from, 1)[0]); +} +  function hideForm(selector) {  	hide('#cover');  	hide(selector);  | 
