I started my vanilla survival surver with only datapacks on it and i didn't want it to be a bukkit server or any other surver that uses plugins.
I wanted my players to be able to switch to spectator mode whenever they wanted but i didn't want them to use it to tp to other places.
So this is when my search began. I started a post on the minecraft forums asking for this. but the only responce I got was make a plugin.
This wasn't an option for me so I tried creating a datapack it was based on the sethome datapack on the vanila tweaks website.
This datapack allows players on your server to type
/trigger spectator
and that puts them in spectator mode.
after they use the command again they will be teleported back to the position the command was first used.