Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from vlad-ghita/9d7c6a04ba39bf36e7581685ec71f3…
…314dc18e3f Structural rework
- Loading branch information
Showing
27 changed files
with
2,057 additions
and
1,351 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* Simple JavaScript Inheritance | ||
* By John Resig http://ejohn.org/ | ||
* MIT Licensed. | ||
* | ||
* Inspired by base2 and Prototype | ||
* | ||
* http://ejohn.org/blog/simple-javascript-inheritance/ | ||
* | ||
* eg: | ||
* | ||
var Person = Class.extend({ | ||
init: function(isDancing){ | ||
this.dancing = isDancing; | ||
}, | ||
dance: function(){ | ||
return this.dancing; | ||
} | ||
}); | ||
var Ninja = Person.extend({ | ||
init: function(){ | ||
this._super( false ); | ||
}, | ||
dance: function(){ | ||
// Call the inherited version of dance() | ||
return this._super(); | ||
}, | ||
swingSword: function(){ | ||
return true; | ||
} | ||
}); | ||
var p = new Person(true); | ||
p.dance(); // => true | ||
var n = new Ninja(); | ||
n.dance(); // => false | ||
n.swingSword(); // => true | ||
// Should all be true | ||
p instanceof Person && p instanceof Class && | ||
n instanceof Ninja && n instanceof Person && n instanceof Class | ||
* | ||
* | ||
*/ | ||
|
||
|
||
|
||
;(function(){ | ||
var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/; | ||
|
||
// The base Class implementation (does nothing) | ||
this.Class = function(){}; | ||
|
||
// Create a new Class that inherits from this class | ||
Class.extend = function(prop) { | ||
var _super = this.prototype; | ||
|
||
// Instantiate a base class (but only create the instance, | ||
// don't run the init constructor) | ||
initializing = true; | ||
var prototype = new this(); | ||
initializing = false; | ||
|
||
// Copy the properties over onto the new prototype | ||
for (var name in prop) { | ||
// Check if we're overwriting an existing function | ||
prototype[name] = typeof prop[name] == "function" && | ||
typeof _super[name] == "function" && fnTest.test(prop[name]) ? | ||
(function(name, fn){ | ||
return function() { | ||
var tmp = this._super; | ||
|
||
// Add a new ._super() method that is the same method | ||
// but on the super-class | ||
this._super = _super[name]; | ||
|
||
// The method only need to be bound temporarily, so we | ||
// remove it when we're done executing | ||
var ret = fn.apply(this, arguments); | ||
this._super = tmp; | ||
|
||
return ret; | ||
}; | ||
})(name, prop[name]) : | ||
prop[name]; | ||
} | ||
|
||
// The dummy class constructor | ||
function Class() { | ||
// All construction is actually done in the init method | ||
if ( !initializing && this.init ) | ||
this.init.apply(this, arguments); | ||
} | ||
|
||
// Populate our constructed prototype object | ||
Class.prototype = prototype; | ||
|
||
// Enforce the constructor to be what we expect | ||
Class.prototype.constructor = Class; | ||
|
||
// And make this class extendable | ||
Class.extend = arguments.callee; | ||
|
||
return Class; | ||
}; | ||
})(); |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
(function($, undefined){ | ||
|
||
var sblp = { | ||
views: {}, | ||
current: '', | ||
edit: false, | ||
sort_order: false, | ||
|
||
init: function(){ | ||
$.ajax({ | ||
type: "GET", | ||
url: Symphony.Context.get('root')+'/symphony/extension/selectbox_link_field_plus/', | ||
data: { get: this.getEntryIDFromURL() }, | ||
dataType: "JSON", | ||
success: function(data){ | ||
sblp.sort_order = data; | ||
|
||
// this allows the views to register their instances | ||
$(sblp).trigger('sblp.initialization'); | ||
} | ||
}); | ||
|
||
// Create some elements, and style them: | ||
$("body").append('<div id="sblp-white"></div>'); | ||
$("body").append('<div id="sblp-popup"><a href="javascript:void(0)" class="sblp-close">×</a><iframe id="sblp-iframe" src="" width="100%" height="100%" border="0" /></div>'); | ||
|
||
sblp.$white = $("#sblp-white"); | ||
sblp.$popup = $("#sblp-popup"); | ||
sblp.$iframe = $("#sblp-iframe"); | ||
|
||
// When the iFrame is loaded, hide some Symphony stuff: | ||
sblp.$iframe.hide().load(function(){ | ||
var iFrame = document.getElementById('sblp-iframe'); | ||
// Look at the URL to determine if the window should be closed (checks if the string '/edit/' occurs in it). | ||
var url = iFrame.contentWindow.location.href; | ||
if( url.indexOf('/edit/') != -1 && sblp.edit == false ){ | ||
|
||
// Entry had errors. Keep window open | ||
if( $(".invalid", iFrame.contentWindow.document).length > 0){ | ||
return false; | ||
} | ||
|
||
// Entry saved successfully. Close! | ||
sblp.$popup.hide(); | ||
|
||
// Get the ID: | ||
var a = url.split('/edit/'); | ||
a = a[1].split('/'); | ||
var id = a[0]; | ||
|
||
sblp.restoreCurrentView(id); | ||
} | ||
else{ | ||
sblp.edit = false; | ||
|
||
// Hide the header and the footer of the edit window (after all, it's just a default Symphony page): | ||
$("#header, #footer, button.delete, #context .actions a.drawer, #drawer-drawer-left", iFrame.contentWindow.document).hide(); | ||
$("#contents", iFrame.contentWindow.document).css('margin-left', 0); | ||
|
||
// Edit the form to send the parent ID | ||
var a = window.location.href.split('/edit/'); | ||
if( a.length == 2 ){ | ||
$("form", iFrame.contentWindow.document).append('<input type="hidden" name="sblp_parent" value="'+parseInt(a[1].replace('/', ''))+'" />'); | ||
} | ||
|
||
sblp.$iframe.show(); | ||
} | ||
}); | ||
|
||
// Close window-button: | ||
sblp.$popup.on('click', "a.sblp-close", function(){ | ||
sblp.$popup.add(sblp.$white).hide(); | ||
return false; | ||
}); | ||
|
||
// store sort order | ||
$('#contents > form').on('submit', function(){ | ||
var data = {}; | ||
for( var i in sblp.views ){ | ||
data['id-'+sblp.views[i].$view.data('id')] = sblp.views[i].sort_order; | ||
} | ||
|
||
$('<input/>', { | ||
name: "sblp_sortorder", | ||
type: "text", | ||
value: JSON.stringify(data) | ||
}).appendTo(this); | ||
|
||
this.submit(); | ||
}); | ||
}, | ||
|
||
/** | ||
* Get sort order for specific field | ||
* | ||
* @param field_id | ||
*/ | ||
getSorting: function(field_id){ | ||
return this.sort_order['id-'+field_id]; | ||
}, | ||
|
||
/** | ||
* Restore current view. | ||
* | ||
* @param id - extra ID to add to selected options | ||
*/ | ||
restoreCurrentView: function(id){ | ||
var current_view = this.views[ this.current ]; | ||
|
||
// Get the selected items: | ||
var selected = current_view.$view.find(current_view.settings["select"]).val(); | ||
// Prevent an empty array (when no items are selected): | ||
if( selected == null ){ | ||
selected = []; | ||
} | ||
if( typeof selected == 'string' ){ | ||
selected = [selected]; | ||
} | ||
|
||
if( id !== null && id !== undefined ) | ||
selected.push(id); | ||
|
||
// Reload the view with native Symphony functionality: | ||
$("#"+sblp.current).load(window.location.href+' #'+sblp.current, function(){ | ||
// Restore the selected items: | ||
current_view.$view.find(current_view.settings["select"]).val(selected); | ||
|
||
// Initialize the view: | ||
current_view.update(); | ||
|
||
sblp.$white.hide(); | ||
}); | ||
}, | ||
|
||
/** | ||
* Get entry ID from URL | ||
*/ | ||
getEntryIDFromURL: function(){ | ||
var entryID = String(window.location).split('/edit/'); | ||
if( entryID.length == 2 ){ | ||
entryID = entryID[1].split('/')[0]; | ||
}else{ | ||
entryID = 0; | ||
} | ||
return entryID; | ||
} | ||
}; | ||
|
||
// export sblp | ||
window.sblp = sblp; | ||
|
||
$(document).ready(function(){ | ||
sblp.init(); | ||
}); | ||
|
||
})(jQuery); |
Oops, something went wrong.