jQuery Mobile 1st Edition Jon Reid - The ebook in PDF/DOCX format is available for instant download
jQuery Mobile 1st Edition Jon Reid - The ebook in PDF/DOCX format is available for instant download
com
https://ebookgate.com/product/jquery-mobile-1st-edition-jon-
reid/
OR CLICK BUTTON
DOWLOAD EBOOK
https://ebookgate.com/product/reid-s-read-alouds-2-rob-reid/
ebookgate.com
https://ebookgate.com/product/jquery-for-dummies-1st-edition-lynn-
beighley/
ebookgate.com
https://ebookgate.com/product/jquery-pocket-primer-oswald-campesato/
ebookgate.com
Head First jQuery Ryan Benedetti
https://ebookgate.com/product/head-first-jquery-ryan-benedetti/
ebookgate.com
https://ebookgate.com/product/learning-jquery-4th-edition-jonathan-
chaffer/
ebookgate.com
https://ebookgate.com/product/dunbar-1650-comwell-s-most-famous-
victory-by-stuart-reid-stuart-reid/
ebookgate.com
https://ebookgate.com/product/herbal-chinese-cooking-reid/
ebookgate.com
https://ebookgate.com/product/jquery-in-action-third-edition-bear-
bibeault/
ebookgate.com
www.it-ebooks.info
www.it-ebooks.info
Download from Wow! eBook <www.wowebook.com>
jQuery Mobile
www.it-ebooks.info
www.it-ebooks.info
www.it-ebooks.info
jQuery Mobile
Jon Reid
jQuery Mobile
by Jon Reid
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions
are also available for most titles (http://my.safaribooksonline.com). For more information, contact our
corporate/institutional sales department: (800) 998-9938 or [email protected].
Printing History:
June 2011: First Edition.
Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of
O’Reilly Media, Inc. jQuery Mobile, the image of the squirrel tree toad, and related trade dress are
trademarks of O’Reilly Media, Inc.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as
trademarks. Where those designations appear in this book, and O’Reilly Media, Inc. was aware of a
trademark claim, the designations have been printed in caps or initial caps.
While every precaution has been taken in the preparation of this book, the publisher and authors assume
no responsibility for errors or omissions, or for damages resulting from the use of the information con-
tained herein.
ISBN: 978-1-449-30668-7
[LSI]
1307713150
www.it-ebooks.info
Table of Contents
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix
3. Page Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Under The Hood: jQuery Plug-ins and Widgets 25
List Views 26
Basic List View 26
Advanced List Views 29
Under The Hood: Updating a List View 39
Toolbars 39
Navigation Bars 39
Positioning the Header and Footer 43
Buttons 44
Button Control Groups 46
Button Icons 47
v
www.it-ebooks.info
Form Elements 49
Accessing Form Elements with JavaScript 49
Checkboxes and Radio Buttons 50
Flip Toggle 52
Input Fields and Textareas 53
Search Fields 54
Select Menus 55
Sliders 59
Layout Grids 61
vi | Table of Contents
www.it-ebooks.info
Preface
Introduction
Mobile applications come in two basic flavors: native applications, which are compiled
programs that run natively on the device, and mobile web applications, which run
inside a web browser on the device.
Native applications get almost all of the press these days, especially given the financial
success of the iTunes App Store and the Android Market. And with good reason, as
native applications have many advantages: they are fast, have access to all of the power
of the platform they are built for, and so forth. However, native applications suffer from
one important limitation: they are not portable. If you want to make your application
available on multiple platforms, you either have to write it in multiple languages
(resulting in multiple code bases to maintain) or use a platform abstraction layer like
Titanium or PhoneGap.
Mobile web applications, on the other hand, are created in HTML, CSS, and JavaScript,
and run in the web browser on the mobile device. This means one code base to maintain,
but mobile web applications still need to account for variations in web browsers across
platforms.
Enter jQuery Mobile. Based on the popular jQuery JavaScript library, jQuery Mobile
is designed to create mobile web applications that function on a broad range of devices.
With jQuery Mobile, it is possible to quickly create mobile web applications that look
and behave consistently across all supported devices, and that have advanced user
interface capabilities. jQuery Mobile gives the developer a standard set of layouts, user
interface widgets, and interactions, as well as a rich API for applying and extending
them.
jQuery Mobile is not yet in production—as of this writing, it is in its Alpha 4 release,
with the beta coming soon.
Even so, the library already has a broad set of features and is remarkably stable. In fact,
I have already used it in one production project with great success, and if you review
posts on the jQuery Mobile forums, you’ll see that there are many people using jQuery
ix
www.it-ebooks.info
x | Preface
www.it-ebooks.info
Finally, this book assumes you are familiar with the technologies of the web: HTTP,
clients and servers, security, etc.
mined by context.
Preface | xi
www.it-ebooks.info
How to Contact Us
Please address comments and questions concerning this book to the publisher:
O’Reilly Media, Inc.
1005 Gravenstein Highway North
Sebastopol, CA 95472
800-998-9938 (in the United States or Canada)
707-829-0515 (international or local)
707-829-0104 (fax)
We have a web page for this book, where we list errata, examples, and any additional
information. You can access this page at:
http://www.oreilly.com/catalog/0636920020585
To comment or ask technical questions about this book, send email to:
[email protected]
For more information about our books, courses, conferences, and news, see our website
at http://www.oreilly.com.
Find us on Facebook: http://facebook.com/oreilly
Follow us on Twitter: http://twitter.com/oreillymedia
Watch us on YouTube: http://www.youtube.com/oreillymedia
xii | Preface
www.it-ebooks.info
Acknowledgments
I’d like to thank RJ Owen for volunteering to do the technical review of this book. His
honesty and encouragement helped make this book a success.
I also want to thank Juan Sanchez for providing suggestions for the “Under The Hood”
sections in the book.
The HTML development team at EffectiveUI patiently listened to me rave about jQuery
Mobile and obsess about this book: Aaron Congleton, Ryan McGinty, Kevin Bauman,
Shane Church, Tony Walt, and George Robison. Thanks, guys.
Preface | xiii
www.it-ebooks.info
www.it-ebooks.info
CHAPTER 1
Meet jQuery Mobile
jQuery Mobile is a set of jQuery plug-ins and widgets that aim to provide a cross-
platform API for creating mobile web applications. In terms of code implementation,
jQuery Mobile is very similar to jQuery UI, but while jQuery UI is focused on desktop
applications, jQuery Mobile is built with mobile devices in mind.
As of this writing, jQuery Mobile is still in its Alpha 4 release, with beta just around
the corner. There are still plenty of issues that are being fixed, but the jQuery Mobile
development team has said that they consider the library to be feature-complete for
their 1.0 release. Although the documentation is sparse, especially compared to the
extensive documentation for the jQuery project itself, the forums are very active.
Even so, many people are already using jQuery Mobile in production, which is a
testament not only to the stability and quality of the library, but of how easy it is to use.
1
www.it-ebooks.info
This includes everything you need to start building a jQuery Mobile application.
Next, we need to include some content. Content should be marked up semantically,
and since we’re using HTML 5, we have access to all of the new tags like header, footer,
section, nav, etc. We can mark up our content using those tags, or we simply block off
our content using div tags.
For our first example, we want to create a page in our application that is a self-contained
section, with a header, content area, and footer. (We’ll discuss the details of pages and
views in jQuery Mobile in the next chapter. For now, we’ll just focus on the simplest
case.) Using div-based markup, we would create something like what is shown in
Example 1-2.
Example 1-2. Old and busted: div-based markup
<div class="section" id="page1">
<div class="header"><h1>jQuery Mobile</h1></div>
<div class="content">
<p>First page!</p>
</div>
<div class="footer"><h1>O'Reilly</h1></div>
</div>
Or we can mark up the same content using the HTML 5 tags section, header, and
footer, as shown in Example 1-3.
jQuery Mobile will work with either markup style, though as we move forward in this
book, we will use the HTML 5 markup.
jQuery Mobile doesn’t need specific markup, but it does need us to indicate the roles
of the content areas somehow. To do this, jQuery Mobile uses a custom data- attribute:
data-role. Valid data-role values include page, header, content, and footer.
This is our first encounter with a custom data- attribute. jQuery Mobile uses them
extensively to designate functionality, layout, and behaviors. We’ll learn more about
them in later chapters, so for right now we’ll just focus on the data-role attribute.
Applying the appropriate data-role attributes, our HTML 5 markup would be written
as shown in Example 1-4.
That is all you need to do to create an application in jQuery Mobile. It will do all the
rest for you.
To view your new web application, you can run it locally in an HTML 5 capable browser
(such as Safari), as shown in Figure 1-1.
This will give you an idea of what it will look like and how it will perform, but to really
test the application you will need to view it in a mobile device.
You can use various emulators that come with the platform application development
SDKs, but the ideal way to test the application is to serve it via a web server and use a
mobile device to browse it. This will give you the best feel for how the application
behaves.
Throughout this book, we will be using screen shots from an iPhone, and our current
application is shown in Figure 1-2.
Adding another page is a simple matter of copying and pasting our code and changing
the id of the containing section and updating the content to reflect a new page, as
shown in Example 1-5.
Example 1-5. Adding a second page to the sample application
<section id="page2" data-role="page">
<header data-role="header"><h1>jQuery Mobile</h1></header>
<div class="content" data-role="content">
<p>Second page!</p>
</div>
<footer data-role="footer"><h1>O'Reilly</h1></footer>
</section>
Navigation between pages is simple: just add a link to your content area in the first
page of the application, as shown in Example 1-6.
Example 1-6. Adding a link to second page
<div class="content" data-role="content">
<p>First page!</p>
<p><a href="#page2">Go to the second page!</a></p>
</div>
Now when you refresh the application, you will see a link to tap, as shown in Figure 1-3.
Tapping the link will transition to the next screen. jQuery Mobile will automatically
handle the page transition animation, and will automatically provide a back button in
the header.
Tapping on the back button will return you to the previous page, and again jQuery
Mobile will automatically handle the page transition.
There you have it, your first jQuery Mobile application. It doesn’t do much, but it
should give you some insight into the simplicity of the framework. All you have to do
is mark up your content semantically and then designate roles, functionality, and
interactions using custom data- attributes. Then sit back and allow jQuery Mobile to
do all the work for you.
To use jqmData() to select all elements with a data-role="page", you would use
$(":jqmData(role='page')"). To select all elements with any custom data- attribute
within those selected pages, you could use $(":jqmData(role='page')").jqmData(role).
The jqmData() selector also automatically handles namespacing. Since jQuery Mobile
relies so heavily on data attributes, you should be able to apply a namespace to them
to avoid conflicts with other data attributes that won’t be used by jQuery Mobile. (For
example, instead of data-role="page", it could use data-namespace-role="page" where
namespace- is a configurable string.) By default, jQuery Mobile does not apply a name-
space, but it can be configured to do so using the $.mobile.ns configuration option (see
“Configuring jQuery Mobile” on page 88 in Chapter 5 for more information). If you
do configure a namespace, the jqmData() selector will automatically account for it.
There was an interesting discussion around adding the namespacing feature to jQuery
Mobile, which you can read over on the project’s GitHub at https://github.com/jquery/
jquery-mobile/issues/196.
CHAPTER 2
Application Structure and Navigation
Pages
As we saw in our first example, jQuery Mobile designates pages using the data-role
attribute. Behind the scenes, jQuery Mobile selects elements based on this attribute
and progressively enhances them, adding CSS classes, any needed markup, and event
management. This may seem like a complicated way of handling things—why not
simply have regular pages linked like you ordinarily would?—but this methodology
gives jQuery Mobile several important features:
Page Transitions
By handling pages as separate content areas in one document, jQuery Mobile can
create smooth page transitions, resulting in an overall “application-like” look and
feel.
Navigation Management
jQuery Mobile can automatically handle page navigation, providing features like
back buttons and deep linking.
Efficiency
Since resources are all contained in one file, the browser does not have to access
the network over and over again, as it would with smaller individual files. This will
help mitigate application slowness and battery drain on the mobile device. The
trade-off is that for a large application there could be an appreciable download
time for a large HTML page with many individual jQuery Mobile page views.
However, once the file is downloaded and ready, the behavior will be much faster
and will not necessarily be dependent on network access.
9
www.it-ebooks.info
Internal Pages
As we have already seen, we can mark discreet sections of content as pages within the
application with the data-role="page". These sections must be top-level siblings in the
document body; it is not possible to nest pages within one another. As shown in
Example 2-1, a single HTML document can have as many of these pages as desired.
Example 2-1. Multiple internal pages in one HTML document
<!-- begin first page -->
<section id="page1" data-role="page">
<header data-role="header"><h1>jQuery Mobile</h1></header>
<div data-role="content" class="content">
<p>First page!</p>
<p><a href="#page2">Go to Second Page</a></p>
</div>
<footer data-role="footer"><h1>O'Reilly</h1></footer>
</section>
<!-- end first page -->
jQuery Mobile will automatically handle page transitions, back buttons, etc., as the
user clicks through the resulting pages of the application (see Figures 2-1, 2-2, and 2-3).
Pages | 11
www.it-ebooks.info
External Pages
jQuery Mobile will also handle external pages as well. If you link to a separate page
instead of to an ID of a data-role="page" element within the current document, jQuery
Mobile will perform an asynchronous fetch of the requested page and integrate it into
the current document, allowing it to perform its page management functions.
jQuery Mobile will fetch the external page and search through it for the first element
marked with a data-role="page" attribute and insert that into the DOM of the origin
document. Any other content, including subsequent elements with data-role="page"
attributes, will be ignored.
If jQuery Mobile fails to retrieve the page, or if it retrieves the page but fails to find a
data-role="page" designated element, it will display an error message.
To add an external page to our previous example code, create a file called
“external.html” and include the markup shown in Example 2-2.
Example 2-2. External.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
</head>
<body>
</body>
</html>
To load the new page, simply add a link to it in the markup for the third page of our
application:
<!-- begin third page -->
<section id="page3" data-role="page">
<header data-role="header"><h1>jQuery Mobile</h1></header>
<div data-role="content" class="content">
<p>Third page!</p>
<p><a href="external.html">Go to external page</a></p>
</div>
<footer data-role="footer"><h1>O'Reilly</h1></footer>
</section>
<!-- end third page -->
This will produce the screen shown in Figure 2-4 on the third page of our application.
Pages | 13
www.it-ebooks.info
And when we tap the “Go to external page” link, jQuery Mobile will display the loading
dialog and attempt to fetch and insert the external.html page. If it succeeds, it will
display the page shown in Figure 2-5.
And it now becomes a part of the application and can be accessed from any other page
as if it were included in the original DOM.
When creating pages that will be loaded asynchronously, make sure you
do not introduce duplicate IDs into the original DOM.
Pages | 15
www.it-ebooks.info
Notice that the semantics of the markup hasn’t changed, all that happened was the
addition of ARIA attributes and CSS classes. Other more complex interface elements
(like list views) are more heavily enhanced, and jQuery Mobile will even modify
markup, usually by adding span or div tags.
It’s often useful to examine the alterations jQuery Mobile makes to your markup.
Unfortunately, most browsers limit their source view capabilities to just showing the
markup that was downloaded from the server, without any changes that might have
been made subsequently by JavaScript. Fortunately, most browsers have “view gener-
ated source” plug-ins or extensions. Firebug for Firefox, for example, has a view gen-
erated source capability, and there are similar extensions for Safari.
ui.nextPage will be either the page being transitioned to, or an empty jQuery object
if there is none.
pagebeforeshow
This event fires on the page being transitioned to, before the transition starts.
ui.prevPage will be the page being transitioned from, or an empty jQuery object if
there is none.
pagehide
This event fires on the page being transitioned from, after the transition finishes.
ui.nextPage will be the jQuery object of the page being transitioned to, or empty
if it does not exist.
pageshow
This event fires on the page being transitioned to, after the transition finishes.
ui.prevPage will contain the jQuery object of the page being transitioned from, or
empty if it does not exist.
These four events provide useful analogs to the jQuery(document).ready() call for
application page views.
To use these events, you attach event listeners to the appropriate page using
jQuery.bind(), jQuery.live(), or jQuery.delegate().
Pages | 17
www.it-ebooks.info
}
alert(strAlert);
});
</script>
For pages that are all contained within the same document, jQuery.bind() is sufficient.
For pages that will be asynchronously loaded by jQuery Mobile, use jQuery.dele
gate() or jQuery.live().
<header data-role="header">
<h1>jqmTwit: Settings</h1>
</header>
<div data-role="content" class="content">
<p>Settings go here.</p>
</div>
<footer data-role="footer">
<h2>Because the world needed another Twitter app.</h2>
</footer>
</section>
<!-- end second page -->
When the user first fires up the app, you’ll need to fill in the twitter feed. If the user
goes to the settings page, you’ll need to refresh the twitter feed when they return to the
main page. So you’d end up with some JavaScript, as shown in Example 2-6 .
Example 2-6. jqmTwit initialization script
<script>
$(document).ready(function() {
This is a very simple example and is missing a lot of detail, but it does show the begin-
nings of a useful jQuery Mobile page initialization pattern:
1. Upon document ready, initialize anything that needs to happen on the first page,
plus any event listeners for elements throughout the application
2. Bind pageshow and pagehide events to pages as needed to handle transitions to and
from them.
This simple pattern works well and is extensible for complicated applications. It’s also
easy to wrap in the jQuery plug-in pattern (see “Under The Hood: Using Swipe Events
to Trigger Page Transitions” on page 81 in Chapter 5 for a full example of using the
jQuery plug-in pattern to create an application initialization plug-in). The only thing
to watch out for is to make sure your application can handle it if the user hits the refresh
button. The easiest way to do this is to make sure that the initialization events that fire
on document ready make sure that an expected view is being shown in an expected
state.
Pages | 19
www.it-ebooks.info
Dialogs
Any valid jQuery Mobile page can also be displayed as a dialog by simply adding the
data-rel="dialog" attribute to the link, as shown in Example 2-7. This signals jQuery
Mobile to add extra styles to the page when it is displayed, such as rounded corners,
margins, and drop shadows, so that it appears to be hovering over the rest of the
application.
Example 2-7. Calling a dialog
<!-- begin first page -->
<section id="page1" data-role="page">
<header data-role="header"><h1>jQuery Mobile</h1></header>
<div data-role="content" class="content">
<p>First page!</p>
<p><a href="#page2" data-rel="dialog">Open page 2 as a dialog</a></p>
</div>
<footer data-role="footer"><h1>O'Reilly</h1></footer>
</section>
<!-- end first page -->
Tapping on this link will result in page 2 being displayed as a modal dialog, as shown
in Figure 2-6.
Due to their modal nature, dialogs are not included in the history hash.
As a result, when you need to manually move from page to page in the application, you
will need to use jQuery Mobile’s changePage() method, so that the framework can
correctly handle everything:
changePage(to, transition, back, changeHash)
• to: one of the following:
— a simple string denoting either an element ID or a filename
— an array of two elements, with the first being a simple string denoting the ele-
ment ID or filename of the page to transition from, and the second being a simple
string denoting the page to transition to
— an object with the following properties:
— url: the url string of the desired page
— type: the HTTP verb (“GET” or “POST”)
— data: serialized parameters to send to the url
• transition: the name of the desired transition
Transitions
jQuery Mobile has several animated transitions that can be used when changing pages
or displaying dialogs. These transitions are created using CSS 3 transforms, and so are
only available on browsers that support that feature.
To specify a transition, apply the data-transition property to the link, as shown in
Example 2-9. Valid values are:
fade: simply fade the page or dialog in over the previous content
flip: an animated page flip, rotating the current view out with the other view on the
reverse side
pop: the page springs into view from the center of the screen
slide: slide in from the left or right, pushing previous content out of the way
slidedown: slide down from the top, over the top of the current content
slideup: slide up to the top, revealing the next content below
As shown in Example 2-10, each transition can be reversed by specifying the data-
direction="reverse" property, though this is more useful for some transitions (slide
and flip, for example) than others (fade and pop, for example). jQuery Mobile will try
to employ the reverse transition in certain cases, such as when using the automatic back
button, or when hiding a dialog.
Example 2-10. Specifying reverse transitions
<!-- begin first page -->
<section id="page1" data-role="page">
<header data-role="header"><h1>jQuery Mobile</h1></header>
<div data-role="content" class="content">
<p>First page!</p>
<p><a href="#page2" data-transition="flip">Flip to Page 2</a></p>
</div>
<footer data-role="footer"><h1>O'Reilly</h1></footer>
</section>
<!-- end first page -->
Transitions | 23
www.it-ebooks.info
The transitions are defined as rules within the jQuery Mobile style sheet, and you can
use them directly if you wish to animate elements in your application beyond the page
transitions that jQuery Mobile provides. It’s a simple matter of toggling CSS classes,
as shown in Example 2-11.
Example 2-11. Animations in jQuery Mobile
<!-- begin first page -->
<section id="page1" data-role="page">
<header data-role="header">
<h1>CSS 3 Animations</h1>
</header>
<div data-role="content" class="content">
<p class="show-menu">Show/Hide Menu</p>
<div class="sliding-menu slide out">Menu</div>
</div>
<footer data-role="footer">
<h2>jQuery Mobile</h2>
</footer>
</section>
<!-- end first page -->
<script>
$(document).ready(function() {
$(".show-menu").click(function() {
$(".sliding-menu").toggleClass("reverse out in");
})
})
</script>
When you click on the Show/Hide Menu paragraph, the menu element will be animated
onto or off of the screen.
There are seven CSS classes that define base animations: slide, slideup, slidedown,
spin, fade, flip, and pop. In concert with these are the styles reverse, in, and out. By
combining these styles, you can animate elements in your application. You’ll need to
experiment to get the desired effects.
One word of warning: animations are nifty, but they can negatively impact usability
and accessibility. Use them judiciously.
CHAPTER 3
Page Elements
Like jQuery UI, jQuery Mobile has many different UI elements. Many of these are based
on common mobile UI elements, and are created in the standard jQuery Mobile way:
you write semantic markup and then apply a data attribute to the element, and jQuery
Mobile enhances the element upon initialization.
25
www.it-ebooks.info
Sound familiar? It should, that’s exactly what jQuery Mobile does. Many of the page
elements we are about to explore are created as jQuery widgets, and you handle them
in exactly the same way.
List Views
jQuery Mobile can produce visually formatted lists that are very similar to the styles
seen in native applications.
The list items are now tappable (see Figure 3-2). (In this example, of course, these items
don’t go anywhere; keep reading for a more fully functional example.)
Download from Wow! eBook <www.wowebook.com>
List Views | 27
www.it-ebooks.info
Nested Lists
jQuery Mobile will take nested lists and produce interactive views into which the user
can drill down by tapping on individual items. The first view will consist of the items
in the top-level list, and tapping on one of those items will display its sub-list, and so
forth. The code for this is shown in Example 3-4; the resulting linked list views are
shown in Figures 3-4, 3-5, and 3-6. jQuery Mobile will automatically provide a back
button and manage the URL mapping and transitions from page to page.
List Views | 29
Another Random Document on
Scribd Without Any Related Topics
fidelity to Basiliscus that the clergy could devise, he straightway sold
his services to Zeno for the promise of a cæsarship for his son and
the perpetual command of the armies for himself.
The career of the romantic Zenonis then came to a rapid and
tragic close. As the troops of Zeno marched into the city Basiliscus
and his Empress fled to the church of St Sophia, and endeavoured,
by promises of undoing their heretical work, to induce the clergy to
make Zeno respect the sanctuary. After a time an imperial officer
came to the trembling wretches by the altar, and stripped them of all
their imperial ensigns, to be taken to Zeno and Ariadne. Zeno
scrupled to drag them from the altar, and they were at last induced
to come forth on the solemn assurance that their lives would be
spared. It was now their turn to sail for Asia. They were sent to an
obscure village in Cappadocia, and imprisoned in a tower. One
tradition reports that they were killed on the journey, but the more
persistent and convincing report is that the door of the tower was
sealed with masonry, and the brother of Verina and his Empress
were doomed to a slow and horrible death by starvation. It was the
second revolution in three years, and Verina had been an active
element in both.
Exile had not improved the temper of Zeno, and the restoration
of his rule was at once stained with murder. He reflected gloomily on
the prestige of the handsome Harmatius, and easily persuaded
himself that he who had been faithless to one master might be
faithless to another. Soon afterwards the luxurious officer was cut to
pieces as he ascended the spiral stair from the palace to the
Hippodrome; his son was stripped of the robes and ensigns of Cæsar
and was sent to take a minor order of the Church at Blachernæ. But
for the intervention of the more humane Ariadne the youth would,
like his father, have exchanged his high dignity for death.
Constantinople seems to have regarded the murder with
indifference, but an avenger arose in the provinces and the two
Empresses had soon grave cause for anxiety. For a time
Constantinople trembled under the menace of the formidable
barbarians, but they at length returned to Italy without having
penetrated into the city. A more serious danger fell upon the palace
in the following year, however, when the younger daughter of Verina
joined for a moment in the conflict of ambitions. Leontia, it will be
remembered, had married Marcian, son of the Western Emperor
Anthemius. On the ground that she had been “born in the Porphyry,”
while her elder sister Ariadne had been born before the crowning of
Leo, her husband demanded that the Empire should be assigned to
him, and marched on Constantinople at the head of an army. He
broke through the defences of the city, and some of the chroniclers
actually assure us that he surprised the guard of the palace in their
midday siesta. It is at least certain that Zeno and the Empresses fled
in alarm, and a vigorous action would have put Verina’s younger
daughter on the throne. Marcian seems, however, to have postponed
the occupation of the palace until the following day, and the
commander Illus, secretly transporting fresh troops from Asia,
restored the balance in favour of Zeno and Verina. Marcian was
visited with the more refined punishment of the Byzantine world—he
was forced to enter the priesthood—and Leontia retired into
obscurity.
But the romance of Verina and her daughters had already
entered upon a fresh chapter. Verina had welcomed her returning
son-in-law at the palace, and her earlier expulsion of him and
Ariadne was overlooked in view of the important share she had had
in securing their return. We can, however, well understand that Zeno
regarded her with suspicion and distrust, and would welcome the
first opportunity to remove her from the palace. The argument which
he had applied so remorselessly to Harmatius plainly extended to his
imperial mother-in-law. The writers of the time represent him as not
taking a prominent part in the events that followed, but it is difficult
to doubt that his secret commands directed the whole intrigue.
In the year 478 a soldier attempted to assassinate the
commander Illus, and he confessed—under torture or bribery—that
he had been instructed by Verina’s steward Epinicius. The steward
was given into the custody of Illus by the Emperor, and was sent
under guard to a castle in Isauria. Illus followed, and easily induced
the steward to impeach his mistress. Illus then returned to the city,
and arranged with Zeno a plot for the capture of Verina. It is clear
that the Empress-Mother had great power in Constantinople, and
that they dare not openly touch her. Illus was to go to Isauria, and
pretend that he feared danger from Zeno. The Emperor was then to
ask Verina to take to Illus with her own hand a letter of indemnity,
and, when she reached Isauria, she was to be imprisoned there. We
should find it difficult to believe that so naïve a plot could entrap the
virile and experienced Empress were we not expressly assured of it
by the highest authorities. In a few weeks Verina was enraged to
find herself imprisoned in a Papirian fortress, one of the strongly
fortified castles of remote Isauria. One authority observes that they
first compelled her to take the vows of a nun, but we may decline to
believe that they troubled to place so frail and so superfluous a chain
on such a woman.
From the lonely hills of Isauria Verina at length found a means of
communicating with Ariadne and securing her interest. Zeno, to
whom Ariadne appealed, referred her to Illus, and, when that
general was summoned to the Empress’s apartments, and implored
with tears to release her mother, he bluntly asked: “Do you want to
be rid of your husband and wed another?” Ariadne returned stormily
to her husband, and declared that either Illus or she must leave the
palace. “If you can do anything, I’m with you,” said the distracted
Emperor, who was overshadowed by the vigorous commander.
Presently, as Illus was mounting the spiral stair to the Hippodrome, a
soldier in the pay of Ariadne’s chamberlain fell upon him. Illus was
saved, except for the loss of an ear, by his guards, but he prudently
decided that Constantinople was injurious to his health and
requested the Emperor for a change of air. He was appointed
commander of the eastern troops, took with him the patrician
Leontius and a distinguished company, and reached Antioch only to
declare himself in rebellion and Leontius Emperor.
In the extraordinary confusion of events which the meagre
chronicles transmit to us Verina had obtained her wish in an
unexpected manner. A messenger came to her in her solitary prison
to say that she was to crown Leontius at the city of Tarsus and join
forces with him and Illus against Zeno. Verina was not the woman to
hesitate. She crowned Leontius, a cultivated Syrian noble and
excellent soldier, at Tarsus, and issued a characteristic letter to the
officials and commanders of the Empire:
T
HE next Empress to occupy the superb apartments in the
palace, with their couches of ivory and silver and their
regiments of fawning eunuchs and silk-clad ladies, was
assuredly one of the most remarkable figures that ever sat on a
throne. The Empress Euphemia hardly ever issues into the pages of
history from the becoming seclusion of the women’s quarters in the
palace, but the few details which we have concerning her suggest
the most incongruous figure that imagination could place in such a
world, and a brief account of her romantic elevation is a necessary
introduction to the equally remarkable and better-known story of the
famous Empress Theodora. The Roman Empire seemed to be
deterred by some faint recollection of its early democratic spirit from
admitting the hereditary principle; but the absence of this
arrangement for securing the succession, together with the complete
lack of any really democratic arrangement, often threw it into a
chaotic confusion when a ruler died, and made its internal history a
thrilling succession of romances and tragedies, with an occasional
page of comedy. In this case it is comedy.
W
E have seen how Theodora rewarded the friends, and must
now see how she punished the enemies, of her earlier
career. It will be remembered that her father had been a
servant of the “greens” of the Hippodrome, but that this party had
greeted her mother with derision when she appealed for sympathy
with her three children, while the “blues” received them
compassionately. Twenty years afterwards the young circus-girl had
become the most powerful woman in the world, and the blues began
to tyrannize with impunity over their rivals. In the earliest years of
the reign of Theodora and Justinian we find them swollen with
conceit and encouraged in the perpetration of every kind of disorder.
The livelier “sparks” of that faction advertised their formidable
character by adopting the trousers and sandals of the fierce Huns
and trimming their hair after the fashion of those terrible invaders;
they wore long moustaches and beards, shaved the front part of the
head, and cultivated long hair at the back.
A few outrages soon taught them that the laws would not be
enforced against them, and before long the city of Constantinople
became, during the night, a land of terror. The citizen who dared to
pass along the streets with a gold clasp to his belt or his cloak or
money in his purse was robbed, and women could not move after
nightfall. The continued silence of the authorities encouraged the
blues, and drew all the dissolute elements of the city into their
ranks. They now began to force the doors of the houses, plunder the
coffers, rape the wives and daughters, and carry off the more
handsome slaves and boys. At the least resistance their deadly
poniards were drawn, and murder became frequent. When the
authorities intervened, none but the greens were punished. The evil
rapidly spread from night to day, and from the metropolis to other
cities. It would be futile in this case to quarrel with the details given
in the “Anecdotes.” The great riot into which the greens were stung
by this reign of terror is an historical fact; and nothing but the
vindictive memory of Theodora can explain how Justinian, the great
legislator, permitted so appalling a disorder.
Theodora meantime enjoyed the conversation of her monks and
hermits, and even Justinian seems to have been unconscious that he
was slipping the leash of beasts whom he might be powerless to
control. At length, on 14th January 532, the greens stirred. The
Emperor appeared in his kathisma at the Hippodrome, and an appeal
was made to him for justice. His officer replied disdainfully, and a
9
long and curious conversation took place. The Emperor still refused
to grant the impartial administration of justice or to punish the
murderers, and the greens left the Hippodrome. They gathered in
strength in the streets, and, although Justinian prudently sent to
learn and partly to remove their grievances, they remained in arms.
Belisarius was now sent against them with a troop of Goths, and the
rioting and burning began. Unfortunately for the Court an accident
then happened which had the singular effect of uniting the two
factions against the troops. Seven criminals were to be executed,
and Procopius cannot conceal the fact—in spite of his insistence that
the blues were never punished—that some of the seven were blues
and some greens. After five of the seven had been despatched, the
rope broke, and the crowd demanded the acquittal of the remaining
two. The authorities refused, and, as one criminal was a blue and
the other a green, the factions turned in common anger upon the
prefect and the troops.
The terrible riot that followed during four days must be read in
history. The first part of the palace, the great church of St Sophia,
and many other churches, mansions and public buildings were
destroyed. Priests who rushed into the fray holding aloft the
disarming emblems of their faith were cut down. On the fourth day,
a Sunday, Justinian entered the Hippodrome with a Bible in his hand,
and took a solemn oath to spare the offenders if they would disarm.
“Ass, thou art perjuring thyself,” was the infuriated answer; and he
retired to contemplate with Theodora the impending ruin of their
reign. On the following day the crowd forced Hypatius, nephew of
the Emperor Anastasius, to accept such purple robes as they could
obtain, marched with him in triumph to the Hippodrome, and exulted
in the downfall of Justinian and Theodora, who were believed to
have fled to Asia.
The “great” Justinian makes a lamentable appearance
throughout the whole riot, which he had guiltily occasioned, but
Theodora and the abler ministers were not minded to yield. As they
gathered in the hall of the palace, to which the cries in the
Hippodrome must almost have penetrated, the chief eunuch Narses
came to report that by a judicious distribution of money he had
distracted the factions and weakened the cause of Hypatius. It is
probably this news that turned the scale in the wavering counsels of
Justinian and his ministers, but it was Theodora who pressed it
home. The speech which Procopius assigns to her is worth
reproducing, though we cannot regard it as more than a rhetorical
paraphrase of the words she used:
ebookgate.com