Created
December 18, 2017 07:17
-
-
Save liorkesos/65db30730bc320c3957515d1da493933 to your computer and use it in GitHub Desktop.
A mean powered service that changes the meta tags according to state changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
angular.module('mean.sport1').factory('Sport1', ['$resource', '$http', '$rootScope', '$q', '$location', | |
function($resource, $http, $rootScope, $q, $location) { | |
var dataConfig; | |
return { | |
getData: function(url) { | |
var deferred = $q.defer(); | |
$http({ | |
method: 'GET', | |
url: $rootScope.drupalServe1 + url.param, | |
crossDomain: false | |
}) | |
.success(function(data) { | |
if (url.param === 'data?name=config') | |
dataConfig = data; | |
deferred.resolve(data); | |
}) | |
.error(function(data) { | |
deferred.reject('invalid value'); | |
}); | |
return deferred.promise; | |
}, | |
postData: function(data){ | |
var deferred = $q.defer(); | |
$http({ | |
method: 'POST', | |
url: $rootScope.drupalServe1 + data.url, | |
data: {'data' : data.data}, | |
crossDomain: false | |
}) | |
.success(function(data) { | |
deferred.resolve(data); | |
}) | |
.error(function(data) { | |
deferred.reject('invalid value'); | |
}); | |
return deferred.promise; | |
}, | |
getDataConfig: function(){ | |
var deferred = $q.defer(); | |
if (dataConfig ) | |
deferred.resolve(dataConfig); | |
else{ | |
$http({ | |
method: 'GET', | |
url: $rootScope.drupalServe1 + 'data?name=config', | |
crossDomain: false | |
}) | |
.success(function(data) { | |
dataConfig = data; | |
deferred.resolve(dataConfig); | |
}) | |
} | |
return deferred.promise; | |
}, | |
setMeta: function(data){ | |
document.querySelectorAll('[property="og:description"]')[0].setAttribute('content', data.description); | |
document.querySelectorAll('[property="og:title"]')[0].setAttribute('content', data.title); | |
document.querySelectorAll('title')[0].setAttribute('content', data.title); | |
document.querySelectorAll('[name=description]')[0].setAttribute('content', data.description); | |
// if(data.image) document.querySelectorAll('[property="og:image"]')[0].setAttribute('content', "http://cms.sport2.co.il/sites/default/files/styles/thumbnail/public/" + data.image); | |
if(data.image) document.querySelectorAll('[property="og:image"]')[0].setAttribute('content', $rootScope.drupalImage + "557x314/" + data.image); | |
else document.querySelectorAll('[property="og:image"]')[0].setAttribute('content', $location.protocol() + '://' + $location.host() + "/system/assets/img/logo.png"); | |
document.title = data.title | |
var tags = 'sport1, sport2, sport , ספורט, ספורט1, ספורט2'; | |
if (data.tag) | |
var tags = [tags, data.tag].join(' , '); | |
document.querySelectorAll('[name=keywords]')[0].setAttribute('content', tags ); | |
} | |
}; | |
// $rootScopeProvider.digestTtl(15); | |
} | |
]); | |
angular.module('mean.sport1').factory('Sport1Config', ['$resource', '$http', '$rootScope', '$q', 'Sport1','$filter', | |
function($resource, $http, $rootScope, $q, Sport1, $filter) { | |
return { | |
getHP: function(callback){ | |
Sport1.getDataConfig().then(function(data){ | |
var date = new Date(); | |
date = ($filter('date')(date, "EEE")).toLowerCase(); | |
if (data[0].data.statistics[date].top == 0 ){ | |
data = { | |
'more-articles' : 4, | |
'statistics' : 6 | |
} | |
} | |
else{ | |
data = { | |
'more-articles' : 6, | |
'statistics' : 4 | |
} | |
} | |
return callback(data); | |
}) | |
} | |
} | |
}]) | |
angular.module('mean.sport1').factory('MeanSocket', function($rootScope) { | |
var socket = io.connect($rootScope.socketServer); | |
return { | |
on: function(eventName, callback) { | |
socket.on(eventName, function() { | |
var args = arguments; | |
$rootScope.$apply(function() { | |
callback.apply(socket, args); | |
}); | |
}); | |
}, | |
emit: function(eventName, data, callback) { | |
socket.emit(eventName, data, function() { | |
var args = arguments; | |
$rootScope.$apply(function() { | |
if (callback) { | |
callback.apply(socket, args); | |
} | |
}); | |
}); | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment