/*global $gp:false, gpui:false, gplinks:false, gpinputs:false isadmin:false, gpBase:false, strip_from:false, gpRem:false, gpBLink:false */ /*jshint forin:true, noarg:true, noempty:true, eqeqeq:true, bitwise:true, strict:true, undef:true, unused:true, curly:true, browser:true, jquery:true, indent:4, maxerr:100, newcap:false, white:false*/ //"use strict"; var gp_editor = false; $gp.curr_edit_id = null; $gp.interface = []; // storage for editing interfaces $gp.cached = {}; $gp.defaults = {}; $gp.editors = []; // storage for editing objects /** * Get the coordinates for positioning editable area overlays * */ $gp.Coords = function(area){ if( area.hasClass('inner_size') ){ area = area.children().first(); } var loc = area.offset(); loc.w = area.outerWidth(); loc.h = area.outerHeight(); return loc; }; /** * Create a
in the #gp_admin_html space * */ $gp.div = function(id,div_class){ var div = $('#'+id); div_class = div_class || ''; if( div.length === 0 ){ div = $('
').appendTo('#gp_admin_html'); } return div; }; /** * Dynamically load inline editing * */ $gp.links.inline_edit_generic = function(evt,arg){ evt.preventDefault(); var area_id = $gp.AreaId( $(this) ); $gp.LoadEditor(this.href, area_id, arg); //show editor when a edit link is clicked in the var $target = $(evt.target); if( $target.closest('.panel_tabs').length && typeof(gp_editing) != 'undefined' ){ if( $target.data('mode') == 'extra' ){ gp_editing.is_extra_mode = true; }else{ gp_editing.is_extra_mode = false; } gp_editing.ShowEditor(); } } $gp._loadingEditor = false; $gp.LoadEditor = function(href, area_id, arg){ area_id = area_id || 0; if( area_id === $gp.curr_edit_id ){ return; } if( $gp._loadingEditor ){ console.log('editor still loading'); return; } $gp._loadingEditor = true; //first time editing, get default $gp.links, $gp.inputs, $gp.response if( typeof(gp_editing) == 'undefined' ){ $gp.defaults['links'] = $gp.Properties($gp.links); $gp.defaults['inputs'] = $gp.Properties($gp.inputs); $gp.defaults['response'] = $gp.Properties($gp.response); } $gp.CacheInterface(function(){ //set the current editing interface aside so the new one can be created if( typeof(gp_editing) !== 'undefined' ){ if( gp_editing.RestoreCached(area_id) ){ $gp._loadingEditor = false; return; } }else{ $gp.LoadStyle('/include/css/inline_edit.css'); $gp.LoadStyle('/include/css/manage_sections.css'); // $gp.LoadStyle('/include/css/manage_sections_compact.css'); // alternative compact style } $gp.curr_edit_id = area_id; var $edit_div = $gp.CurrentDiv(); $gp.DefinedObjects(); $gp.loading(); //legacy inline editing support //can also be used for development/troubleshooting if( typeof(gplinks[arg]) === 'function' ){ gplinks[arg].call(this,arg,evt); $gp._loadingEditor = false; return; } var script = strip_from(href,'#'); script += '&gpreq=json&defined_objects='+$gp.DefinedObjects(); if( arg != 'manage_sections' ){ script += '&cmd=inlineedit&area_id='+area_id+'§ion='+$edit_div.data('gp-section'); } //get the new editor $.getScript( script,function(data){ if( data === 'false' ){ alert($gp.error); $gp.loaded(); $gp._loadingEditor = false; return; } if( typeof(gp_editor.wake) == 'function' ){ gp_editor.wake(); } $gp._loadingEditor = false; }); }); }; /** * Get object properties * */ $gp.Properties = function(obj){ var properties = []; for( var i in obj ){ if( obj.hasOwnProperty(i) ){ properties.push(i); } } return properties; } /** * Get the current editing div * */ $gp.CurrentDiv = function(){ return $('#ExtraEditArea'+$gp.curr_edit_id); } /** * Cache the current editing interface * */ $gp.CacheInterface = function(callback){ $gp.CurrentDiv().removeClass('gp_edit_current'); //if gp_editing is not defined then we don't have anything to cache yet if( typeof(gp_editing) == 'undefined' ){ callback.call(); return; } //only continue if we can save gp_editing.SaveChanges(function(){ if( typeof(gp_editor.sleep) == 'function' ){ gp_editor.sleep(); } $gp.interface[$gp.curr_edit_id] = $('#ck_area_wrap').children().detach(); $gp.editors[$gp.curr_edit_id] = gp_editor; //cache $gp.links that were defined by the current gp_editor $gp.cached[$gp.curr_edit_id] = {}; $gp.CacheObjects( 'links' ); $gp.CacheObjects( 'inputs' ); $gp.CacheObjects( 'response' ); $('.cktabs .ckeditor_control.selected').removeClass('selected'); callback.call(); }); } /** * Cache $gp.links, $gp.inputs and $gp.Response * ?? gpresponse, gplinks, gpinputs ?? */ $gp.CacheObjects = function(type, cache_loc){ var from = $gp[type]; $gp.cached[$gp.curr_edit_id][type] = {}; for( var i in from ){ if( !from.hasOwnProperty(i) ){ continue; } if( $gp.defaults[type].indexOf(i) > -1 ){ continue; } $gp.cached[$gp.curr_edit_id][type][i] = from[i]; } } /** * Restore $gp.links, $gp.inputs and $gp.Response * ?? gpresponse, gplinks, gpinputs ?? */ $gp.RestoreObjects = function(type, id){ var from = $gp.cached[id][type]; for( var i in from ){ if( !from.hasOwnProperty(i) ){ continue; } $gp[type][i] = from[i]; } } /** * Send to the server which javascript objects are already defined * */ $gp.defined_objects = []; $gp.DefinedObjects = function(){ //get all objects the first time if( typeof(gp_editing) == 'undefined' ){ for( var i in window ) { if( typeof(window[i]) != 'object' ){ continue; } $gp.defined_objects.push(i); } } //compare with $gp.defined_objects var objects = []; for( var i in window ) { if( typeof(window[i]) != 'object' ){ continue; } if( $gp.defined_objects.indexOf(i) != -1 ){ continue; } objects.push(i); } return objects.join(','); } /** * Remote Browse * @param object evt Event object * */ $gp.links.remote = function(evt){ evt.preventDefault(); var src = $gp.jPrep(this.href,'gpreq=body'); //can remote install if( gpRem ){ var pathArray = window.location.href.split( '/' ); var url = pathArray[0] + '//' + pathArray[2]+gpBase; if( window.location.href.indexOf('index.php') > 0 ){ url += '/index.php'; } src += '&inUrl='+encodeURIComponent(url) + '&gpRem='+encodeURIComponent(gpRem); } //40px margin + 17px*2 border + 20px padding + 10 (extra padding) = approx 130 // var height = $gp.$win.height() - 130; var opts = {context:'iframe',width:780}; var iframe = '