### # Copyright (C) 2014-2015 Taiga Agile LLC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . # # File: app-meta.service.coffee ### taiga = @.taiga truncate = taiga.truncate class AppMetaService @.$inject = [ "$rootScope" ] constructor: (@rootScope) -> _set: (key, value) -> return if not key if key == "title" meta = $("title") if meta.length == 0 meta = $("") $("head").append(meta) meta.text(value or "") else if key.indexOf("og:") == 0 meta = $("meta[property='#{key}']") if meta.length == 0 meta = $("") $("head").append(meta) meta.attr("content", value or "") else meta = $("meta[name='#{key}']") if meta.length == 0 meta = $("") $("head").append(meta) meta.attr("content", value or "") setTitle: (title) -> @._set('title', title) setDescription: (description) -> @._set("description", truncate(description, 250)) setTwitterMetas: (title, description) -> @._set("twitter:card", "summary") @._set("twitter:site", "@taigaio") @._set("twitter:title", title) @._set("twitter:description", truncate(description, 300)) @._set("twitter:image", "#{window.location.origin}/images/logo-color.png") setOpenGraphMetas: (title, description) -> @._set("og:type", "object") @._set("og:site_name", "Taiga - Love your projects") @._set("og:title", title) @._set("og:description", truncate(description, 300)) @._set("og:image", "#{window.location.origin}/images/logo-color.png") @._set("og:url", window.location.href) setAll: (title, description) -> @.setTitle(title) @.setDescription(description) @.setTwitterMetas(title, description) @.setOpenGraphMetas(title, description) addMobileViewport: () -> $("head").append( "" ) removeMobileViewport: () -> $("meta[name=\"viewport\"]").remove() setfn: (fn) -> @._listener() if @.listener @._listener = @rootScope.$watchCollection fn, (metas) => @.setAll(metas.title, metas.description) angular.module("taigaCommon").service("tgAppMetaService", AppMetaService)