forked from Stanford-Online/xblock-image-modal
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e8d7a2f
commit 874a322
Showing
18 changed files
with
914 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
""" | ||
A fullscreen, zooming image modal XBlock | ||
""" | ||
from .xblocks import ImageModal |
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,3 @@ | ||
""" | ||
Mixin behavior to XBlocks | ||
""" |
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,90 @@ | ||
""" | ||
Mixin fragment/html behavior into XBlocks | ||
Note: We should resume test coverage for all lines in this file once | ||
split into its own library. | ||
""" | ||
from django.template.context import Context | ||
from xblock.core import XBlock | ||
from xblock.fragment import Fragment | ||
|
||
|
||
class XBlockFragmentBuilderMixin: | ||
""" | ||
Create a default XBlock fragment builder | ||
""" | ||
static_css = [ | ||
'view.css', | ||
] | ||
static_js = [ | ||
'view.js', | ||
] | ||
static_js_init = None | ||
template = 'view.html' | ||
|
||
def provide_context(self, context): # pragma: no cover | ||
""" | ||
Build a context dictionary to render the student view | ||
This should generally be overriden by child classes. | ||
""" | ||
context = context or {} | ||
context = dict(context) | ||
return context | ||
|
||
@XBlock.supports('multi_device') | ||
def student_view(self, context=None): | ||
""" | ||
Build the fragment for the default student view | ||
""" | ||
template = self.template | ||
context = self.provide_context(context) | ||
static_css = self.static_css or [] | ||
static_js = self.static_js or [] | ||
js_init = self.static_js_init | ||
fragment = self.build_fragment( | ||
template=template, | ||
context=context, | ||
css=static_css, | ||
js=static_js, | ||
js_init=js_init, | ||
) | ||
return fragment | ||
|
||
def build_fragment( | ||
self, | ||
template='', | ||
context=None, | ||
css=None, | ||
js=None, | ||
js_init=None, | ||
): | ||
""" | ||
Creates a fragment for display. | ||
""" | ||
context = context or {} | ||
css = css or [] | ||
js = js or [] | ||
rendered_template = '' | ||
if template: # pragma: no cover | ||
template = 'templates/' + template | ||
rendered_template = self.loader.render_django_template( | ||
template, | ||
context=Context(context), | ||
i18n_service=self.runtime.service(self, 'i18n'), | ||
) | ||
fragment = Fragment(rendered_template) | ||
for item in css: | ||
if item.startswith('/'): | ||
url = item | ||
else: | ||
item = 'public/' + item | ||
url = self.runtime.local_resource_url(self, item) | ||
fragment.add_css_url(url) | ||
for item in js: | ||
item = 'public/' + item | ||
url = self.runtime.local_resource_url(self, item) | ||
fragment.add_javascript_url(url) | ||
if js_init: # pragma: no cover | ||
fragment.initialize_js(js_init) | ||
return fragment |
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,72 @@ | ||
""" | ||
Mixin workbench behavior into XBlocks | ||
""" | ||
from glob import glob | ||
import pkg_resources | ||
|
||
|
||
def _read_file(file_path): | ||
""" | ||
Read in a file's contents | ||
""" | ||
with open(file_path, encoding='utf-8') as file_input: | ||
file_contents = file_input.read() | ||
return file_contents | ||
|
||
|
||
def _parse_title(file_path): | ||
""" | ||
Parse a title from a file name | ||
""" | ||
title = file_path | ||
title = title.split('/')[-1] | ||
title = '.'.join(title.split('.')[:-1]) | ||
title = ' '.join(title.split('-')) | ||
title = ' '.join([ | ||
word.capitalize() | ||
for word in title.split(' ') | ||
]) | ||
return title | ||
|
||
|
||
def _read_files(files): | ||
""" | ||
Read the contents of a list of files | ||
""" | ||
file_contents = [ | ||
( | ||
_parse_title(file_path), | ||
_read_file(file_path), | ||
) | ||
for file_path in files | ||
] | ||
return file_contents | ||
|
||
|
||
def _find_files(directory): | ||
""" | ||
Find XML files in the directory | ||
""" | ||
pattern = "{directory}/*.xml".format( | ||
directory=directory, | ||
) | ||
files = glob(pattern) | ||
return files | ||
|
||
|
||
class XBlockWorkbenchMixin: | ||
""" | ||
Provide a default test workbench for the XBlock | ||
""" | ||
|
||
@classmethod | ||
def workbench_scenarios(cls): | ||
""" | ||
Gather scenarios to be displayed in the workbench | ||
""" | ||
module = cls.__module__ | ||
module = module.split('.', maxsplit=1)[0] | ||
directory = pkg_resources.resource_filename(module, 'scenarios') | ||
files = _find_files(directory) | ||
scenarios = _read_files(files) | ||
return scenarios |
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,70 @@ | ||
""" | ||
Handle data access logic for the XBlock | ||
""" | ||
from django.utils.translation import gettext_lazy as _ | ||
from xblock.fields import Scope | ||
from xblock.fields import String | ||
|
||
|
||
class ImageModalModelMixin: | ||
""" | ||
Handle data access for Image Modal XBlock instances | ||
""" | ||
|
||
editable_fields = [ | ||
'display_name', | ||
'image_url', | ||
'thumbnail_url', | ||
'description', | ||
'alt_text', | ||
] | ||
|
||
show_in_read_only_mode = True | ||
|
||
display_name = String( | ||
display_name=_('Display Name'), | ||
default='Image Modal XBlock', | ||
scope=Scope.settings, | ||
help=_("This is the XBlock's display name"), | ||
) | ||
|
||
image_url = String( | ||
display_name=_('Image URL'), | ||
default=( | ||
'http://upload.wikimedia.org/' | ||
'wikipedia/commons/4/48/' | ||
'1853_Kaei_6_Japanese_Map_of_the_World_-_' | ||
'Geographicus_-_ChikyuBankokuHozu-nakajima-1853.jpg' | ||
), | ||
scope=Scope.settings, | ||
help=_( | ||
'This is the location of the full-screen image to be displayed.' | ||
), | ||
) | ||
|
||
thumbnail_url = String( | ||
display_name=_('Thumbnail URL'), | ||
default='', | ||
scope=Scope.settings, | ||
help=_( | ||
'This is the (optional) location of a thumbnail image to be ' | ||
'displayed before the main image has been enlarged.' | ||
), | ||
) | ||
|
||
description = String( | ||
display_name=_('Description'), | ||
default='', | ||
scope=Scope.settings, | ||
help=_('Description text, displayed to screen readers'), | ||
multiline_editor=True, | ||
) | ||
|
||
alt_text = String( | ||
display_name=_('Alt Text'), | ||
default='', | ||
scope=Scope.settings, | ||
help=_( | ||
'This field allows you to add alternate or descriptive text that pertains to your image.' | ||
), | ||
) |
Large diffs are not rendered by default.
Oops, something went wrong.
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,89 @@ | ||
.imagemodal_block P { | ||
cursor: pointer; | ||
} | ||
.imagemodal_block IMG { | ||
max-width: 100%; | ||
} | ||
.imagemodal_block A, | ||
.imagemodal_block BUTTON { | ||
cursor: pointer; | ||
} | ||
.imagemodal_block BUTTON { | ||
border: 2px solid #2e2d29; | ||
background: #fbfbf9; | ||
color: #2e2d29; | ||
border-radius: 5px; | ||
cursor: pointer; | ||
opacity: 0.9; | ||
padding: 5px 7px 7px; | ||
font-weight: bold; | ||
font-size: 1em; | ||
} | ||
.imagemodal_block BUTTON I { | ||
font-style: normal; | ||
} | ||
.imagemodal_block .close { | ||
position: absolute; | ||
top: 10px; | ||
right: 10px; | ||
} | ||
.imagemodal_block .zoom { | ||
position: absolute; | ||
bottom: 10px; | ||
right: 10px; | ||
} | ||
.imagemodal_block .fullscreen { | ||
position: absolute; | ||
top: 10px; | ||
left: 10px; | ||
} | ||
.imagemodal_block .wrapper { | ||
position: relative; | ||
} | ||
.imagemodal_block .count { | ||
font-weight: bold; | ||
} | ||
.imagemodal_block .curtain { | ||
display: none; | ||
position: fixed; | ||
width: 100%; | ||
height: 100%; | ||
top: 0; | ||
left: 0; | ||
background-color: #000; | ||
background-color: rgba(0, 0, 0, 0.7); | ||
cursor: no-drop; | ||
/* | ||
Override LMS's sequence-nav (z-index: 99;) | ||
and modal-backdrop (z-index: 1000;) | ||
*/ | ||
z-index: 1001; | ||
} | ||
.imagemodal_block .curtain .mask { | ||
height: 95%; | ||
width: 95%; | ||
margin: auto; | ||
overflow: hidden; | ||
position: relative; | ||
top: 2.5%; | ||
} | ||
.imagemodal_block .curtain .mask .wrapper { | ||
height: 100%; | ||
width: 100%; | ||
top: 0; | ||
left: 0; | ||
position: relative; | ||
} | ||
.imagemodal_block .curtain .mask .wrapper IMG { | ||
display: block; | ||
margin: auto; | ||
max-height: 100%; | ||
max-width: 100%; | ||
position: relative; | ||
cursor: zoom-in; | ||
} | ||
.imagemodal_block .curtain .mask .wrapper .zoomed { | ||
max-height: none; | ||
max-width: none; | ||
cursor: move; | ||
} |
Oops, something went wrong.