From 8284dcc129d48d2a7f0572fc0662de6a691440db Mon Sep 17 00:00:00 2001 From: buddh4 Date: Wed, 15 Mar 2017 20:10:31 +0100 Subject: [PATCH] - Enh: added js module 'ui.view' for view state and utils - Changed 'ui.state.getState' to 'ui.view.getState' - Enh: added view helper as getHeight/Width and isSmall/Medium/Normal (width) to 'ui.view' js module - Fix: removed popover image preview from mobile - Fix: removed target-densitydpi not supported warning --- protected/humhub/assets/CoreApiAsset.php | 1 + protected/humhub/components/Controller.php | 2 +- .../modules/file/resources/js/humhub.file.js | 24 ++++---- .../resources/js/humhub.notification.js | 6 +- protected/humhub/views/layouts/main.php | 2 +- static/js/humhub/humhub.ui.view.js | 56 +++++++++++++++++++ 6 files changed, 76 insertions(+), 15 deletions(-) create mode 100644 static/js/humhub/humhub.ui.view.js diff --git a/protected/humhub/assets/CoreApiAsset.php b/protected/humhub/assets/CoreApiAsset.php index 83c9f3f6fe..1ee0e17265 100755 --- a/protected/humhub/assets/CoreApiAsset.php +++ b/protected/humhub/assets/CoreApiAsset.php @@ -45,6 +45,7 @@ class CoreApiAsset extends AssetBundle 'js/humhub/humhub.core.js', 'js/humhub/humhub.util.js', 'js/humhub/humhub.log.js', + 'js/humhub/humhub.ui.view.js', 'js/humhub/humhub.ui.additions.js', 'js/humhub/humhub.ui.showMore.js', 'js/humhub/humhub.ui.form.elements.js', diff --git a/protected/humhub/components/Controller.php b/protected/humhub/components/Controller.php index 8c3239f38e..57b2e1df10 100644 --- a/protected/humhub/components/Controller.php +++ b/protected/humhub/components/Controller.php @@ -221,7 +221,7 @@ class Controller extends \yii\web\Controller public function setJsViewStatus() { $modluleId = (Yii::$app->controller->module) ? Yii::$app->controller->module->id : ''; - $this->view->registerJs('humhub.modules.ui.status.setState("' . $modluleId . '", "' . Yii::$app->controller->id . '", "' . Yii::$app->controller->action->id . '");', \yii\web\View::POS_BEGIN); + $this->view->registerJs('humhub.modules.ui.view.setState("' . $modluleId . '", "' . Yii::$app->controller->id . '", "' . Yii::$app->controller->action->id . '");', \yii\web\View::POS_BEGIN); if(Yii::$app->request->isPjax) { \humhub\widgets\TopMenu::setViewState(); diff --git a/protected/humhub/modules/file/resources/js/humhub.file.js b/protected/humhub/modules/file/resources/js/humhub.file.js index 61139c3113..25d81287be 100644 --- a/protected/humhub/modules/file/resources/js/humhub.file.js +++ b/protected/humhub/modules/file/resources/js/humhub.file.js @@ -12,6 +12,8 @@ humhub.module('file', function (module, require, $) { var string = util.string; var action = require('action'); var event = require('event'); + + var view = require('ui.view'); var Upload = function (node, options) { Widget.call(this, node, options); @@ -330,16 +332,18 @@ humhub.module('file', function (module, require, $) { if (file.thumbnailUrl && !this.options.preventPopover) { // Preload image new Image().src = file.thumbnailUrl; - $file.find('.file-preview-content').popover({ - html: true, - trigger: 'hover', - animation: 'fade', - delay: 100, - placement: this.options.popoverPosition || 'right', - content: function () { - return string.template(Preview.template.popover, file); - } - }); + if(!view.isSmall()) { + $file.find('.file-preview-content').popover({ + html: true, + trigger: 'hover', + animation: 'fade', + delay: 100, + placement: this.options.popoverPosition || 'right', + content: function () { + return string.template(Preview.template.popover, file); + } + }); + } }; var that = this; diff --git a/protected/humhub/modules/notification/resources/js/humhub.notification.js b/protected/humhub/modules/notification/resources/js/humhub.notification.js index 1c17e2643b..4703f89f3e 100644 --- a/protected/humhub/modules/notification/resources/js/humhub.notification.js +++ b/protected/humhub/modules/notification/resources/js/humhub.notification.js @@ -10,7 +10,7 @@ humhub.module('notification', function (module, require, $) { var Widget = require('ui.widget').Widget; var event = require('event'); var client = require('client'); - var status = require('ui.status'); + var view = require('ui.view'); var user = require('user'); module.initOnPjaxLoad = true; @@ -207,9 +207,9 @@ humhub.module('notification', function (module, require, $) { var updateTitle = function ($count) { if ($count) { - document.title = '(' + $count + ') ' + status.getState().title; + document.title = '(' + $count + ') ' + view.getState().title; } else if ($count === false) { - document.title = status.getState().title; + document.title = view.getState().title; } }; diff --git a/protected/humhub/views/layouts/main.php b/protected/humhub/views/layouts/main.php index 6520585ba0..36616e5770 100755 --- a/protected/humhub/views/layouts/main.php +++ b/protected/humhub/views/layouts/main.php @@ -10,7 +10,7 @@ <?php echo $this->pageTitle; ?> - + head() ?> render('head'); ?> diff --git a/static/js/humhub/humhub.ui.view.js b/static/js/humhub/humhub.ui.view.js new file mode 100644 index 0000000000..4c0c80c544 --- /dev/null +++ b/static/js/humhub/humhub.ui.view.js @@ -0,0 +1,56 @@ +humhub.module('ui.view', function (module, require, $) { + var title; + var state = {}; + + var isSmall = function () { + return module.getWidth() <= 767; + }; + + var isMedium = function () { + return module.getWidth() > 767 && module.getWidth() <= 991; + }; + + var isNormal = function () { + return module.getWidth() >= 991; + }; + + var setState = function (moduleId, controlerId, action) { + state = { + title: title || document.title, + moduleId: moduleId, + controllerId: controlerId, + action: action + }; + }; + + var getHeight = function() { + return window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight; + }; + + var getWidth = function() { + return window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; + }; + + module.initOnPjaxLoad = true; + var init = function ($pjax) { + title = document.title; + module.log.debug('Current view state', state); + }; + + module.export({ + init: init, + isSmall: isSmall, + isMedium: isMedium, + isNormal: isNormal, + getHeight: getHeight, + getWidth: getWidth, + // This function is called by controller itself + setState: setState, + getState: function () { + return $.extend({}, state); + }, + getTitle: function () { + return state.title; + } + }); +}); \ No newline at end of file