Commit 872cff11 authored by Sean Hammond's avatar Sean Hammond

Rename several variables to isSidebar

Replace `isSidebar`, `isEmbedded`, `annotation-embedded`, `annotationEmbedded`
and `embedded` with a single `isSidebar` variable.

- Rename `isEmbedded` in AppController to `isSidebar`.

- Rename `embedded` in AnnotationController to `isSidebar`, it just passes the
value of `AppController`'s `isSidebar` into `annotation.html`.

- Rename the `annotation-embedded`/`annotationEmbedded` variable that is used
to pass `isSidebar` (was `isEmbedded`) into `AnnotationController`,
rename it to `is-sidebar` / `isSidebar`.

- Delete the duplicate `isSidebar` variable from `WidgetController`'s scope,
`WidgetController`'s templates can simply access `AppController`'s `isSidebar`
from the scope.

Note that there's another variable, `isStream`, that's actually true when we're
either in the sidebar or on the stream page, but not when we're on individual
annotation pages. This is used to show/hide the
"Sorted by newest, oldest, location" menu which appears in the sidebar or
stream but not on individual annotation pages (the "location" option in this
menu only appears when in the sidebar not on the stream).

This commit leaves the `isStream` variable alone.

So the `isSidebar` variable is now used to show/hide the following elements:

- The share dialog (share this page on twitter etc) is shown in the top bar,
only when in the sidebar (and not on the `/stream` page or on individual
annotation pages).

- The group list dropdown menu, shown in the top bar only when in the sidebar.

- The "location" entry in the sort menu (sorted by newest, oldest, location)
shown only when in the sidebar.

- The "citation" on annotations that says which page was annotated
(the 'on "Example Document" (example.com)' in the annotation's title),
is shown only when _not_ in the sidebar.
parent 389113ad
......@@ -32,8 +32,9 @@ module.exports = class AppController
$scope.accountDialog = visible: false
$scope.shareDialog = visible: false
# Check to see if we are on the stream page so we can hide share button.
$scope.isEmbedded = $window.top isnt $window
# Check to see if we're in the sidebar, or on a standalone page such as
# the stream page or an individual annotation page.
$scope.isSidebar = $window.top isnt $window
# Default sort
$scope.sort = name: 'Location'
......
......@@ -32,7 +32,8 @@ errorMessage = (reason) ->
# @property {string} action One of 'view', 'edit', 'create' or 'delete'.
# @property {string} preview If previewing an edit then 'yes', else 'no'.
# @property {boolean} editing True if editing components are shown.
# @property {boolean} embedded True if the annotation is an embedded widget.
# @property {boolean} isSidebar True if we are in the sidebar (not on the
# stream page or an individual annotation page)
#
# @description
#
......@@ -53,7 +54,7 @@ AnnotationController = [
@document = null
@preview = 'no'
@editing = false
@embedded = false
@isSidebar = false
@hasDiff = false
@showDiff = undefined
@timestamp = null
......@@ -402,17 +403,14 @@ AnnotationController = [
# Directive that instantiates
# {@link annotation.AnnotationController AnnotationController}.
#
# If the `annotation-embbedded` attribute is specified, its interpolated
# value is used to signal whether the annotation is being displayed inside
# an embedded widget.
###
module.exports = [
'$document',
($document) ->
linkFn = (scope, elem, attrs, [ctrl, thread, threadFilter, counter]) ->
# Observe the embedded attribute
attrs.$observe 'annotationEmbedded', (value) ->
ctrl.embedded = value? and value != 'false'
# Observe the isSidebar attribute
attrs.$observe 'isSidebar', (value) ->
ctrl.isSidebar = value? and value != 'false'
# Save on Meta + Enter or Ctrl + Enter.
elem.on 'keydown', (event) ->
......
......@@ -83,18 +83,18 @@ describe 'AppController', ->
afterEach ->
sandbox.restore()
describe 'isEmbedded property', ->
describe 'isSidebar property', ->
it 'is false if the window is the top window', ->
$window = {}
$window.top = $window
createController({$window})
assert.isFalse($scope.isEmbedded)
assert.isFalse($scope.isSidebar)
it 'is true if the window is not the top window', ->
$window = {top: {}}
createController({$window})
assert.isTrue($scope.isEmbedded)
assert.isTrue($scope.isSidebar)
it 'watches the identity service for identity change events', ->
createController()
......
......@@ -11,7 +11,6 @@ module.exports = class WidgetController
streamer, streamFilter, store, threading
) ->
$scope.isStream = true
$scope.isSidebar = true
$scope.threadRoot = threading.root
@chunkSize = 200
......
......@@ -28,11 +28,11 @@
<span class="annotation-citation"
ng-bind-html="vm.document | documentTitle"
ng-if="!vm.embedded">
ng-if="!vm.isSidebar">
</span>
<span class="annotation-citation-domain"
ng-bind-html="vm.document | documentDomain"
ng-if="!vm.embedded">
ng-if="!vm.isSidebar">
</span>
</span>
......
......@@ -14,7 +14,7 @@
<article class="annotation thread-message {{vm.collapsed && 'collapsed'}}"
name="annotation"
annotation="vm.container.message"
annotation-embedded="{{isEmbedded}}"
is-sidebar="{{isSidebar}}"
annotation-show-reply-count="{{vm.shouldShowNumReplies()}}"
annotation-reply-count="{{vm.numReplies()}}"
annotation-reply-count-click="vm.toggleCollapsed()"
......
......@@ -27,7 +27,7 @@
</span>
<ul class="dropdown-menu pull-right" role="menu">
<li ng-click="sort.name = option"
ng-hide="option == 'Location' && !isEmbedded"
ng-hide="option == 'Location' && !isSidebar"
ng-repeat="option in ['Newest', 'Oldest', 'Location']"
><a href="">{{option}}</a></li>
</ul>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment