Permalink
Browse files

Initial commit. Not sure if I'll actually use this...

  • Loading branch information...
0 parents commit beac8effc42a26264bf4c930325deff651538143 @Daniel15 committed Jan 16, 2011
Showing with 103 additions and 0 deletions.
  1. +6 −0 classes/controller/template.php
  2. +47 −0 classes/daniel15/controller/template.php
  3. +50 −0 js/d15.js
@@ -0,0 +1,6 @@
+<?php defined('SYSPATH') or die('No direct script access.');
+
+class Controller_Template extends Daniel15_Controller_Template
+{
+}
+?>
@@ -0,0 +1,47 @@
+<?php defined('SYSPATH') or die('No direct script access.');
+
+class Daniel15_Controller_Template extends Kohana_Controller_Template
+{
+ protected $internal = false;
+
+ public function before()
+ {
+ // Is this an internal request (HMVC)?
+ if ($this->request !== Request::instance())
+ {
+ $this->internal = true;
+ $this->template = 'template_internal';
+ }
+ // Otherwise, AJAX request?
+ elseif (Request::$is_ajax)
+ {
+ $this->template = 'template_ajax_html';
+ }
+
+ parent::before();
+
+ // Set up some common things
+ $this->session = Session::instance();
+ $this->logged_in = Membership::instance()->logged_in();
+ $this->member = Membership::instance()->get_member();
+ // Set body ID
+ $this->template->body_id = $this->request->controller . '-' . $this->request->action;
+
+ // Check if we have a top message...
+ // Why is there no flashdata in Kohana 3?? O_O
+ if (($message = $this->session->get('message', null)) != null)
+ {
+ $this->template->message = $message;
+ $this->session->delete('message');
+ }
+ }
+
+ public function after()
+ {
+ $this->template->logged_in = $this->logged_in;
+ $this->template->member = $this->member;
+
+ parent::after();
+ }
+}
+?>
@@ -0,0 +1,50 @@
+/*
+ * D15 - Daniel15 framework stuff :-)
+ * Author: Daniel15 <dan.cx>
+ */
+
+// Various string functions
+String.implement(
+{
+ /**
+ * Uppercase the first letter of the string
+ */
+ ucfirst: function()
+ {
+ return this.charAt(0).toUpperCase() + this.slice(1);
+ }
+});
+
+var D15 = D15 || {};
+/**
+ * Onload handler for Daniel15 framework. Calls onload functions depending on the current page.
+ * Splits the body ID by hyphen (-), uses first piece as the main object, and other pieces as
+ * sub-objects. Non-existant init methods are ignored (no error is thrown).
+ *
+ * Example: An ID of "site-projects" would call Site.init() and Site.Projects.init().
+ * site-projects-foo would call Site.init(), Site.Projects.init() and Site.Foo.init().
+ * "blog" would call Blog.init().
+ *
+ */
+D15.onload = function()
+{
+ var id_pieces = document.body.id.split('-');
+ // First piece is the main object
+ var obj_name = id_pieces.shift().ucfirst();
+ var obj = window[obj_name];
+ // If we don't have the object, just die
+ if (obj === undefined)
+ return;
+
+ // Call the object initialisation function
+ obj.init && obj.init();
+ // Go through each piece, and call the initialisation on it.
+ id_pieces.each(function(piece)
+ {
+ piece = piece.ucfirst();
+ obj[piece] && obj[piece].init && obj[piece].init();
+ });
+};
+
+// Fire it up!
+window.addEvent('domready', D15.onload);

0 comments on commit beac8ef

Please sign in to comment.