...

Hi! I’m Starx

experienced Software Developer. And this is my blog
Start Reading About me
Blog Page
November 9, 2012

Remove scrollbar but not scrolling functionality

Question by Max

I know you can define overflow:hidden; on the body of the HTML to remove the scrollbar, but I would like to still be able to scroll with the arrows or scroll wheel on a mouse.

Thanks in advance for any help.

Edit:
Thanks for all the advice about on hover scrollbars and custom bars. Also thank you for all concerns about impacting users experience by removing the scrollbars. I shall elaborate a little more so you explain where I am coming from.

I have a circular page (if you scroll with a scroll wheel or arrow button, when it reaches the bottom it resets to the top of the page and starts again). A never ending loop. A scrollbar impacts on this as a bar is limited and when it reaches the bottom and resets to the top the users mouse is still at the bottom of the page meaning when they move it there is some flickering between the top and bottom of the page.

I plan to remove the scroll bar and replace it with arrow buttons at the top and the bottom of the window. This is why I would like to remove the scrollbar completely but leave the scrolling functionality.

Answer by Starx

Ok, new answer. I just developed a little trick to do so, mixed with jQuery.

Create a wrapper div inside the body, with the following css.

body { overflow: hidden; }

#wrapper { overflow: auto; }

Then, simply set their respective heights:

$("body").height($(window).height());
$("#wrapper").height($("#text").height());

Demo


To support for resizes

$(window).trigger('scroll');

$(window).scroll(function() {
    $("body").height($(window).height());
    $("#wrapper").height($("#text").height());    
});

Demo

Read more

a href link with basic authentication

Question by Anna Smother

I have a website were I login via basic authentication, that works fine. But when I want to download a .pdf file (that is generated by the server) I get a popup with the information that I need to login…again :/.

How can I prevent this? Or how can I send the basic authentication information with the link? I saw some examples, like: http://username:password@yourserver.com/filename.pdf . But that don’t work in IE.

How can I solve this with only html and or jQuery?

edit:
I login via a form in the site, that works. But when I want to download an .pdf file while i’m logged in, I get the pop-up.

<a href="http://yourserver.com/yourpdffile.pdf">Report1.pdf</a>

Answer by Starx

Basic authentication is Server based, HTML and jQuery are helpless here.

However, before sending AJAX request to such page, you can provide these details. Here is an example.

