-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Draft preliminary interactive article linking
- Loading branch information
Showing
9 changed files
with
407 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
let JointSourcesHandler = Handler.createComponent("JointSourcesHandler"); | ||
|
||
JointSourcesHandler.defineAlias("content", "jointSources"); | ||
|
||
JointSourcesHandler.defineMethod("init", function init(content = []) { | ||
return [content]; | ||
}); | ||
|
||
JointSourcesHandler.defineMethod("add", function (jointSource) { | ||
if (this.jointSources.indexOf(jointSource) < 0) { | ||
this.jointSources.push(jointSource); | ||
} | ||
}); | ||
|
||
JointSourcesHandler.defineMethod("remove", function (jointSource) { | ||
let index = this.jointSources.indexOf(jointSource); | ||
if (index > -1) { | ||
this.jointSources.splice(index, 1); | ||
} | ||
}); | ||
|
||
JointSourcesHandler.defineMethod("toggle", function (jointSource) { | ||
let index = this.jointSources.indexOf(jointSource); | ||
if (index > -1) { | ||
this.jointSources.splice(index, 1); | ||
return false; | ||
} | ||
this.jointSources.push(jointSource); | ||
return true; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
|
||
let JointSourcePromptController = PromptController.createComponent("JointSourcePromptController"); | ||
|
||
JointSourcePromptController.createViewFragment = function () { | ||
return cloneTemplate("#template-prompt-jointsource"); | ||
}; | ||
|
||
JointSourcePromptController.defineMethod("initView", function initView() { | ||
if (!this.view) return; | ||
|
||
this.jointSourcesHandler = new JointSourcesHandler(); | ||
|
||
// Explore | ||
|
||
// Conversations | ||
|
||
this.exploreConversations = new Explore(); | ||
new ExploreJointSourceSelectionController( | ||
this.exploreConversations, | ||
this.view.querySelector("[data-ica-subview='conversations'] .explore") | ||
).componentOf = this; | ||
|
||
ICA.getConversations() | ||
.then(function (conversations) { | ||
this.exploreConversations.requestNext = conversations.requestNext; | ||
this.exploreConversations.addItems(conversations); | ||
this.exploreConversations.didUpdate(); | ||
}.bind(this), function (err) { | ||
console.warn(err); | ||
}); | ||
|
||
// Discussions | ||
|
||
this.exploreDiscussions = new Explore(); | ||
new ExploreJointSourceSelectionController( | ||
this.exploreDiscussions, | ||
this.view.querySelector("[data-ica-subview='discussions'] .explore") | ||
).componentOf = this; | ||
|
||
ICA.getDiscussions() | ||
.then(function (discussions) { | ||
this.exploreDiscussions.requestNext = discussions.requestNext; | ||
this.exploreDiscussions.addItems(discussions); | ||
this.exploreDiscussions.didUpdate(); | ||
}.bind(this), function (err) { | ||
console.warn(err); | ||
}); | ||
|
||
// Pagination | ||
|
||
new Routine(function () { | ||
this.view.querySelectorAll(".conversations, .discussions").forEach(function (element) { | ||
if (element.hidden) return; | ||
element = element.querySelector(".explore"); | ||
|
||
let rect = element.getBoundingClientRect(); | ||
let explore = element.controller.explore; | ||
|
||
if (rect.bottom < 2 * document.body.offsetHeight | ||
&& explore.requestNext) { | ||
// Need to load more content | ||
|
||
console.count("Need to load more"); | ||
let requestNext = explore.requestNext; | ||
explore.requestNext = undefined; | ||
|
||
requestNext() | ||
.then(function (conversations) { | ||
explore.requestNext = conversations.requestNext; | ||
explore.addItems(conversations); | ||
explore.didUpdate(); | ||
}.bind(element), function (err) { | ||
if (err instanceof ICA.APIResponse.EndOfResponse) { | ||
// End of response | ||
console.log("AppJointSourcesController: End of response"); | ||
} else { | ||
// Critical error | ||
console.error(err.message); | ||
} | ||
}); | ||
|
||
element.classList.toggle("loading", true); | ||
} else { | ||
element.classList.toggle("loading", false); | ||
} | ||
}); | ||
}.bind(this), 500, true) | ||
.componentOf = this; | ||
|
||
// View selection | ||
|
||
this.view.querySelectorAll("[data-ica-for-subview]").forEach(function (element) { | ||
let subview = getElementProperty(element, "for-subview"); | ||
|
||
element.addEventListener("click", function () { | ||
event.preventDefault(); | ||
|
||
this.querySelectorAll("[data-ica-for-subview]").forEach(function (element) { | ||
element.classList.toggle("active", getElementProperty(element, "for-subview") === subview); | ||
}); | ||
|
||
this.querySelectorAll("[data-ica-subview]").forEach(function (element) { | ||
element.hidden = getElementProperty(element, "subview") !== subview; | ||
}); | ||
}.bind(this.view)); | ||
}.bind(this)); | ||
|
||
// Use first one as default | ||
this.view.querySelector("[data-ica-for-subview]").click(); | ||
|
||
}); | ||
|
||
/***/ | ||
|
||
function promptJointSourceSelection() { | ||
return new Promise(function (resolve, reject) { | ||
let prompt = new Prompt([ | ||
new PromptAction( | ||
"Cancel", | ||
function () { | ||
resolve([]); | ||
} | ||
), | ||
new PromptAction( | ||
"Select", | ||
function () { | ||
resolve(controller.jointSourcesHandler.jointSources); | ||
}, | ||
true | ||
) | ||
]); | ||
|
||
let fragment = JointSourcePromptController.createViewFragment(); | ||
let element = fragment.querySelector(".prompt"); | ||
document.body.appendChild(fragment); | ||
let controller = new JointSourcePromptController(prompt, element); | ||
}); | ||
} |
78 changes: 78 additions & 0 deletions
78
scripts/prompts/explore/ExploreJointSourceSelectionController.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
|
||
let ExploreJointSourceSelectionController = SingleModelController.createComponent("ExploreJointSourceSelectionController"); | ||
|
||
ExploreJointSourceSelectionController.defineAlias("model", "explore"); | ||
|
||
ExploreJointSourceSelectionController.defineMethod("initView", function initView() { | ||
if (!this.view) return; | ||
|
||
this.viewItems = []; | ||
|
||
setElementProperty(this.view, "explore-id", this.explore.exploreId); | ||
}); | ||
|
||
ExploreJointSourceSelectionController.defineMethod("updateView", function updateView() { | ||
if (!this.view) return; | ||
|
||
this.viewItems = this.viewItems.filter(function (item) { | ||
if (this.explore.items.indexOf(item) > -1) return true; | ||
|
||
var element = this.view.querySelector("[data-ica-jointsource-id='{0}']".format(item.jointSourceId)); | ||
if (element) { | ||
element.controller.destroy(true); | ||
} | ||
|
||
return false; | ||
}.bind(this)); | ||
|
||
this.explore.items.forEach(function (item) { | ||
|
||
let Controller; | ||
switch (item.constructor) { | ||
case Conversation: Controller = ExploreConversationController; break; | ||
case Discussion: Controller = ExploreDiscussionController; break; | ||
default: | ||
console.warn("Unhandled item:", item.constructor); | ||
return; | ||
} | ||
|
||
let element = this.view.querySelector("[data-ica-jointsource-id='{0}']".format(item.jointSourceId)); | ||
|
||
// Check existing element | ||
if (!element) { | ||
|
||
// Create new view | ||
let fragment = Controller.createViewFragment(); | ||
element = fragment.querySelector(".jointsource"); | ||
this.view.appendChild(fragment); | ||
|
||
// Add event listener beforehand to so the controller would have a lower priority | ||
element.addEventListener("click", function () { | ||
event.preventDefault(); | ||
event.stopImmediatePropagation(); | ||
|
||
// Toggle selection | ||
if (this.componentOf) { | ||
let selected = this.componentOf.jointSourcesHandler.toggle(item); | ||
element.classList.toggle("selected", selected); | ||
} | ||
|
||
}.bind(this)); | ||
|
||
let controller = new Controller(item, element); | ||
controller.componentOf = this; | ||
|
||
this.viewItems.push(item); | ||
|
||
} | ||
|
||
// element.classList.toggle("selected", !!this.componentOf.pinnedRefereeJointSources[item.jointSourceId]); | ||
|
||
}.bind(this)); | ||
}); | ||
|
||
ExploreJointSourceSelectionController.defineMethod("uninitView", function initView() { | ||
if (!this.view) return; | ||
|
||
delete this.viewItems; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -389,6 +389,7 @@ | |
border: solid 1px rgba(#000, 0.10); | ||
border-radius: 50%; | ||
@include shadow(3); | ||
z-index: 2; | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.