Tag Archives: jquery

qTip – jQuery Tooltip Plugin with Excellent Docs

6 Dec

qTip - jQuery Tooltips

qTip - jQuery Tooltips

The bar has been set on jQuery plugins by this simple yet very robust project: qTip.

What is it? An easy way to create fancy tooltips that has (optional) customization options for just about anything you want to do. I had been using a pretty old and bland library before, so I was excited to stumble on this one.

Example: a tooltip positioned at the bottom left of a selector, with a green color scheme and a little tip pointing to the selector.

    $('#myselector').qtip({
        content: 'Eat my tooltip, sucker!',
        position: {
            corner: {
                target: "bottomLeft",
                tooltip: "topLeft"
            },
            adjust: {
                x: 10,
                y: 10
            }
        },
        style: {
            name: "green",
            tip: "topLeft"
        }
    });

Perhaps the best part of this plugin is the documentation. Just check them out and tell me that’s not the most well-documented library you’ve ever seen.

Results are in – No One Likes Working With Time

15 Jan

20fswp3I recently performed a very Scientific survery asking ‘do you like working with time?’  I don’t mean ‘working with time constraints’, or ‘working with a person whos name is Time but they probably spell it like PThyhm (the P is silent).’  No, I mean working with time (timestamps, date formating, human-friendly time representation, etc) in your code — do you like it?

The results may or may not surprise you.  With a sample size of 1, most if not all of those surveyed responded that they very strongly dislike working with timestamps!

I strongly agree with the person surveyed, so that’s why I’m so elated that I stumbled upon this repo on github the other day — jQuery timeago.  Yes!  Finally I can just dump my timestamps straight from the database onto the page, call $.timeago(’selector’), and bam — a perfectly human readable, self updating time representation.

If you’re one of the many that agree with the extremely scientific survey above, then I highly recommend you give this jQuery plugin a try – here’s the plugins homepage.

Code Drive-By: Edit Anywhere Component for CakePHP

8 Aug

I call this a code drive-by because I’m just going to dump the code without much explanation.  When I have time I’ll come back and walk through it and turn it into a useful article on the CakePHP bakery.

This component allows you to manage content (primarily text blocks) on a site if you’re logged in.  The editor pops up in a thickbox.

Some requirements off the top of my head:

  • CakePHP, duh.
  • jquery
  • thickbox
  • Auth Component

Again, sorry for the drive-by but hopefully someone will get use out of this.

controller =& $controller;
			App::import('Model', 'Setting');
			$this->Setting = new Setting();
		}

		function read($field = null) {
			return $this->render($field);
		}

		function render($field = null)
		{
			$content = $this->Setting->findByField($field);

			if(!empty($content)) {
				return $this->output($field, $content['Setting']['value']);
			} else {
				return $this->output($field, '');
			}
		}

		function output($field, $str)
		{
			$output = $str;
			if($this->controller->u['User']['role'] == 'admin') {
				$output .= $this->editButton($field);
			}
			return nl2br($output);
		}

		function editButton($field) {
			return '';
		}
	}
?>

And my Settings Controller looks like:

Setting->findByField($field);

			if(!empty($content)) {
				$this->Setting->id = $content['Setting']['id'];
			}

			if(!empty($this->data))
			{
				$content['Setting'] = array(
					'field' => $field,
					'value' => $this->data['Setting']['value'],
				);

				$this->Setting->save($content);
				die($this->redirect($_REQUEST['r']));
			}

			$this->set(compact('field', 'content'));
		}
	}
?>