$.ajax({
    'url': 'http://yourdomain.com/action/',
    'beforeSend': function(xhr) {
        xhr.setRequestHeader("Authorization", "Basic " + encodeBase64(username + ":" + password) 
    },
    //.....
});
Read more

List connected files as array when we call a file with php?

Question by AnzaVR

What I am trying to achieve, when I open a website, it starts a network activity by loading images, swf files, css file etc. Is there any way in php to get a list of those resources as array?

Answer by Starx

You can use regular expression to parse the links once you have all HTML markups.

Here is an example to get the CSS request:

$regexp = "<links[^>]*href=("??)([^" >]*?)\1[^>]*/>"; 
preg_match_all("/$regexp/siU", $input, $matches);
var_dump($matches);

In the same way get scripts resources, image request, and iframe request.

Read more

Extending the Session Library in Codeigniter 3

Question by luv2Code

I’ve been using CI for a while now and recently upgraded to CI 3. I noticed the Session library has now been moved to a folder.
I used to have my own MY_Session.php file in the application/libraries folder that extended the default CI library.

I also use the autoload.php file to autoload my session library.
This no longer works, as I get Unable to load the requested class: Session.

If I remove MY_Session.php file, then the pages load, but then I’ll be missing my extended functionality.

Does anyone know how exactly to extend the session library in CI 3?

Answer by Starx

You can do this similar to extending other core components.

class MY_Session extends CI_Session {

    function __construct() 
    {
        parent::__construct();
        echo "In extended the session";
    }
}  

Make sure you load the session library as well. Like

$autoload['libraries'] = array('database','session');

Also, Unable to load the requested class: Session are generally triggered for the two reasons.

  • CI can’t fine the session
  • You haven’t autoloaded the library

Also, make sure you have a encryption key on your config.php

$config['encryption_key'] = 'xxxxxxxxxxxxxxxxxxxxxxx';
Read more
November 8, 2012

Using onChange on Select Option

Question by deetu

I have a select option box that is dynamically populated, so if i change the select some other boxes are filled, and i can delete them too.
Which also deletes the option from the select box, this works fine, but when i delete the options and i have just one left in the box, there seem to be no way to fire the option.

$("#email_name").on("change", function(){
    var componentkeys = myDailyemail.getKeys($("#Component").val());
    $.each(componentkeys, function(kIndex, kItem) {
        $("#key").append($("<option/>").val(kItem).text(kItem.toUpperCase()));
    });
});

Answer by iMoses

You can automatically trigger a change event after you populated the select element, making it as if the user already selected the first option.

$("#email_name").on("change", function(){
    var componentkeys = myDailyemail.getKeys($("#Component").val());
    $.each(componentkeys, function(kIndex, kItem) {
        $("#key").append($("<option/>").val(kItem).text(kItem.toUpperCase()));
    });
    $("#key").trigger("change"); // trigger key
}).trigger("change"); // trigger email_name

I wasn’t sure what you wanted to trigger so I entered both possibilities.

Answer by Starx

You can use .trigger() to fire events manually.

Insert following, where needed.

$("#email_name").trigger('change');
Read more
November 7, 2012

How send with post method in code behind?

Question by mum

I have a param A and its 25000 characters long.
How to send param A with GET method in php?

 $kq=0;
 $msg1= strtr(base64_encode($msg), '+/=', '-_,');              
 $Title1=strtr(base64_encode($Title), '+/=', '-_,'); 
header("Location:".JRoute::_('./index.php/i0702?'.'kq='.$kq."&Title=".$Title1."&Msg=".$msg1));

Note: strlen($msg1)> 25000 characters. Now, How send with post method?

Answer by Starx

The maximum characters you can send from GET method is 3000. Use POST method.

<form method="POST" action="your/url/to/open.php">

    <input type="text" value="<?php echo $a; ?>" />
    <input type="submit" />

</form>
Read more

PHP4 variables: concatenate array in declaration

Question by Dbugger

Possible Duplicate:
PHP error, concatenation in array() in member initialiser

I have this sort of code:

var $compSQL = array(
        '0' => "#FIELD# LIKE '%#VALUE#%'",
        '1' => "#FIELD# NOT LIKE '%#VALUE#%'",
        '2' => "#FIELD# LIKE '#VALUE#%'",
        '3' => "#FIELD# NOT LIKE '#VALUE#%'",
        '4' => "#FIELD# LIKE '%#VALUE#'",
        '5' => "#FIELD# NOT LIKE '%#VALUE#'",
        '6' => "#FIELD# = '#VALUE#'",
        '7' => "#FIELD# != '#VALUE#'"
);

and I need to change the values of the string with some concatenation operation, sorta like this:

var $compSQL = array(
        '0' => "#FIELD# LIKE ".$somevalue,
        ...
);

But that is not allowed. How should I do it?

Answer by mmmshuddup

As requested, here is the bit of code that will help you run your concat operation.

public function myReplace($field, $value, $index = '0')
{
    $patterns     = array('/#FIELD#/', '/(%{0,1}#VALUE#%{0,1})/');
    $replacements = array($field, $value);
    $merged       = preg_replace(
        $patterns, $replacements, $this->compSQL[$index]
    );
    $this->compSQL[$index] = $merged;
}

Then say you set a field name and value in your code and call that function:

$field = 'user';
$value = 'test';
$object->myReplace($field, $value, '7');

Answer by Starx

You can directly insert the variable inside the double quotes.

'0' => "#FIELD# LIKE $somevalue",

Or

'0' => "#FIELD# LIKE {$someValue}",
Read more

Jquery val() not working in ie for dynamically added option

Question by rahul

i am generating options for my dropdown by jquery ajax method, filling it by db.

$.ajax({
        type: "POST",
        url: pageUrl + '/FillAssignee',
        data: {},
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (response) {
                        for (var i = 0; i < response.d.length; i++) {
                            $('#SelectAssignee').append($("<option></option>").val(response.d[i]['Value']).html(response.d[i]['Text']));
                        }
                  }            
      });

it’s works fine. only problem is that first value not got selected by default on ie. so for that i used many options

1. $('#SelectAssignee").val();
2. $('#SelectAssignee option:first').attr('selected','selected');
3. $('#SelectAssignee option:first').prop('selected',true);

how to get it work please help me out.

Thanks in advance.

Answer by Starx

Try setting as attributes rather than properties.

$('#SelectAssignee').append($("<option />", { value: response.d[i]['Value'], html: response.d[i]['Text'] }));
Read more

How to get original URL from a specific Controller + Action

Question by Le Trung Hieu

I’ve been working on a project and everything’s fine until my partner wants to request to an original URL without rewriting.

For example:
He wants to call to

http://mydomain.com/index.php?module=default&controller=check&action=index

instead of

http://mydomain.com/default/controller/index.

Is there any way that i can make the above URL working?

Answer by Starx

Yes, in fact Rob Allen (Author of Zend Framework in Action) has written an excellent article explain just how to do this.

Zend Framework URLs without mod_rewrite

Read more
...

Please fill the form - I will response as fast as I can!