Issue #1209532 by timmillwood, lucascaro, wiifm, mikeytown2, slashrsm: Count node views via AJAX in the statistics module.

8.0.x
webchick 2012-09-19 23:36:58 -07:00
parent da4adbdafb
commit 6a064f416a
2 changed files with 4 additions and 6 deletions

View File

@ -3,13 +3,11 @@
"use strict";
$(document).ready(function() {
var nid = Drupal.settings.statistics.nid;
var basePath = Drupal.settings.basePath;
$.ajax({
type: "POST",
cache: false,
url: basePath+"core/modules/statistics/statistics.php",
data: "nid="+nid
url: Drupal.settings.statistics.url,
data: Drupal.settings.statistics.data
});
});
})(jQuery);

View File

@ -102,9 +102,9 @@ function statistics_permission() {
* Implements hook_node_view().
*/
function statistics_node_view(Node $node, $view_mode) {
if (!empty($node->nid) && $view_mode == 'full') {
if (!empty($node->nid) && $view_mode == 'full' && node_is_page($node) && empty($node->in_preview)) {
$node->content['#attached']['library'][] = array('statistics', 'drupal.statistics');
$settings = array('nid' => $node->nid);
$settings = array('data' => array('nid' => $node->nid), 'url' => url(drupal_get_path('module', 'statistics') . '/statistics.php'));
$node->content['#attached']['js'][] = array(
'data' => array('statistics' => $settings),
'type' => 'setting',