Category Archives: CSS

Laravel 4.2 Using Custom View for Pagination

Recently in one of my project we used laravel pagination and we have to use custom pagination as the theme we used were having different CSS classes for pagination which were not compatible with laravel default views. So in this blog I am going to explain how to do this. 

First of all open app/config/view.php file. Here remove pagination key and add following key. 
‘pagination’ => ‘paging’
Now go to your views folder and add new file and name it paging.blade.php and add following content to it.
<?php
$presenter = new IlluminatePaginationBootstrapPresenter($paginator);
?>
<?php if ($paginator->getLastPage() > 1): ?>
    <ul class=”pagination”>
        <?php echo $presenter->render(); ?>
        <li>
            <?php
            echo Form::open(array(‘url’ => $paginator->getUrl(0), ‘method’ => ‘GET’));
            ?>
            <?php echo Form::close(); ?>
        </li>
    </ul>
<?php endif; ?>
Above is your custom view so you can make changes as per your requirements and add custom code. 
Now add following code where you want to display paging. First of all in controller file. 
$pagedData = Model::where(‘company_id’,$companyId)->paginate(5);
Now in view add following code.
{{ $pagedData->links(); }}
That’s it now you have custom paging view in your laravel app.

Passing and Retrieving Data from Booststrap Modal

Recently in one my project I was using a theme which is using boostrap modal. Basically I was using modal for confirmation of delete and once user click on confirm process the delete action. I was using laravel REST API so we have to pass the id of object to be destroyed. So I have to pass id of object to modal and confirmation call API to delete. In this blog I will explain how to do this.

First of all add following modal code to your HTML.

<div class=”modal-dialog”>
        <div class=”modal-content”>
            <div class=”modal-header”>
                <button type=”button” class=”close” data-dismiss=”modal” aria-hidden=”true”></button>
                <h4 class=”modal-title”>Confirmation</h4>
            </div>
            <div class=”modal-body”>
                <p> Are you sure you want to delete? </p>
                <input type=”hidden” id=”objectId”/>
            </div>
            <div class=”modal-footer”>
                <button type=”button” data-dismiss=”modal” class=”btn dark btn-outline”>Cancel</button>
                <button id=”confirmDelete” type=”button” data-dismiss=”modal” class=”btn green”>Continue</button>
            </div>
        </div>
    </div>

As you can in above code I have added one hidden field in modal where we will store object id.

Now following will your code of delete button.

<a id=”deleteButton” data-id=”{{$object->id}}” data-toggle=”modal” href=”#deleteConfirmation” class=”btn btn-danger btn-sm”>

As soon as you click on delete button modal will be displayed.

Now add following code to your JavaScript.

    $(document).on(“click”, “#deleteButton”, function () {
        var id = $(this).data(‘id’);
        jQuery(‘#deleteConfirmation .modal-body #objectId’).val( id );
    });

    $(‘#deleteConfirmation .modal-footer button’).on(‘click’, function (e) {
        var $target = $(e.target); // Clicked button element
        $(this).closest(‘.modal’).on(‘hidden.bs.modal’, function () {
            if($target[0].id == ‘confirmDelete’){
                $id = $(‘#deleteConfirmation .modal-body #objectId’).val();
            }
        });
    });

As you can in above code we have added click event on delete button and setting id in modal hidden field.

Then we are adding event for confirm button in modal window and getting value stored in hidden field and then you can call the APIs or submit form whatever you want.

Hope this helps you.

HTML Fit Content to Available Space – Dynamic Font Size

Hello,

Recently in one of my project we have to fit content to available screen height. Basically it was cross platform mobile application built in HTML 5 and JavaScript. On screen there was a card with content. Card height and width as set to screen height and width. Now the problem was content can big or small and there should not be scrollbar. So what I did is I reduced the size of font till the content fits available width and height. This I did in JavaScript. So here in blog I am going to explain how to do this.

First of all add onload method to your body tag.

<body onload=”resizeFontSizeInit()”>

   <div id=”contentContainer” style=”width:100%;height:100%;overflow:hidden;”>
       <div id=”content”>
        Dynamic Content Here
       </div>
   </div>

</body>

Now add following function to JavaScript

function resizeFontSizeInit(){
   resizeFont(0.1);
}

function resizeFont(emSize){
      //first get the screen height
      var screenHeight = document.documentElement.clientHeight;
   
      //Now set the font size to content div
      var contentDiv = document.getElementById(‘content’);
      contentDiv.style.fontSize = String(emSize)+”em”;

      //Now check the height of screen to height of content div
      var contentHeight = contentDiv.clientHeight;

      //Check if content height is less than screen height.
      if(contentHeight < screenHeight){
           //Increase font size and call the same function recursively.
           emSize = emSize + 0.1;
           resizeFont(emSize);
      }else{
           //content height is greater than screen size so time to stop recursion.
          //set fontsize to previous size.
          revertFontSizeToPreviousSize(emSize);
      }
}

function revertFontSizeToPreviousSize(emSize){
      emSize = emSize – 0.1;
      var contentDiv = document.getElementById(‘content’);
      contentDiv.style.fontSize = String(emSize)+”em”;
}

