mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-05-25 04:24:45 -04:00
Refactor notifications.
This commit is contained in:
parent
6500b624f5
commit
73496c6b7c
6 changed files with 40 additions and 39 deletions
|
@ -1,4 +1,4 @@
|
|||
#notify {
|
||||
#notification {
|
||||
position: fixed;
|
||||
left: 50%;
|
||||
width: 200px;
|
||||
|
@ -9,4 +9,5 @@
|
|||
background: rgba(0,0,0,0.2);
|
||||
border-radius: 0 0 4px 4px;
|
||||
text-align: center;
|
||||
overflow: hidden;
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
modulejs.define('core/location', ['_', 'modernizr', 'core/event', 'core/notify', 'core/settings'], function (_, modernizr, event, notify, allsettings) {
|
||||
modulejs.define('core/location', ['_', 'modernizr', 'core/event', 'core/settings', 'view/notification'], function (_, modernizr, event, allsettings, notification) {
|
||||
|
||||
var settings = _.extend({
|
||||
fastBrowsing: true,
|
||||
|
@ -135,10 +135,10 @@ modulejs.define('core/location', ['_', 'modernizr', 'core/event', 'core/notify',
|
|||
event.pub('location.changed', item);
|
||||
refresh();
|
||||
} else {
|
||||
notify.set('loading...');
|
||||
notification.set('loading...');
|
||||
load(function () {
|
||||
item.isLoaded = true;
|
||||
notify.set();
|
||||
notification.set();
|
||||
event.pub('location.changed', item);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
modulejs.define('core/notify', ['$'], function ($) {
|
||||
|
||||
var template = '<div id="notify"/>';
|
||||
|
||||
function set(content) {
|
||||
|
||||
if (content) {
|
||||
$('#notify').stop(true, true).html(content).fadeIn(400);
|
||||
} else {
|
||||
$('#notify').stop(true, true).fadeOut(400);
|
||||
}
|
||||
}
|
||||
|
||||
$(template).hide().appendTo('body');
|
||||
|
||||
return {
|
||||
set: set
|
||||
};
|
||||
});
|
19
src/_h5ai/client/js/inc/view/notification.js
Normal file
19
src/_h5ai/client/js/inc/view/notification.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
modulejs.define('view/notification', ['$'], function ($) {
|
||||
|
||||
var template = '<div id="notification"/>';
|
||||
|
||||
function set(content) {
|
||||
|
||||
if (content) {
|
||||
$('#notification').stop(true, true).html(content).fadeIn(400);
|
||||
} else {
|
||||
$('#notification').stop(true, true).fadeOut(400);
|
||||
}
|
||||
}
|
||||
|
||||
$(template).hide().appendTo('body');
|
||||
|
||||
return {
|
||||
set: set
|
||||
};
|
||||
});
|
|
@ -2,7 +2,7 @@
|
|||
'use strict';
|
||||
|
||||
var ID = 'core/location';
|
||||
var DEPS = ['_', 'modernizr', 'core/event', 'core/notify', 'core/settings'];
|
||||
var DEPS = ['_', 'modernizr', 'core/event', 'core/settings', 'view/notification'];
|
||||
|
||||
describe('module \'' + ID + '\'', function () {
|
||||
|
||||
|
@ -21,16 +21,16 @@ describe('module \'' + ID + '\'', function () {
|
|||
pub: sinon.stub(),
|
||||
sub: sinon.stub()
|
||||
};
|
||||
this.xNotify = {
|
||||
this.xNotification = {
|
||||
set: sinon.stub()
|
||||
};
|
||||
this.applyFn = function () {
|
||||
|
||||
this.xEvent.pub.reset();
|
||||
this.xEvent.sub.reset();
|
||||
this.xNotify.set.reset();
|
||||
this.xNotification.set.reset();
|
||||
|
||||
return this.definition.fn(_, this.xModernizr, this.xEvent, this.xNotify, this.xSettings);
|
||||
return this.definition.fn(_, this.xModernizr, this.xEvent, this.xSettings, this.xNotification);
|
||||
};
|
||||
});
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
(function () {
|
||||
'use strict';
|
||||
|
||||
var ID = 'core/notify';
|
||||
var ID = 'view/notification';
|
||||
var DEPS = ['$'];
|
||||
|
||||
describe('module \'' + ID + '\'', function () {
|
||||
|
@ -71,9 +71,9 @@ describe('module \'' + ID + '\'', function () {
|
|||
it('adds HTML', function () {
|
||||
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#notify'), 1);
|
||||
assert.lengthOf($('#notify:visible'), 0);
|
||||
assert.strictEqual($('#notify').text(), '');
|
||||
assert.lengthOf($('#notification'), 1);
|
||||
assert.lengthOf($('#notification:visible'), 0);
|
||||
assert.strictEqual($('#notification').text(), '');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -90,20 +90,20 @@ describe('module \'' + ID + '\'', function () {
|
|||
var instance = this.applyFn();
|
||||
|
||||
instance.set();
|
||||
assert.lengthOf($('#notify:visible'), 0);
|
||||
assert.strictEqual($('#notify').text(), '');
|
||||
assert.lengthOf($('#notification:visible'), 0);
|
||||
assert.strictEqual($('#notification').text(), '');
|
||||
|
||||
instance.set('hello');
|
||||
assert.lengthOf($('#notify:visible'), 1);
|
||||
assert.strictEqual($('#notify').text(), 'hello');
|
||||
assert.lengthOf($('#notification:visible'), 1);
|
||||
assert.strictEqual($('#notification').text(), 'hello');
|
||||
|
||||
instance.set('world');
|
||||
assert.lengthOf($('#notify:visible'), 1);
|
||||
assert.strictEqual($('#notify').text(), 'world');
|
||||
assert.lengthOf($('#notification:visible'), 1);
|
||||
assert.strictEqual($('#notification').text(), 'world');
|
||||
|
||||
instance.set();
|
||||
// assert.lengthOf($('#notify:visible'), 0);
|
||||
assert.strictEqual($('#notify').text(), 'world');
|
||||
// assert.lengthOf($('#notification:visible'), 0);
|
||||
assert.strictEqual($('#notification').text(), 'world');
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue