summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Brown2013-03-23 10:05:18 (GMT)
committer Jonathan Brown2013-03-23 10:05:18 (GMT)
commitbc018ddbbb5628f319d22e15fa31cfb4c1f01c6f (patch)
treed61342124268f6fd7ccfbf9afd75966f4f7c45e9
parent602a176b594fe8ef455cb13023c956c8b8cb6beb (diff)
Fix buttons.
-rw-r--r--persona.admin.inc23
-rw-r--r--persona.admin.js9
-rw-r--r--persona.module52
3 files changed, 26 insertions, 58 deletions
diff --git a/persona.admin.inc b/persona.admin.inc
index 94095fe..55cc3f2 100644
--- a/persona.admin.inc
+++ b/persona.admin.inc
@@ -50,27 +50,10 @@ function persona_admin_form(array $form, array &$form_state) {
'dark' => t("Dark"),
),
);
- $form['buttons']['persona_button_text_sign_in'] = array(
- '#type' => 'textfield',
- '#title' => t("Sign In Button Text"),
- '#default_value' => variable_get('persona_button_text_sign_in'),
- '#required' => TRUE,
- );
- $form['buttons']['persona_sign_in_button_preview'] = array(
- '#type' => 'item',
- '#title' => t("Sign In Button Preview"),
- '#markup' => persona_button(),
- );
- $form['buttons']['persona_button_text_change_email'] = array(
- '#type' => 'textfield',
- '#title' => t("Change Email Button Text"),
- '#default_value' => variable_get('persona_button_text_change_email'),
- '#required' => TRUE,
- );
- $form['buttons']['persona_change_email_button_preview'] = array(
+ $form['buttons']['persona_style_preview'] = array(
'#type' => 'item',
- '#title' => t("Change Email Button Preview"),
- '#markup' => persona_button(FALSE),
+ '#title' => t("Preview"),
+ '#markup' => persona_button('sign_in'),
);
// Legal Document settings.
$form['legal_docs'] = array(
diff --git a/persona.admin.js b/persona.admin.js
index 6eacc5a..d574826 100644
--- a/persona.admin.js
+++ b/persona.admin.js
@@ -3,22 +3,13 @@
Drupal.behaviors.personaAdmin = {
attach: function (context, settings) {
var button_sign_in = $('.persona-sign-in');
- var button_change_email = $('.persona-change-email');
$('#edit-persona-button-style').change(function (e) {
button_sign_in.removeClass("dark orange persona-button");
- button_change_email.removeClass("dark orange persona-button");
var button = "";
if ($(this).val()) {
button = "persona-button ";
}
button_sign_in.addClass(button + $(this).val());
- button_change_email.addClass(button + $(this).val());
- });
- $('#edit-persona-button-text-sign-in').keyup(function (e) {
- button_sign_in.children('span').text($(this).val());
- });
- $('#edit-persona-button-text-change-email').keyup(function (e) {
- button_change_email.children('span').text($(this).val());
});
}
}
diff --git a/persona.module b/persona.module
index 79fe144..5fa7e82 100644
--- a/persona.module
+++ b/persona.module
@@ -275,21 +275,32 @@ function persona_sign_in() {
/**
* Generates a Persona button.
*
- * @param bool $sign_in
- * Whether the button should be a Sign In button (default). Otherwise it will
- * be a Change Email button.
+ * @param string $type
+ * Button to render.
*
* @return string
* HTML of generated button.
*/
-function persona_sign_in_button() {
- // Determine CSS classes and text.
- $classes = array('persona-sign-in');
- if (!user_is_logged_in()) {
- $text = t("sign in");
+function persona_button($type = NULL) {
+ // Determine button type if not specified.
+ if (!$type) {
+ $type = user_is_logged_in() ? 'switch_account' : 'sign_in';
}
- else {
- $text = t("switch account");
+ // Determine CSS classes and text.
+ $classes = array('persona-' . $type);
+ switch ($type) {
+ case 'sign_in':
+ $text = t("sign in");
+ $classes[] = 'persona-sign-in';
+ break;
+ case 'switch_account':
+ $text = t("switch account");
+ $classes[] = 'persona-sign-in';
+ break;
+ case 'sign_out':
+ $text = t("sign out");
+ $classes[] = 'persona-sign-out';
+ break;
}
$style = variable_get('persona_button_style');
if ($style != '') {
@@ -303,23 +314,6 @@ function persona_sign_in_button() {
return $html;
}
-function persona_sign_out_button() {
- // Determine CSS classes.
- $style = variable_get('persona_button_style');
- if ($style != '') {
- $classes[] = 'persona-button';
- $classes[] = $style;
- }
- return l('<span>' . t("sign out") . '</span>', 'https://login.persona.org/', array(
- 'attributes' => array(
- 'style' => 'cursor: pointer;',
- 'target' => '_blank',
- 'class' => $classes,
- ),
- 'html' => TRUE,
- ));
-}
-
/**
* Implements hook_block_info().
*/
@@ -338,9 +332,9 @@ function persona_block_info() {
* Implements hook_block_view().
*/
function persona_block_view($delta) {
- $output = persona_sign_in_button() ;
+ $output = persona_button();
if (user_is_logged_in()) {
- $output .= persona_sign_out_button();
+ $output .= persona_button('sign_out');
}
return array('content' => $output);
}