Skip to content

Commit

Permalink
add moi krug share button
Browse files Browse the repository at this point in the history
  • Loading branch information
esvit committed Dec 4, 2014
1 parent 503ef3c commit 3615d06
Show file tree
Hide file tree
Showing 10 changed files with 438 additions and 232 deletions.
2 changes: 1 addition & 1 deletion angular-social.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion angular-social.js

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions angular-social.less
Original file line number Diff line number Diff line change
Expand Up @@ -473,4 +473,26 @@
border-right-color: mix(@btn-color, #fff, 10%);
}
}
}
/* Мой круг */
.ng-social-moi-krug {
@first-color: #afd0f0;
@second-color: #70b0e6;

.ng-social-button {
padding-left:19px;
background: @first-color;
.linear-gradient(@first-color, @second-color);
color:#fff;
border-color: darken(@second-color, 10%);

&:hover {
border-color: darken(@second-color, 10%);
.linear-gradient(@first-color, darken(@second-color, 10%));
}
}
.ng-social-icon {
background-image:url('images/moikrug.png');
background-position:3px 3px;
}
}
2 changes: 1 addition & 1 deletion angular-social.map

Large diffs are not rendered by default.

175 changes: 105 additions & 70 deletions angular-social.src.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,91 +28,89 @@ app.directive('ngSocialButtons', ['$compile', '$q', '$parse', '$http', '$locatio
controller: ['$scope', '$q', '$http', function ($scope, $q, $http) {
var getUrl = function () {
return $scope.url || $location.absUrl();
}, ctrl = this;
this.init = function (scope, element, options) {
if (options.counter) {
ctrl.getCount(scope.options).then(function (count) {
scope.count = count;
});
}
};
var ctrl = {
init: function (scope, element, options) {
if (options.counter) {
ctrl.getCount(scope.options).then(function(count) {
scope.count = count;
});
}
},
link: function (options) {
this.link = function (options) {
options = options || {};
var urlOptions = options.urlOptions || {};
urlOptions.url = getUrl();
urlOptions.title = $scope.title;
urlOptions.image = $scope.image;
urlOptions.description = $scope.description || '';
return ctrl.makeUrl(options.clickUrl || options.popup.url, urlOptions);
},
clickShare: function (e, options) {
if (e.shiftKey || e.ctrlKey) {
return;
}
e.preventDefault();
};
this.clickShare = function (e, options) {
if (e.shiftKey || e.ctrlKey) {
return;
}
e.preventDefault();

if (options.track && typeof _gaq != 'undefined' && angular.isArray(_gaq)) {
_gaq.push(['_trackSocial', options.track.name, options.track.action, $scope.url]);
}
if (options.track && typeof _gaq != 'undefined' && angular.isArray(_gaq)) {
_gaq.push(['_trackSocial', options.track.name, options.track.action, $scope.url]);
}

var process = true;
if (angular.isFunction(options.click)) {
process = options.click.call(this, options);
}
if (process) {
var url = ctrl.link(options);
ctrl.openPopup(url, options.popup);
}
},
openPopup: function (url, params) {
var left = Math.round(screen.width / 2 - params.width / 2),
top = 0;
if (screen.height > params.height) {
top = Math.round(screen.height / 3 - params.height / 2);
}
var process = true;
if (angular.isFunction(options.click)) {
process = options.click.call(this, options);
}
if (process) {
var url = ctrl.link(options);
ctrl.openPopup(url, options.popup);
}
};
this.openPopup = function (url, params) {
var left = Math.round(screen.width / 2 - params.width / 2),
top = 0;
if (screen.height > params.height) {
top = Math.round(screen.height / 3 - params.height / 2);
}

var win = window.open(
url,
'sl_' + this.service,
'left=' + left + ',top=' + top + ',' +
'width=' + params.width + ',height=' + params.height +
',personalbar=0,toolbar=0,scrollbars=1,resizable=1'
);
if (win) {
win.focus();
} else {
location.href = url;
}
},
getCount: function (options) {
var def = $q.defer();
var urlOptions = options.urlOptions || {};
urlOptions.url = getUrl();
urlOptions.title = $scope.title;
var url = ctrl.makeUrl(options.counter.url, urlOptions),
showcounts = angular.isUndefined($scope.showcounts) ? true : $scope.showcounts;
var win = window.open(
url,
'sl_' + this.service,
'left=' + left + ',top=' + top + ',' +
'width=' + params.width + ',height=' + params.height +
',personalbar=0,toolbar=0,scrollbars=1,resizable=1'
);
if (win) {
win.focus();
} else {
location.href = url;
}
};
this.getCount = function (options) {
var def = $q.defer();
var urlOptions = options.urlOptions || {};
urlOptions.url = getUrl();
urlOptions.title = $scope.title;
var url = ctrl.makeUrl(options.counter.url, urlOptions),
showcounts = angular.isUndefined($scope.showcounts) ? true : $scope.showcounts;

if (showcounts) {
if (options.counter.get) {
options.counter.get(url, def, $http);
} else {
$http.jsonp(url).success(function (res) {
if (options.counter.getNumber) {
def.resolve(options.counter.getNumber(res));
} else {
def.resolve(res);
}
});
}
if (showcounts) {
if (options.counter.get) {
options.counter.get(url, def, $http);
} else {
$http.jsonp(url).success(function (res) {
if (options.counter.getNumber) {
def.resolve(options.counter.getNumber(res));
} else {
def.resolve(res);
}
});
}
return def.promise;
},
makeUrl: function (url, context) {
return template(url, context, encodeURIComponent);
}
return def.promise;
};
return ctrl;
this.makeUrl = function (url, context) {
return template(url, context, encodeURIComponent);
};
return this;
}]
};
}
Expand Down Expand Up @@ -603,6 +601,43 @@ app.directive('ngSocialStumbleupon', ['$parse', function ($parse) {
}
};
}]);
app.directive('ngSocialMoiKrug', ['$parse', function ($parse) {
'use strict';

var options = {
popup: {
url: 'http://share.yandex.ru/go.xml?service=moikrug&url={url}&title={title}',
width: 800,
height: 600
},
track: {
'name': 'MoiKrug',
'action': 'share'
}
};
return {
restrict: 'C',
require: '^?ngSocialButtons',
scope: true,
replace: true,
transclude: true,
template: '<li> \
<a ng-href="{{ctrl.link(options)}}" target="_blank" ng-click="ctrl.clickShare($event, options)" class="ng-social-button"> \
<span class="ng-social-icon"></span> \
<span class="ng-social-text" ng-transclude></span> \
</a> \
</li>',
link: function (scope, element, attrs, ctrl) {
element.addClass('ng-social-moi-krug');
if (!ctrl) {
return;
}
scope.options = options;
scope.ctrl = ctrl;
ctrl.init(scope, element, options);
}
};
}]);
angular.module('ngSocial').run(['$templateCache', function ($templateCache) {
$templateCache.put('/views/buttons.html', '<div class="ng-social-container ng-cloak"><ul class="ng-social" ng-transclude></ul></div>');
}]);
2 changes: 2 additions & 0 deletions examples/demo1.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<script src="../src/scripts/09-github.js"></script>
<script src="../src/scripts/09-github-forks.js"></script>
<script src="../src/scripts/10-stumbleupon.js"></script>
<script src="../src/scripts/11-moikrug.js"></script>
<link rel="stylesheet" href="../angular-social.css">
</head>
<body ng-app="main">
Expand All @@ -44,6 +45,7 @@
<li class="ng-social-github" user="esvit" repository="ng-table">GitHub</li>
<li class="ng-social-github-forks" user="esvit" repository="ng-table">Forks</li>
<li class="ng-social-stumbleupon">StumbleUpon</li>
<li class="ng-social-moi-krug">Мой круг</li>
</ul>


Expand Down
Loading

0 comments on commit 3615d06

Please sign in to comment.