예제 #1
0
 /**
  *	Include Meta
  *	Add Meta Information In View
  *	@param string $nameOrSnipit
  *	@param BOOL $content
  *	@return \Touchbase\View\self
  */
 public function includeMeta($nameOrSnipit, $content = null)
 {
     if (!empty($content)) {
         $nameOrSnipit = HTML::meta()->attr('name', $nameOrSnipit)->attr('content', $content);
     }
     $this->includeAsset(self::META, $nameOrSnipit);
     return $this;
 }
예제 #2
0
    /**
     *	__construct
     *	@param \Touchbase\Control\WebpageController $controller
     */
    public function __construct(WebpageController $controller)
    {
        $this->controller = $controller;
        //Set Default Title, if available...
        $this->assets()->pushTitle($controller->config("project")->get("name", null));
        //Add Defualt Meta
        $this->assets()->includeMeta(HTML::meta()->attr('charset', 'UTF-8'));
        $this->assets()->includeMeta(HTML::meta()->attr('http-equiv', 'Content-type')->attr('content', 'text/html; charset=utf-8'));
        $this->assets()->includeMeta('generator', 'Touchbase - http://touchbase.io');
        //Include base url
        $this->assets()->includeExtra(HTML::base()->href(Router::buildPath(SITE_URL, $_SERVER['REQUEST_URI'])));
        //WebApp
        $this->assets()->includeMeta('HandheldFriendly', 'true');
        $this->assets()->includeMeta('MobileOptimized', '320');
        $this->assets()->includeMeta(HTML::meta()->attr('http-equiv', 'cleartype')->attr('content', 'on'));
        $this->assets()->includeMeta('viewport', 'user-scalable=no, initial-scale=1.0, maximum-scale=1.0');
        $this->assets()->includeMeta('apple-mobile-web-app-status-bar-style', 'black-translucent');
        $this->assets()->includeMeta('apple-mobile-web-app-capable', 'yes');
        $this->assets()->includeMeta('apple-mobile-web-app-title', $this->controller->config("project")->get("name", null));
        $this->assets()->includeMeta('mobile-web-app-capable', 'yes');
        //WebAppIcons
        $manifest = File::create([Router::pathForAssetUrl(BASE_IMAGES), 'icons', 'manifest.json']);
        if ($manifest->exists()) {
            $manifestData = json_decode($manifest->read());
            $manifestUrl = Router::urlForPath($manifest->folder->path);
            $this->assets()->includeExtra(HTML::link()->href(Router::buildPath($manifestUrl, $manifest->name))->rel("manifest"));
            //Launch Images
            //Icons
            foreach ($manifestData->icons as $icon) {
                $this->assets()->includeExtra(HTML::link()->href(Router::buildPath($manifestUrl, $icon->src))->sizes($icon->sizes)->rel("apple-touch-icon-precomposed"));
            }
        }
        //Prevent Opening WebApp Links In Mobile Safari!
        $this->assets()->includeScript(HTML::script('(function(a,b,c){if(c in b&&b[c]){var d,e=a.location,f=/^(a|html)$/i,g=a.documentElement;a.addEventListener("click",function(a){d=a.target;while(!f.test(d.nodeName))d=d.parentNode;"href"in d&&(d.href.indexOf("http")||~d.href.indexOf(e.host))&&(a.preventDefault(),e.href=d.href)},!1);g.className=g.className+" "+c}})(document,window.navigator,"standalone")'), true);
        //Add Base Scripts
        $assetConfig = $controller->config("assets");
        $assetPath = $assetConfig->get("assets", "assets");
        $baseScripts = Router::buildPath(SITE_URL, $assetPath, $assetConfig->get("js", "js"));
        //Include Modernizr
        $this->assets()->includeScript([$baseScripts, 'modernizr.min.js'], true);
        //Include jQuery?
        if ($jqVersion = $controller->config("assets")->get("jquery_version", false)) {
            //Load From Google
            $jqueryPath = Router::buildPath($jqVersion, "jquery.min.js");
            $this->assets()->includeScript(Router::buildPath("//ajax.googleapis.com/ajax/libs/jquery/", $jqueryPath));
            //If That Fails Load Locally
            if (Router::pathForAssetUrl($jqueryUrl = Router::buildPath($baseScripts, "vendor", "jquery", $jqueryPath))) {
                $this->assets()->includeScript(HTML::script('window.jQuery||document.write(\'<script src="' . $jqueryUrl . '"><\\/script>\')'));
            }
        }
        //Include Google Analytics
        $googleAnalyticsCode = $controller->config("project")->get("analytics", null);
        if (isset($googleAnalyticsCode) && Router::isLive()) {
            $this->assets()->includeScript("<script>\n\t\t\t  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){\n\t\t\t  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),\n\t\t\t  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)\n\t\t\t  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');\n\n\t\t\t  ga('create', '{$googleAnalyticsCode}', 'auto');\n\t\t\t  ga('send', 'pageview');\n\t\t\t</script>");
        }
        if (Router::pathForAssetUrl($fastclickUrl = Router::buildPath($baseScripts, "vendor", "fastclick.js"))) {
            $this->assets()->includeScript($fastclickUrl);
            $this->assets()->includeScript(HTML::script('if ("addEventListener" in document) {
				document.addEventListener("DOMContentLoaded", function() {
					FastClick.attach(document.body);
				}, false);
			}'));
        }
        $this->setLayout($this->layout);
        //HTML
        $this->_htmlTag = HTML::html()->attr("lang", "en")->addClass('no-js');
        $this->_bodyTag = HTML::body();
    }