Custom output for session:messages? - pyrocms
In PyroCMS, I'm using the session:messages tag to display messages to the user. This is working well, but I'd like to add a close button to each message which requires placing a span within each message. For example:
<div class="alert success">
You have logged in successfully. <span class="close">X</span>
</div>
Each message is wrapped in a div, which is given a class by setting an attribute of the session:messages tag. There is no built-in way to specify the output. How can I override the messages() function in session.php, adding a new attribute to append this close button?
So far I have tried:
Copying system/cms/plugins/session.php to *addons/shared_addons/plugins/session.php* and modifying the messages() function. The core function is used, rather than the new plugin as I had hoped.
Copying the plugin as described above, and then changing it's class to My_Plugin_Session extends Plugin_Session in hopes that its functions would then override the core Plugin_Session class. No luck.
It's not possible to extend certain things that are in the core (e.g. libraries and helpers) - I think this applies to plugins too.
In this case, if I was you (and I may well have to do this for my next project as these closable alerts are typically in Twitter Bootstrap etc.) I'd just edit /system/cms/plugins/session.php directly and add the extra <span> for the close button to the success, notice and error conditionals ('if' statements).
On a typical site I can't think of a situation where you'd ever need some alerts displayed differently to others (other than different colours depending on the outcome of course, which you can do in the CSS using the class name).
Providing you're using Git (you've cloned or forked the official PyroCMS repository and made your own branch) you'll be absolutely fine with future updates - if in a future version the session plugin changes, any changes will just be merged into your code automatically, or if Git can't figure it out, it'll show you the differences and prompt you to fix it by hand.
Note - there are a couple of other solutions for this specific problem based on the admin interface (you may have noticed the flash messages there are closable).
You could create a partial - which can contain PHP, not just Lex tags - e.g. see /system/cms/themes/pyrocms/views/admin/partials/notices.php with something like this (edit as needed and duplicate for notice and error):
<?php if ($this->session->flashdata('success')): ?>
<div class="alert success">
<?php echo $this->session->flashdata('success'); ?>
</div>
<?php endif; ?>
PyroCMS admin actually uses liveQuery to append the close button <span> in the browser
Source: /system/cms/modules/wysiwyg/js/wysiwyg.js:
// Add the close link to all alert boxes
$('.alert').livequery(function(){
$(this).prepend('x');
});
I did this and it is working perfect no need other plugin than jQuery.
in the template layout add this:
{{ session:messages success="message success" notice="message info" error="message error" }}
JavaScript:
$(function() {
$('.message').prepend('<a class="baxclose" id="baxclose"></a>');
$('#baxclose').click(function(){
$('.message').fadeOut('slow');
});
});
and the CSS:
a.baxclose{
float:left;
width:30px;
height:30px;
background:transparent url(../img/close-icon.png);
margin-top: -30px;
margin-left: -30px;
cursor:pointer;
}
.message {
padding: 20px 20px;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
border-radius: 3px;
margin-bottom: 10px;
-moz-box-shadow:inset 0 2px 3px rgba(255,255,255,0.5), 0 2px 3px rgba(0,0,0,0.1);
-webkit-box-shadow:inset 0 2px 3px rgba(255,255,255,0.5), 0 2px 3px rgba(0,0,0,0.1);
box-shadow:inset 0 2px 3px rgba(255,255,255,0.5), 0 2px 3px rgba(0,0,0,0.1);
zoom: 1;
margin-bottom: 20px;
}
.message h3 {
margin-top: 0;
font-size: 12px;
font-weight: bold;
}
.message p {
margin-bottom: 0;
}
.message.info {
border: 1px solid #cadcea;
background-color: #cdf;
background-image: -o-linear-gradient(top, #eef, #cdf);
background-image: -ms-linear-gradient(top, #eef, #cdf);
background-image: -moz-linear-gradient(top, #eef, #cdf);
background-image: -webkit-gradient(linear, left top, left bottom, from(#eef), to(#cdf));
background-image: -webkit-linear-gradient(top, #eef, #cdf);
background-image: linear-gradient(top, #eef, #cdf);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#EEEEFF', endColorstr='#CCDDFF');
color: #225b86;
text-shadow: 0 1px 1px #fff;
}
.message.error {
border: 1px solid #eeb7ba;
background-color: #fae2e2;
background-image: -o-linear-gradient(top, #fae2e2, #f2cacb);
background-image: -ms-linear-gradient(top, #fae2e2, #f2cacb);
background-image: -moz-linear-gradient(top, #fae2e2, #f2cacb);
background-image: -webkit-gradient(linear, left top, left bottom, from(#fae2e2), to(#f2cacb));
background-image: -webkit-linear-gradient(top, #fae2e2, #f2cacb);
background-image: linear-gradient(top, #fae2e2, #f2cacb);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#fae2e2', endColorstr='#f2cacb');
color: #be4741;
text-shadow: 0 1px 1px #fff;
}
.message.success {
border: 1px solid #b8c97b;
background-color: #e5edc4;
background-image: -o-linear-gradient(top, #e5edc4, #d9e4ac);
background-image: -ms-linear-gradient(top, #e5edc4, #d9e4ac);
background-image: -moz-linear-gradient(top, #e5edc4, #d9e4ac);
background-image: -webkit-gradient(linear, left top, left bottom, from(#e5edc4), to(#d9e4ac));
background-image: -webkit-linear-gradient(top, #e5edc4, #d9e4ac);
background-image: linear-gradient(top, #e5edc4, #d9e4ac);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#e5edc4', endColorstr='#d9e4ac');
color: #3f7227;
text-shadow: 0 1px 1px #fff;
}
Instead of the button you use to remove, another option would be to create a fadeOut message on click event.
HTML:
<div id="msgAlert"> …session:messages goes here...</div>
JS:
<script type="text/javascript">
$('html').click(function() { $('#msgAlert').delay(5000).fadeOut('slow'); });
Having a click will fadeOut the session message after 5sec.
Related
Media Queries on Joomla 3 Not working Suddenly
For some reason, my Joomla 3 website (using the Protostar Template) has media queries that just aren't working anymore. A specific example is located on this page. If you view the page on your phone, the large bus image on the page is supposed to "stack" on the text below it once the window gets to 599px or less. What's strange is things like this were working, then suddenly stopped working. I tried to find out what could have gone wrong with no luck. Here's my CSS Code that includes the media queries. I just put it all in the template.css file: .bustype{width:206px; height:296px; border:2px solid black; margin-right:10px; margin-left:10px; margin-bottom:25px; display:inline-block; padding:5px } #bustypewrap{ width:100%; margin:auto; text-align:center;} .busimage{ width:45%; margin-left:5%; float:left} .buscopy{ width:40%; float:right; text-align:justify} .clearitall{ clear:both;} .footerbb{ width:100%; padding:15px; margin-top:20px; text-align:center; background-color:#00467e; color:#fff;} .spectable{ display:block; } .spectablemobile{ display:none; } .mobilelogo{ display:none; } .buttonblue, .buttonblue:hover { font-size:18px; a{color:#fff;} a:hover{color:#fff;} background-color: #1d78cb; -webkit-box-shadow: 0px 3px 0px 0px #0f3e68; -moz-box-shadow: 0px 3px 0px 0px #0f3e68; box-shadow: 0px 3px 0px 0px #0f3e68; } .mobilebanner{display:none;} .popupimagesbuses{ float:left; margin:10px;} } #media only screen and (max-device-width: 599px) { .spectablemobile{ display:block; } .spectable{ display:none; } .busimage{ width:100%; } .buscopy{ width:100%; text-align:justify} .mobilebanner{display:block;} #content{ padding-left:10px; padding-right:10px; } body{ padding-left:0px!important; } } #media only screen and (max-device-width: 979px) { .mobilelogo{ display:block; } } I only included the code that I added in, the rest is basic CSS from the template (Protostar) that may be modified with colors, etc- but that's about it. Any help you can provide will be greatly appreciated! Thank you.
You have a typo before the media query (an extra curly brace ...): .popupimagesbuses{ float:left; margin:10px;} }
Changing CSS Styles for component
I am using Joomla Membership Pro component and am having some trouble with CSS styling. If you click here http://se24media.net/dc3/index.php/join-us/membership-options/supporter/sign-up You will see the background is styled nicely but if you fill in the form, click submit and go through to the page which dispalys your membership details it loses all styling (see link below) http://i60.tinypic.com/33pa4c2.png Does anyone know why it suddenly loses it's formatting? Many thanks
It loses the styling because on the first page, the table containing all the fields is wrapped with <form> tags like so: <form id="os_form"> <!-- Table with fields are in here --> </form> and the following CSS has been given for #os_form #os_form { background-color: #FFFFFF; background-image: url("/dc3/images/news_header.gif"); background-repeat: repeat-x; border-color: #868687; border-radius: 12px; border-style: solid; border-width: 0 2px 3px 0; color: #000000; float: left; font-family: 'Source Code Pro',sans-serif; height: auto; margin: 0 40px 40px 50px; max-width: 100%; opacity: 0.9; padding: 40px 20px 20px; width: 85%; } The second page simply displays a table with the class os_table so style this table, you will need to add the following to your CSS file: .os_table { /* code here */ } Hope this helps
href link not working in ie 8
I just can't figure this out. The links below work absolutely fine in every browser except IE8. If you click on the elements in IE8, the button disappears. If you click again where it was it reappears. But no amount of clicking will actually lead you to the href location. Can anybody explain to me why that might be? I've exhausted all of my thoughts and it still doesn't work. Many thanks for all your thoughts! The html... <div style="padding:0px 0px 30px 0px; clear: both;"> <div style="width: 50%; display: block; float: left;"> Learn More </div> <div style="width: 50%; display: block; float: left;"> Get Started </div> </div> ...and the stylesheet... .big_button { -moz-box-shadow: inset 0px 1px 0px 0px #bbdaf7; -webkit-box-shadow: inset 0px 1px 0px 0px #bbdaf7; box-shadow: inset 0px 1px 0px 0px #bbdaf7; background: -webkit-gradient(linear, left top, left bottom, color-stop(0.05, #79bbff ), color-stop(1, #378de5) ); background: -moz-linear-gradient(center top, #79bbff 5%, #378de5 100%); filter: progid : DXImageTransform.Microsoft.gradient ( startColorstr = '#79bbff', endColorstr = '#378de5' ); background-color: #79bbff; -moz-border-radius: 6px; -webkit-border-radius: 6px; border-radius: 6px; border: 1px solid #84bbf3; display: inline-block; color: #ffffff; font-family: Arial; font-size: 18px; font-weight: bold; padding: 15px 45px; text-decoration: none; margin-left: 130px; } .big_button:hover { background: -webkit-gradient(linear, left top, left bottom, color-stop(0.05, #378de5), color-stop(1, #79bbff) ); background: -moz-linear-gradient(center top, #378de5 5%, #79bbff 100%); filter: progid : DXImageTransform.Microsoft.gradient (startColorstr = '#378de5', endColorstr = '#79bbff' ); background-color: #378de5; } .big_button:active { position: relative; top: 1px; }
Its because of the 'filter:' part in your css, remove it, then it will work...
I just figured it out. IE8 seems to have a problem with :active in css. So the following section of the stylesheet was causing issues: .big_button:active { position: relative; top: 1px; } Current fix is to exclude the ':active' part of the css for the button as it's not essential. If anybody has any further information on why IE8 has issues with :active, I'd be interested to know about it.
Firefox12: multiple css classes don't seem to work for me
I have a few buttons on my webpage in different colors. I have one class for the shape of the button, and then a few classes that give them colors. .button { font-family:"Helvetica Neue W01 75 Bold", Helvetica, Arial, Sans-serif; text-decoration: none; white-space: nowrap; color: #333; padding: 13px 15px; display: inline-block; font-size: 1em; font-weight: bold; text-align: center; -webkit-border-radius: 8px; -moz-border-radius: 8px; border-radius: 8px; -webkit-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.1); -moz-box-shadow: 0 1px 0 rgba(0,0,0,0.1); } a.button { color: #333; } .black.button { background-color: #dedede; background: -webkit-gradient(linear, left bottom, left top, color-stop(0.1, #D3D3D3), color-stop(0.45, #EFEFEF), color-stop(0.90, #D3D3D3)); background: -moz-linear-gradient((linear, left bottom, left top, color-stop(0.1, #D3D3D3), color-stop(0.45, #EFEFEF), color-stop(0.90, #D3D3D3)); filter: progid:DXImageTransform.Microsoft.gradient(startColorStr=##EFEFEF, endColorStr=##D3D3D3); -ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#EFEFEF, endColorstr=#D3D3D3)"; -webkit-appearance: push-button; } .black.button:hover { background: #E2E2E2; filter: progid:DXImageTransform.Microsoft.gradient(startColorStr=#E2E2E2, endColorStr=#E2E2E2); -ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#E2E2E2, endColorstr=#E2E2E2)"; } .orange.button { background-color: #ffaa44; background: -webkit-gradient(linear,left bottom, left top, color-stop(0.22, rgb(255,144,9)), color-stop(0.81, rgb(255,170,68))); background: -moz-linear-gradient(center bottom, rgb(255,144,9) 22%, rgb(255,170,68) 81%); filter: progid:DXImageTransform.Microsoft.gradient(startColorStr=#ffaa44, endColorStr=#ff9009); -ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#ffaa44, endColorstr=#ff9009)"; } .orange.button:hover { background: #ff9009; filter: progid:DXImageTransform.Microsoft.gradient(startColorStr=#ff9009, endColorStr=#ff9009); -ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#ff9009, endColorstr=#ff9009)"; } I use them like: <a class="orange button" href="#">Click Me</a> This works in Chrome and Safari but does not work in Firefox12 (and IE). All I see is a white box with 'ClickMe' (So probably the .button is applied, but not .orange) From what I read, this is supported in Firefox. But I cannot figure what is wrong in my stylesheet. When I do an 'Inspect Element', Firefox shows the class as a.orange.button, but in the Styles tab, it doesnot display these classes. It is picking my stylesheet as the rest of the page is displayed okay. What am I missing here?
It seems to work if you remove invalid CSS code. I'm wondering if you have these exact lines in your original CSS code (with ... and unclosed brackets - which should cause the problem): background: -webkit-gradient(... border-radius:... Cleaned up jsFiddle Demo The problem is surely not with multiple classes. They work fine in every modern browser. UPDATE: I found the issue based on this jsFiddle. It is this declaration: .black.button { background: -moz-linear-gradient((linear, left bottom, left top, color-stop(0.1, #D3D3D3), color-stop(0.45, #EFEFEF), color-stop(0.90, #D3D3D3)); } You have one more opening ( than needed right after -moz-linear-gradient. Correct version (jsFiddle): .black.button { background: -moz-linear-gradient(linear, left bottom, left top, color-stop(0.1, #D3D3D3), color-stop(0.45, #EFEFEF), color-stop(0.90, #D3D3D3)); }
Try using something like the following background: -moz-linear-gradient( top left, white, black ); -webkit-gradient is for webkit browsers -- like Chrome and Safari; Firefox is not a webkit browser. see http://jsfiddle.net/Wfxym/ Some notes found # linear gradients and especially Cross-browser CSS gradient (details on the Firefox implementation can be found on MDN: https://developer.mozilla.org/en/CSS/linear-gradient)
Visual artifact in Firefox, perhaps due to css-transform or ::after element?
I'm attempting to give a 'card' element a drop-shadow which looks like it is lifted from the page. I'm doing this with the ::after pseudo-element, a css-transform, and a box shadow. I'm using Mac OSX, Chrome (latest version) and Firefox 5. The results are As you can see, there is a strange border-like artifact in the firefox rendering. The color of this seems to be linked to the body background color - as you can see in the second firefox example. To do this I have the following code: HTML: <div class="card_container"> <div class="card"> <!-- Content //--> </div> </div> CSS: .card{ padding: 5px; background-color: #fff; border: 1px solid #aaa; height: 375px; margin-bottom: 20px; } .card_container::after{ content: ""; width: 210px; height: 10px; -webkit-transform: rotate(2deg); -moz-transform: rotate(2deg); box-shadow: 3px 3px 3px #4a4a4a; background-color: #4a4a4a; position:absolute; bottom: 20px; right: 8px; z-index: -1; } There's some more CSS around, but I'm fairly sure I've played around enough to rule anything else out. Any ideas why this is happening, if it's platform/browser specific, and/or any fix? Thanks for any help!
:after is a tricky selector: you add an HTML element to your document, but you cannot manipulate its position freely. I suggest changing the HTML like this: <div class="card_container"> <div class="card"> <!-- Content //--> </div> <div class="shadow"></div> </div> You have to add some the "shadow" div to every card elements in use, which might take some time. Now for the CSS: .card { padding: 5px; background-color: #fff; border: 1px solid #aaa; margin-bottom: 20px; height:100px; /* just for show, can be set to auto */ } .card_container { width:210px; overflow-x:hidden; /* preventing the shadow from leaking out on the sides */ } .shadow { width: 93%; height: 10px; /* rotation */ transform:rotate(2deg); -moz-transform:rotate(2deg); /* Firefox */ -webkit-transform:rotate(2deg); /* Safari and Chrome */ /* shadow */ box-shadow: 3px 3px 3px #4a4a4a; -moz-box-shadow: 3px 3px 3px #4a4a4a; -webkit-box-shadow: 3px 3px 3px #4a4a4a; background-color: #4a4a4a; border: 1px solid #4a4a4a; position: relative; bottom: 33px; left: 5px; z-index: -1; } This solution is not very flexible: you will need to adjust the shadow element if you change the card's width (the wider the shadow, the less rotation, for instance).