refactory the javascript code of open content view