Skip to content

Commit

Permalink
Merge branch 'GPII-3154'
Browse files Browse the repository at this point in the history
* GPII-3154:
  GPII-3154: Added the build as a postinstall step.
  GPII-3154: Generating a unique prefix to use with id's.
  GPII-3154: Using infusion-all.js for tests.
  GPII-3154: Modifying check for keysToFilter
  GPII-3154: Fixing comment
  GPII-3154: Refactored message posting structure, and caption disabling.
  GPII-3154: Inject scripts in order.
  GPII-3154: Removing commented out code.
  GPII-3154: Updating readme info to include captions as a preference.
  GPII-3154: Touching up captions integration and tests.
  GPII-3154: In progress captions integration.
  GPII-3154: removing package-lock.json
  • Loading branch information
amb26 committed Aug 13, 2018
2 parents f05d12e + 76785a5 commit 8315457
Show file tree
Hide file tree
Showing 24 changed files with 930 additions and 112 deletions.
40 changes: 31 additions & 9 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,24 @@ module.exports = function (grunt) {
"node_modules/infusion/src/framework/core/js/ModelTransformation.js",
"node_modules/infusion/src/framework/core/js/ModelTransformationTransforms.js"
],

webScriptsLib: [
"node_modules/infusion/src/lib/jquery/core/js/jquery.js",
"node_modules/infusion/src/framework/core/js/Fluid.js",
"node_modules/infusion/src/framework/core/js/FluidPromises.js",
"node_modules/infusion/src/framework/core/js/FluidDocument.js",
"node_modules/infusion/src/framework/core/js/FluidDOMUtilities.js",
"node_modules/infusion/src/framework/core/js/FluidIoC.js",
"node_modules/infusion/src/framework/core/js/DataBinding.js",
"node_modules/infusion/src/framework/core/js/FluidView.js",
"node_modules/infusion/src/framework/core/js/FluidRequests.js",
"node_modules/infusion/src/lib/fastXmlPull/js/fastXmlPull.js",
"node_modules/infusion/src/framework/renderer/js/fluidParser.js",
"node_modules/infusion/src/framework/enhancement/js/ContextAwareness.js",
"node_modules/infusion/src/framework/enhancement/js/ProgressiveEnhancement.js",
"node_modules/infusion/src/framework/preferences/js/Enactors.js",
"node_modules/infusion/src/framework/preferences/js/CaptionsEnactor.js",
"extension/src/lib/captionsEnactor.js"
],
contentScriptsLib: [
"node_modules/infusion/src/lib/jquery/core/js/jquery.js",
"node_modules/infusion/src/framework/core/js/Fluid.js",
Expand Down Expand Up @@ -55,7 +72,8 @@ module.exports = function (grunt) {
"node_modules/infusion/src/components/textToSpeech/js/TextToSpeech.js",
"node_modules/infusion/src/components/orator/js/Orator.js",
"node_modules/infusion/src/framework/preferences/js/SelfVoicingEnactor.js",
"node_modules/infusion/src/framework/preferences/js/LetterSpaceEnactor.js"
"node_modules/infusion/src/framework/preferences/js/LetterSpaceEnactor.js",
"node_modules/infusion/src/framework/preferences/js/CaptionsEnactor.js"
],
adjustersLib: [
// jQuery
Expand Down Expand Up @@ -100,8 +118,10 @@ module.exports = function (grunt) {
"node_modules/infusion/src/framework/preferences/js/Panels.js",
"node_modules/infusion/src/framework/preferences/js/SelfVoicingPanel.js",
"node_modules/infusion/src/framework/preferences/js/LetterSpacePanel.js",
"node_modules/infusion/src/framework/preferences/js/CaptionsPanel.js",
"node_modules/infusion/src/framework/preferences/js/Enactors.js",
"node_modules/infusion/src/framework/preferences/js/LetterSpaceEnactor.js",
"node_modules/infusion/src/framework/preferences/js/CaptionsEnactor.js",
"node_modules/infusion/src/framework/preferences/js/StarterGrades.js",
"node_modules/infusion/src/framework/preferences/js/ArrowScrolling.js",
"node_modules/infusion/src/framework/preferences/js/SeparatedPanelPrefsEditor.js",
Expand All @@ -111,6 +131,7 @@ module.exports = function (grunt) {
"node_modules/infusion/src/framework/preferences/js/StarterSchemas.js",
"node_modules/infusion/src/framework/preferences/js/SelfVoicingSchemas.js",
"node_modules/infusion/src/framework/preferences/js/LetterSpaceSchemas.js",
"node_modules/infusion/src/framework/preferences/js/CaptionsSchemas.js",
"node_modules/infusion/src/framework/preferences/js/Builder.js",

// from extension
Expand All @@ -120,13 +141,7 @@ module.exports = function (grunt) {
],
templates: [
"node_modules/infusion/src/components/tableOfContents/html/TableOfContents.html",
"node_modules/infusion/src/framework/preferences/html/PrefsEditorTemplate-textSize.html",
"node_modules/infusion/src/framework/preferences/html/PrefsEditorTemplate-lineSpace.html",
"node_modules/infusion/src/framework/preferences/html/PrefsEditorTemplate-letterSpace.html",
"node_modules/infusion/src/framework/preferences/html/PrefsEditorTemplate-contrast.html",
"node_modules/infusion/src/framework/preferences/html/PrefsEditorTemplate-layout.html",
"node_modules/infusion/src/framework/preferences/html/PrefsEditorTemplate-enhanceInputs.html",
"node_modules/infusion/src/framework/preferences/html/PrefsEditorTemplate-speak.html"
"node_modules/infusion/src/framework/preferences/html/PrefsEditorTemplate-*.html"
],
messages: [
"node_modules/infusion/src/framework/preferences/messages/*.json"
Expand Down Expand Up @@ -185,6 +200,9 @@ module.exports = function (grunt) {
files.extensionLib,
files.extension
),
"dist/<%= pkg.name %>-webScriptsLib.min.js" : [].concat(
files.webScriptsLib
),
"dist/<%= pkg.name %>-contentScriptsLib.min.js" : [].concat(
files.contentScriptsLib
),
Expand Down Expand Up @@ -222,6 +240,10 @@ module.exports = function (grunt) {
src: ["extension/src/lib/adjusterScriptLoader.js"],
dest: "build/src/adjusterScriptLoader.js"
},
{
src: ["extension/src/lib/captionsEnactor.js"],
dest: "build/src/captionsEnactor.js"
},
{
expand: true,
cwd: "extension/css/",
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The following adaptations are supported:
* Reading Mode
* Table of Contents
* Enhance Inputs
* Captions (embedded YouTube videos)

_**Note**: The ability to apply an adaptation will vary from page to page_

Expand Down
10 changes: 6 additions & 4 deletions extension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 2,
"name": "UI Options Plus (UIO+)",
"short_name": "UIO+",
"version": "0.1.0.4",
"version": "0.1.0.5",
"description": "User Interface Options Plus (UIO+) allows you to customize websites to match your own personal needs and preferences.",
"author": "Fluid Project",
"permissions": [
Expand Down Expand Up @@ -43,8 +43,9 @@
"all_frames": true
}, {
"matches": ["<all_urls>"],
"exclude_globs": ["https://www.youtube.com/embed/*"],
"js": [
"content_scripts/fontInjection.js",
"content_scripts/webInjection.js",
"content_scripts/utils.js",
"content_scripts/simplification.js",
"content_scripts/domEnactor.js",
Expand All @@ -62,11 +63,12 @@
"src/background.js"
]
},
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'",
"content_security_policy": "script-src 'self' https://youtube.com https://ytimg.com; object-src 'self'",
"web_accessible_resources": [
"images/gpii.png",
"templates/TableOfContents.html",
"fonts/Orator-Icons.ttf",
"fonts/Orator-Icons.eot"
"fonts/Orator-Icons.eot",
"src/captionsEnactor.js"
]
}
6 changes: 6 additions & 0 deletions extension/messages/ytCaptions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"label": "youtube Captions",
"description": "Request embedded YouTube videos to display captions.",
"switchOn": "ON",
"switchOff": "OFF"
}
61 changes: 53 additions & 8 deletions extension/src/content_scripts/domEnactor.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"onIncomingSettings.updateModel": {
changePath: "",
value: "{arguments}.0"
}
},
"onIncomingSettings.postSettingsToWebPage": "{that}.postSettingsToWebPage"
},
contextAwareness: {
simplify: {
Expand All @@ -50,6 +51,23 @@
}
}
},
webSettings: {
type: "gpii.chrome.domEnactor",
filter: {
keys: ["captionsEnabled"],
exclude: false
}
},
invokers: {
postSettingsToWebPage: {
funcName: "gpii.chrome.domEnactor.postSettingsToWebPage",
args: [
"{that}.options.webSettings.type",
"{arguments}.0",
{filter: "{that}.options.webSettings.filter"}
]
}
},
distributeOptions: {
record: "{that}.container",
target: "{that > fluid.prefs.enactor}.container"
Expand Down Expand Up @@ -115,6 +133,40 @@
}
});