So basically we start with 0.1 em font size and keep increasing it till the content height is greater than screen height. As soon as it’s bigger we have to stop and reset it to previous size. This way no matter what your content is, it will fit to screen without scroll bar.

Sencha Touch List, Different background colors for Group Header

Recently in one of my project we have a Sencha Touch list with grouped headers. We know that we can control group header styles by CSS or we can change it by overriding base css class. In this case we will have one same color for each group header, while in my case the requirement was to have different background colors for each group header. This blog is about how how I implement it, you may have better idea. Feel free to comment.

Here I added background color in each items of the list and then grouped it based in certain field. For example.

Ext.define(‘MyApp.model.MyModel’, {
    extend: ‘Ext.data.Model’,
    config:{
        fields: [
            { name:’id’, type:’int’},
            { name:’group_background_color’, type:’string’},
            { name:’item_name’, type:’auto’},
            { name: ‘group’, type: ‘string’}
        ]
    }
})

Then we have following Store definition.

Ext.define(‘MyApp.store.MyStore’, {
    extend: ‘Ext.data.Store’,
    config: {
        model: ‘MyApp.model.MyModel’,
        autoLoad: true,
        grouper: {
        groupFn: function (item) {
            return item.get(‘group’);
            }
        },
        proxy: {
            type:’ajax’,
            actionMethods:{
                read: ‘POST’
            },
            url:’items.json’,
            reader:{
                type:’json’,
                rootProperty:’items’
            }
        }
    }
});

Now we have our list where we will show this data.

{
        xtype: ‘list’,
        id:’myList’,
itemId:’myList’,
scrollable: true,
grouped: true,
itemTpl:'<div>{item_name}</div>’ ,
        store: ‘MyStore’
}

This will create list with groups and group header. If you use default Sencha Theme the group header will have blue as background color. We have to change it to our colors dynamically. For that we will update on list refresh. List refresh event is fired when list is visible first time and there is some change in data in store or list store is loaded. Add refresh event in controller.

control:{
            ‘#myList’:{
                refresh: ‘refreshListHeaders’
            }
}

And here is the function.

refreshListHeaders: function(list){
    if(list.groups){
    var groupElements  = document.getElementsByClassName(‘x-list-header’);
    for(var i=0;i < groupElements.length i++){     
       var firstChild = list.groups[i].children[0];    var backGroundColor = firstChild.data.banner_background_color;
    groupElements[i+1].style.setProperty(‘background-color’, backGroundColor, ‘!important’);
    }
    }
    }

So our logic is very simple. We get all the elements with class name “x-list-header” . That gives us all the header elements.  Now for each group we are getting background color from the first item of the group and set it as background color to group header.

Alternate Way to Create Image Button in Sencha Touch

Hello,

Recently I was working on a sencha touch project where I need to use a nig round image in sencha touch button.  We all now that we can use images inside button using iconCls and iconMask property. That will put small icons inside your button along with button rounded corners and background colors. But in my case we don’t need button background color or rounded border of button. We just need a round image with transparent background and user should be able to click on it. There are number of ways for doing it.

First we can use xtype : image and put image url to it. But sometimes tap event does not work over image. So this not an option. Other option is to use panel and put image as html inside and add tap evet to panel body. But that will be on complete panel body. So in case of round image if user tapped outside the image but inside a panel, tap event will be fired. So here is the third solution.

As we know that Ext.button extends the Ext.component so we can add html to component.  So we can add image as html as follow.

{

      xtype: ‘button’,

      html: ‘<img src=”lib/images/myImage.png”/>’
}

After adding this image is added inside the button and but still have button background colors and rounded border. This you can remove by updating your sencha touch CSS. Find the following class in sencha touch CSS.

.x-button, .x-button.x-button-back:after, .x-button.x-button-forward:after, .x-toolbar .x-button, .x-toolbar .x-button.x-button-back:after, .x-toolbar .x-button.x-button-forward:after {
background-image: none;
background-color: #ccc;
background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #f2f2f2), color-stop(3%, #d9d9d9), color-stop(100%,#bfbfbf));
background-image: -webkit-linear-gradient(top, #f2f2f2,#d9d9d9 3%,#bfbfbf);

background-image: -moz-linear-gradient(top, #f2f2f2,#d9d9d9 3%,#bfbfbf);

background-image: -o-linear-gradient(top, #f2f2f2,#d9d9d9 3%,#bfbfbf);

background-image: linear-gradient(top, #f2f2f2,#d9d9d9 3%,#bfbfbf);
}

and replace it with following class. This will remove all background of button but still you will have rounded borders.

.x-button,.x-toolbar .x-button.x-button-back:after,.x-toolbar .x-button.x-button-forward:after{background-image:none;}
Now to remove borders, find following class.
.x-button, .x-toolbar .x-button {
border: 1px solid #999;
border-top-color: #a6a6a6;
background-color: #ccc;
color: #000;
}
and replace it with 
.x-button, .x-toolbar .x-button {
color: #000;
}
That’s it and your button will only have image. And still user can tap on and it and have a feeling like button. 
Pelase note that updated sencha touch css is applicable to all the buttons in your application so if you have more than one button which does not have image, please don’t use this trick. In my case I was having only one button in application so that’s why I am using this trick.

Hope this helps you.