Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

version 0.2

  • Loading branch information...
commit ecd5ac42e09f025d7b4b75a049eb3a8f5c2ce378 1 parent edc18cd
@jfragoulis authored
View
15 EMetabox.php
@@ -1,8 +1,7 @@
<?php
/**
- * @author Yannis Fragkoulis <yannis.fragkoulis@gmail.com>
- * @version $Id$
+ *
*/
class EMetabox extends CWidget
{
@@ -61,7 +60,7 @@ public function init()
$this->htmlOptions['class'] = 'metabox';
if ($this->loadingIndicator == null)
- $this->loadingIndicator = CHtml::image(self::$_assets . '/loader.gif', 'loading...', array('class' => 'loader hide'));
+ $this->loadingIndicator = CHtml::image(self::$_assets . '/loader.gif', 'loading...');
$this->url = CHtml::normalizeUrl($this->url);
@@ -71,22 +70,24 @@ public function init()
}
/**
- *
+ * Register extension assets
*/
public function run()
{
$id = $this->id;
echo CHtml::tag('div', $this->htmlOptions, $this->initHtml);
- echo $this->loadingIndicator;
- // Register extension assets
+ /* @var $cs CClientScript */
$cs = Yii::app()->getClientScript();
$min = YII_DEBUG ? '.min' : '';
// Register jQuery scripts
+ $cs->registerCoreScript('jquery');
+ $cs->registerCoreScript('bbq');
+
$options = CJavaScript::encode($this->options);
- $cs->registerScriptFile(self::$_assets . '/jquery.metabox' . $min . '.js', CClientScript::POS_END);
+ $cs->registerScriptFile(self::$_assets . '/jquery.metabox' . $min . '.js');
$cs->registerScript('metabox#' . $id, "$('#{$id}').metabox({$options});", CClientScript::POS_READY);
}
View
36 assets/jquery.metabox.js
@@ -4,11 +4,13 @@
!function( $ ){
- "use strict"
+ "use strict";
var Metabox = function ( element, options ) {
- this.$element = $(element)
- this.options = $.extend({}, $.fn.metabox.defaults, options)
+ this.$element = $(element);
+ this.options = $.extend({}, $.fn.metabox.defaults, options);
+
+ this.options.errorText = this.options.errorText.replace('{url}', this.options.url);
if(this.options.loadingContainer)
this.options.loadingContainer = $(this.options.loadingContainer);
@@ -23,7 +25,7 @@
if(this.options.refreshOnInit)
this.refresh();
- }
+ };
Metabox.prototype = {
@@ -67,13 +69,13 @@
success : function(data) {
$box.$element.removeClass($box.options.loadingClass);
$box.options.loadingContainer.html('');
- $box.options.handleResponse.apply($box, [data])
+ $box.options.handleResponse.apply($box, [data]);
$box.options.afterRefresh.apply($box, [data]);
},
error: function (XHR, textStatus, errorThrown) {
var ret, err;
$box.$element.removeClass($box.options.loadingClass);
- $box.$element.show().next().hide();
+ $box.options.loadingContainer.html($box.options.errorText);
if (XHR.readyState === 0 || XHR.status === 0) {
return;
}
@@ -113,7 +115,7 @@
$.ajax(options);
}
- }
+ };
/* METABOX PLUGIN DEFINITION
@@ -123,17 +125,18 @@
return this.each(function () {
var $this = $(this)
, data = $this.data('metabox')
- , options = typeof option == 'object' && option
- if (!data) $this.data('metabox', (data = new Metabox(this, options)))
+ , options = typeof option == 'object' && option;
+ if (!data) $this.data('metabox', (data = new Metabox(this, options)));
- if (option == 'refresh') data.refresh(ajaxoptions)
+ if (option == 'refresh') data.refresh(ajaxoptions);
})
- }
+ };
$.fn.metabox.defaults = {
loadingText: 'loading...',
loadingClass: 'metabox-loading',
loadingContainer: null,
+ errorText: 'Error loading {url}',
url: null,
data : {},
type : 'GET',
@@ -144,15 +147,10 @@
handleResponse: function(data) {
this.$element.html(data);
},
- afterRefresh: function(data) {}
- }
+ afterRefresh: function(data) {},
+ debug: true
+ };
$.fn.metabox.Constructor = Metabox
- /* METABOX DATA-API
- * =============== */
-
- $(function () {
- })
-
}( window.jQuery );
View
2  assets/jquery.metabox.min.js
@@ -1 +1 @@
-!function($){"use strict"var Metabox=function(element,options){this.$element=$(element)this.options=$.extend({},$.fn.metabox.defaults,options)if(this.options.loadingContainer)this.options.loadingContainer=$(this.options.loadingContainer);else this.options.loadingContainer=this.$element;if(this.options.refreshTimeout>0)this.createTimeout();else if(this.options.refreshInterval>0)this.createInterval();if(this.options.refreshOnInit)this.refresh()}Metabox.prototype={constructor:Metabox,createTimeout:function(){var $this=this;setTimeout(function(){$this.refresh()},this.options.refreshTimeout)},createInterval:function(){var $this=this;setInterval(function(){$this.refresh()},this.options.refreshInterval)},refresh:function(options){var customError;if(options&&options.error!==undefined){customError=options.error;delete options.error}var $box=this;options=$.extend({type:this.options.type,url:this.options.url,data:this.options.data,beforeSend:function(){$box.$element.addClass($box.options.loadingClass);$box.options.loadingContainer.html($box.options.loadingText);$box.options.beforeRefresh.apply($box)},success:function(data){$box.$element.removeClass($box.options.loadingClass);$box.options.loadingContainer.html('');$box.options.handleResponse.apply($box,[data])$box.options.afterRefresh.apply($box,[data])},error:function(XHR,textStatus,errorThrown){var ret,err;$box.$element.removeClass($box.options.loadingClass);$box.$element.show().next().hide();if(XHR.readyState===0||XHR.status===0){return}if(customError!==undefined){ret=customError(XHR);if(ret!==undefined&&!ret){return}}switch(textStatus){case'timeout':err='The request timed out!';break;case'parsererror':err='Parser error!';break;case'error':if(XHR.status&&!/^\s*$/.test(XHR.status)){err='Error '+XHR.status}else{err='Error'}if(XHR.responseText&&!/^\s*$/.test(XHR.responseText)){err=err+': '+XHR.responseText}break}if(err)alert(err)}},options||{});if(options.data!==undefined&&options.type==='GET'){options.url=$.param.querystring(options.url,options.data);options.data={}}$.ajax(options)}}$.fn.metabox=function(option,ajaxoptions){return this.each(function(){var $this=$(this),data=$this.data('metabox'),options=typeof option=='object'&&option if(!data)$this.data('metabox',(data=new Metabox(this,options)))if(option=='refresh')data.refresh(ajaxoptions)})}$.fn.metabox.defaults={loadingText:'loading...',loadingClass:'metabox-loading',loadingContainer:null,url:null,data:{},type:'GET',refreshOnInit:false,refreshTimeout:0,refreshInterval:0,beforeRefresh:function(){},handleResponse:function(data){this.$element.html(data)},afterRefresh:function(data){}}$.fn.metabox.Constructor=Metabox $(function(){})}(window.jQuery);
+!function($){"use strict";var Metabox=function(element,options){this.$element=$(element);this.options=$.extend({},$.fn.metabox.defaults,options);this.options.errorText=this.options.errorText.replace('{url}',this.options.url);if(this.options.loadingContainer)this.options.loadingContainer=$(this.options.loadingContainer);else this.options.loadingContainer=this.$element;if(this.options.refreshTimeout>0)this.createTimeout();else if(this.options.refreshInterval>0)this.createInterval();if(this.options.refreshOnInit)this.refresh()};Metabox.prototype={constructor:Metabox,createTimeout:function(){var $this=this;setTimeout(function(){$this.refresh()},this.options.refreshTimeout)},createInterval:function(){var $this=this;setInterval(function(){$this.refresh()},this.options.refreshInterval)},refresh:function(options){var customError;if(options&&options.error!==undefined){customError=options.error;delete options.error}var $box=this;options=$.extend({type:this.options.type,url:this.options.url,data:this.options.data,beforeSend:function(){$box.$element.addClass($box.options.loadingClass);$box.options.loadingContainer.html($box.options.loadingText);$box.options.beforeRefresh.apply($box)},success:function(data){$box.$element.removeClass($box.options.loadingClass);$box.options.loadingContainer.html('');$box.options.handleResponse.apply($box,[data]);$box.options.afterRefresh.apply($box,[data])},error:function(XHR,textStatus,errorThrown){var ret,err;$box.$element.removeClass($box.options.loadingClass);$box.options.loadingContainer.html($box.options.errorText);if(XHR.readyState===0||XHR.status===0){return}if(customError!==undefined){ret=customError(XHR);if(ret!==undefined&&!ret){return}}switch(textStatus){case'timeout':err='The request timed out!';break;case'parsererror':err='Parser error!';break;case'error':if(XHR.status&&!/^\s*$/.test(XHR.status)){err='Error '+XHR.status}else{err='Error'}if(XHR.responseText&&!/^\s*$/.test(XHR.responseText)){err=err+': '+XHR.responseText}break}if(err)alert(err)}},options||{});if(options.data!==undefined&&options.type==='GET'){options.url=$.param.querystring(options.url,options.data);options.data={}}$.ajax(options)}};$.fn.metabox=function(option,ajaxoptions){return this.each(function(){var $this=$(this),data=$this.data('metabox'),options=typeof option=='object'&&option;if(!data)$this.data('metabox',(data=new Metabox(this,options)));if(option=='refresh')data.refresh(ajaxoptions)})};$.fn.metabox.defaults={loadingText:'loading...',loadingClass:'metabox-loading',loadingContainer:null,errorText:'Error loading {url}',url:null,data:{},type:'GET',refreshOnInit:false,refreshTimeout:0,refreshInterval:0,beforeRefresh:function(){},handleResponse:function(data){this.$element.html(data)},afterRefresh:function(data){},debug:true};$.fn.metabox.Constructor=Metabox}(window.jQuery);
Please sign in to comment.
Something went wrong with that request. Please try again.