gpii.chrome.domEnactor.bindPortEvents = function (that) {
that.port = chrome.runtime.connect({name: "domEnactor-" + that.id});
that.port.onMessage.addListener(function (data) {
that.events.onIncomingSettings.fire(data.settings);
});
};

/**
* Posts a message to the webpage allowing for communication from the content script to the
* web page context. This is typically used to pass the model values from the extension to
* related enactors running in the web page context.
*
* @param {String} type - the value of the "type" field stored in the message's data
* @param {Object} settings - the settings to post to the web page context
* @param {Object} options - optional directives for filtering the settings to be posted.
* this allows the removal of settings that are not handled by
* the web page context, allowing for the remainder to be kept
* private. Options take the following form:
* {filter: {keys: [array of keys], exclude: true/false}} The
* exclude option determines if the filter keys are removed (true)
* or included (false).
*/
gpii.chrome.domEnactor.postSettingsToWebPage = function (type, settings, options) {
var data = {
type: type
};
var keysToFilter = fluid.get(options, ["filter", "keys"]);
if (fluid.isArrayable(keysToFilter)) {
settings = fluid.filterKeys(settings, keysToFilter, options.filter.exclude);
}
data.payload = settings;
window.postMessage(data, "*");
};

fluid.defaults("gpii.chrome.domEnactor.simplify", {
components: {
simplify: {
Expand All @@ -128,13 +180,6 @@
}
});

gpii.chrome.domEnactor.bindPortEvents = function (that) {
that.port = chrome.runtime.connect({name: "domEnactor-" + that.id});
that.port.onMessage.addListener(function (data) {
that.events.onIncomingSettings.fire(data.settings);
});
};

// High contrast
fluid.defaults("gpii.chrome.enactor.contrast", {
gradeNames: ["fluid.prefs.enactor.contrast"],
Expand Down
41 changes: 0 additions & 41 deletions extension/src/content_scripts/fontInjection.js

This file was deleted.

67 changes: 67 additions & 0 deletions extension/src/content_scripts/webInjection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* GPII Chrome Extension for Google Chrome
*
* Copyright 2018 OCAD University
*
* Licensed under the New BSD license. You may not use this file except in
* compliance with this license.
*
* You may obtain a copy of the license at
* https://github.com/GPII/gpii-chrome-extension/blob/master/LICENSE.txt
*/

/* global fluid, gpii, chrome */
"use strict";

(function ($, fluid) {

fluid.registerNamespace("gpii.chrome.webInjection");

gpii.chrome.webInjection.fonts = [{
fontFamily: "Orator-Icons",
urls: [
chrome.runtime.getURL("fonts/Orator-Icons.ttf"),
chrome.runtime.getURL("fonts/Orator-Icons.eot")
]
}];

// Listed in the order the scripts will be injected into the page
gpii.chrome.webInjection.scripts = [
"https://www.youtube.com/iframe_api",
chrome.runtime.getURL("src/captionsEnactor.js")
];

gpii.chrome.webInjection.styleTemplate = "<style>@font-face {font-family: \"%fontFamily\"; src: %src;}</style>";

// inject fonts
fluid.each(gpii.chrome.webInjection.fonts, function (fontInfo) {
var urls = fluid.transform(fluid.makeArray(fontInfo.urls), function (url) {
return "url(\"" + url + "\")";
});

var info = {
fontFamily: fontInfo.fontFamily,
src: urls.join(",")
};

var styleElm = $(fluid.stringTemplate(gpii.chrome.webInjection.styleTemplate, info));

$("head").append(styleElm);
});

// inject scripts
fluid.each(gpii.chrome.webInjection.scripts, function (src) {
var existingScript = $("script[src=\"" + src + "\"]");

// if the script doesn't already exist on the page, inject it.
if (existingScript.length === 0) {
var script = $("<script>").attr("src", src);
$("script").eq(0).before(script);
}
});


})(jQuery, fluid);

// to allow for the pages own instance of jQuery
jQuery.noConflict();
16 changes: 13 additions & 3 deletions extension/src/lib/PrefsEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"preferences.fluid_prefs_speak": "settings.selfVoicingEnabled",
"preferences.gpii_chrome_prefs_simplify": "settings.simplifiedUiEnabled",
"preferences.gpii_chrome_prefs_highlight": "settings.selectionTheme",
"preferences.gpii_chrome_prefs_clickToSelect": "settings.clickToSelectEnabled"
"preferences.gpii_chrome_prefs_clickToSelect": "settings.clickToSelectEnabled",
"preferences.fluid_prefs_captions": "settings.captionsEnabled"
},
listeners: {
"onRead.transform": {
Expand Down Expand Up @@ -349,7 +350,7 @@
"type": "fluid.prefs.tableOfContents",
"panel": {
"type": "fluid.prefs.panel.layoutControls",
"container": ".flc-prefsEditor-layout-controls", // the css selector in the template where the panel is rendered
"container": ".flc-prefsEditor-layout-controls",
"template": "%templatePrefix/PrefsEditorTemplate-layout.html",
"message": "%messagePrefix/tableOfContents.json"
}
Expand All @@ -358,10 +359,19 @@
"type": "fluid.prefs.enhanceInputs",
"panel": {
"type": "fluid.prefs.panel.enhanceInputs",
"container": ".flc-prefsEditor-enhanceInputs", // the css selector in the template where the panel is rendered
"container": ".flc-prefsEditor-enhanceInputs",
"template": "%templatePrefix/PrefsEditorTemplate-enhanceInputs.html",
"message": "%messagePrefix/enhanceInputs.json"
}
},
"captions": {
"type": "fluid.prefs.captions",
"panel": {
"type": "fluid.prefs.panel.captions",
"container": ".flc-prefsEditor-captions",
"template": "%templatePrefix/PrefsEditorTemplate-captions.html",
"message": "%messagePrefix/ytCaptions.json"
}
}
}
});
Expand Down
Loading

0 comments on commit 8315457

Please sign in to comment.