link vs. optional newsbox

General questions about CMSimple
Post Reply
Tata
Posts: 3586
Joined: Tue May 20, 2008 5:34 am
Location: Slovakia
Contact:

link vs. optional newsbox

Post by Tata » Tue May 13, 2014 6:50 pm

There is a way to link a subpage with a specific newsbox using newsbox($variable). I would like, however, to link only a text in a subpage to show specific newsbox. Is it possible? There is a way how to make is with simple HTML and java, evtl. with an iframe. But how about under CMSimple_XH?

Something like this:
[ external image ] [ external image ]
CMSimple.sk
It's no shame to ask for an answer if all efforts failed.
But it's awful to ask without any effort to find the answer yourself.

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: link vs. optional newsbox

Post by cmb » Tue May 13, 2014 7:08 pm

Do you mean you want this particular newsbox to be shown, when the text is clicked? This could be accomplished by adding a parameter to the link URL, e.g. <a href="./?NAME_OF_THE_SHOWN_PAGE&newsbox=NAME_OF_THE_NEWSBOX">. Then you can do in the template:

Code: Select all

<?php echo newsbox(isset($_GET['newsbox']) ? $_GET['newsbox'] : 'DEFAULT_NEWSBOX_NAME');?>
Note, that anybody could request an arbitrary newsbox when you do this (however, that shouldn't be a problem).
Christoph M. Becker – Plugins for CMSimple_XH

Tata
Posts: 3586
Joined: Tue May 20, 2008 5:34 am
Location: Slovakia
Contact:

Re: link vs. optional newsbox

Post by Tata » Tue May 13, 2014 8:43 pm

WEll, seems logical.
I dropped the code on the page, but it shows after saving

Code: Select all

<p><p><a href="./?Sidebox&newsbox=NEWSBOX"><strong>CLICK HERE</strong> (Slovakia)</a></p></p>
In the template

Code: Select all

                   <?php if($adm=='true') { 
                             echo toc();
                             }else{
                             echo newsbox(isset($_GET['newsbox']) ? $_GET['newsbox'] : 'NEWSBOX');
                         }
                    ?>
The result is, that on opening the website no newsbox is shown (the area for the newsbox is empty).
There are two subpages prepared:
Welcome - to be show generally in newsbox
Sidebox - to be called on by the link, replacing the Welcome Page.
Using the link the page is only shown in the content area.
CMSimple.sk
It's no shame to ask for an answer if all efforts failed.
But it's awful to ask without any effort to find the answer yourself.

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: link vs. optional newsbox

Post by cmb » Tue May 13, 2014 8:55 pm

Please try the following (replace THIS_PAGE with the name of the page the link is on):

Code: Select all

<p><a href="./?THIS_PAGE&newsbox=Slidebox"><strong>CLICK HERE</strong> (Slovakia)</a></p> 
and

Code: Select all

            <?php if($adm=='true') { 
                             echo toc();
                             }else{
                             echo newsbox(isset($_GET['newsbox']) ? $_GET['newsbox'] : 'Welcome');
                         }
                    ?>
Christoph M. Becker – Plugins for CMSimple_XH

Tata
Posts: 3586
Joined: Tue May 20, 2008 5:34 am
Location: Slovakia
Contact:

Re: link vs. optional newsbox

Post by Tata » Tue May 13, 2014 9:08 pm

Thanks a lot. It works. I just will try to change it to onMouseOver. It seems easier to me, than add some close button into the newsbox.
CMSimple.sk
It's no shame to ask for an answer if all efforts failed.
But it's awful to ask without any effort to find the answer yourself.

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: link vs. optional newsbox

Post by cmb » Tue May 13, 2014 9:53 pm

Tata wrote:Thanks a lot. It works
Fine. :)
Tata wrote:I just will try to change it to onMouseOver. It seems easier to me, than add some close button into the newsbox.
Hm, in this case you'll probably want to load the content of the newsbox by Ajax. I thought about this in the first place, but it is more difficult to accomplish and it requires JavaScript (even nowadays I prefer to make a general accessible website working without JavaScript, and only add enhancements that require it).

A basic outline:
  • deliver the page without any newsbox content, but with an empty element instead
  • on mouse over, load the newspage as content view, and replace the content of the empty element with it
  • on mouse out, discard the replaced content
A simplified implementation:
  • Add an empty newsbox with id="dynamic_newsbox" to the template:

    Code: Select all

    <div id="dynamic_newsbox"></div> 
  • "Install" the "content" addon
  • we'll use jQuery, so set it's autoload option to on
  • place the following JS in a file newsbox.js in the CMSimple_XH installation folder:

    Code: Select all

    jQuery(function ($) {
        $("a.dynamic_newsbox").mouseenter(function () {
            $.get($(this).prop("href"), "", function (data) {
                $("#dynamic_newsbox").html(data);
            });
        }).mouseleave(function () {
            $("#dynamic_newsbox").html("");
        })
    });
  • load this JS file in the template:

    Code: Select all

    <script type="text/javascript" src="<?php $pth['folder']['base'];?>newsbox.js"></script>
Finally create the links in the page content in the following way:

Code: Select all

<a href="./?Sidebox&content" class="dynamic_newsbox">TEXT</a>
Christoph M. Becker – Plugins for CMSimple_XH

Tata
Posts: 3586
Joined: Tue May 20, 2008 5:34 am
Location: Slovakia
Contact:

Re: link vs. optional newsbox

Post by Tata » Tue May 13, 2014 10:51 pm

Yes, I have found the AJAX solution also. So far I've solved it by a "close" button in the opened newsbox, it works.
I'll try this tomorow.
Thank you again.
CMSimple.sk
It's no shame to ask for an answer if all efforts failed.
But it's awful to ask without any effort to find the answer yourself.

Tata
Posts: 3586
Joined: Tue May 20, 2008 5:34 am
Location: Slovakia
Contact:

Re: link vs. optional newsbox

Post by Tata » Tue May 13, 2014 11:43 pm

cmb wrote:A basic outline:
  • deliver the page without any newsbox content, but with an empty element instead
  • on mouse over, load the newspage as content view, and replace the content of the empty element with it
  • on mouse out, discard the replaced content
In this case I would need to place som image as a background of the empty newsbox. E.g. the content of the page that's loaded now on the beginning.
I'll load the page up tomorrow.
CMSimple.sk
It's no shame to ask for an answer if all efforts failed.
But it's awful to ask without any effort to find the answer yourself.

Post Reply