User Tools

Site Tools


public:tellmaps_url_and_seo

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
public:tellmaps_url_and_seo [2014/04/25 14:05]
honzik
public:tellmaps_url_and_seo [2014/05/05 07:27] (current)
honzik
Line 21: Line 21:
   * a **local hash**, ''#​local-hash''​ - this is used as a normal hash, i.e. to scroll to a given part of document (top / bottom etc).   * a **local hash**, ''#​local-hash''​ - this is used as a normal hash, i.e. to scroll to a given part of document (top / bottom etc).
  
-[Implementation] code to retriveve params from hash part: https://​gist.github.com/​miohtama/​1570295+[Implementation ​details] code to retriveve params from hash part: https://​gist.github.com/​miohtama/​1570295
  
 ===== URLs for Tellmaps ===== ===== URLs for Tellmaps =====
Line 58: Line 58:
  
 ===== Javascript implementation ===== ===== Javascript implementation =====
- 
-The main idea is to create a Javascript service which can be called from existing system modules to perform URL-based operations. We shall call it ''​TellmapsURIService''​. 
- 
-API should provide: 
- 
-<code javascript>​ 
- 
-/** 
- * Register a given path. 
- * @param uri_string string with path. May contain variables in the format of '':​variable''​ - will be passed to callback on request. 
- * @param callback - a function in the form of function(passed_vars,​ get_vars, path_not_changed) 
- ​* ​  ​passed_vars is a collection of { variable_name:​ variable_value } 
- ​* ​  ​get_vars is a collection of param set (GET) in form of { param_name: param_value } with automatic completion from default_params_object 
- ​* ​  ​path_not_changed is true if path component changed from last state, false if only params / local hash changed 
- ​* ​  ​function will be called whenever URI matches on URI change 
- * @param default_params_object - contains default GET values in form of { param_name: param_def_value } 
- * @return none 
- **/ 
-function registerURI( uri_string, callback, default_params_object ) { 
-... 
- 
-/** 
- * Register a callback to be executed on URI parse fail 
- * @param callback - a function in the form of function(current_uri,​ error_message) 
- ​* ​  ​current_uri is the processed shebang that failed 
- ​* ​  ​error_message does show a messages the class outputted on fail 
- ​* ​  ​function will be called on URI parse failed 
- * @return none 
- **/ 
-function onURIFail( callback ) { 
-... 
- 
-/** 
- * Manual call to path change 
- * @param path - string, path component part 
- * @param get_params - get param collection in the form of { param_name : param_value } 
- * @param local_hash - string, local hash part 
- * @return true/false on success / fail 
- **/ 
-function changeURI( path, get_params, local_hash ) { 
-... 
-</​code>​ 
- 
-So, on the side of implementor into existing system, the role is to: call the ''​TellmapsURIService.registerURI''​ in the setup phase of the application and register a callback to provide given task, for every "​static"​ piece of content. 
- 
-Whenever somebody clicks on a link with the hashbang syntax, uses browser history or manually changes the location, callbacks should trigger. 
- 
-''​TellmapsURIService''​ should handle events of location change and/or parse the [variable, get, local hash] data before use. 
- 
-===== Javascript implementation - version B (revised) ===== 
- 
-A more thought-through approach to API: 
  
 <code javascript>​ <code javascript>​
Line 117: Line 65:
  * @param settings - collection {}, specify these properties:  * @param settings - collection {}, specify these properties:
  ​* ​ - path - string - define a path component with possible :variable notation  ​* ​ - path - string - define a path component with possible :variable notation
- ​* ​ - onPathChange ​- function(variables) - pass in a callback to be called whenever a path changes+ ​* ​ - onPathSet ​- function(variables) - pass in a callback to be called whenever a path changes
  ​* ​                   - @param variables - collection of passed :variable values ​  ​* ​                   - @param variables - collection of passed :variable values ​
  ​* ​                       in format { variable_name:​ variable_value }  ​* ​                       in format { variable_name:​ variable_value }
Line 133: Line 81:
  ​* ​ - debug - boolean - provide console.log outputs on various operations of this registerURI block              ​  ​* ​ - debug - boolean - provide console.log outputs on various operations of this registerURI block              ​
  * @return none  * @return none
 + ​* ​
 + * notes:
 + ​* ​ - all callbacks have "​this"​ set which can access the following:
 + ​* ​   getHash(), getParams(),​ getParamString(),​ getPath()
 + ​* ​   please do not use their "​set"​ counterparts directly.
  **/  **/
-function ​registerURI( settings ) {+function ​registerUri( settings ) {
 ... ...
  
Line 144: Line 97:
  ​* ​  ​function will be called on URI parse failed  ​* ​  ​function will be called on URI parse failed
  * @return none  * @return none
 + ​* ​
 + * notes:
 + ​* ​ - callback has "​this"​ set which can access the following:
 + ​* ​   getHash(), getParams(),​ getParamString(),​ getPath()
 + ​* ​   please do not use their "​set"​ counterparts directly.
  **/  **/
-function ​onURIFail( callback ) {+function ​onUriFail( callback ) {
 ... ...
  
 /** /**
- ​* ​Manual call to path change+ ​* ​Get proper URI string ​to be used in parts of the app
  * @param path - string, path component part  * @param path - string, path component part
  * @param get_params - get param collection in the form of { param_name : param_value }  * @param get_params - get param collection in the form of { param_name : param_value }
  * @param local_hash - string, local hash part  * @param local_hash - string, local hash part
- * @return ​true/false on success / fail+ * @return ​string final string
  **/  **/
-function ​changeURIPath( path, get_params, local_hash ) {+function ​getUriString( path, get_params, local_hash ) {
 ... ...
  
-/** 
- * Manual call to path-only change, get_params and local_hash remains the same 
- * @param path - string, path component part 
- * @return true/false on success / fail 
- **/ 
-function changeURIPath( path ) { 
-... 
- 
-/** 
- * Manual call to params-only change, path and local_hash remains the same 
- * @param get_params - get param collection in the form of { param_name : param_value } 
- * @return true/false on success / fail 
- **/ 
-function changeURIParams( get_params ) { 
-... 
- 
-/** 
- * Manual call to local_hash-only change, path and params remains the same 
- * @param local_hash - string, local hash part 
- * @return true/false on success / fail 
- **/ 
-function changeURILocalHash( local_hash ) { 
-... 
 </​code>​ </​code>​
  
Line 188: Line 123:
  
 <​code>​ <​code>​
-(change a path component) -> trigger ​onPathChange ​-> trigger onParamChange -> trigger onHashChange+(change a path component) -> trigger ​onPathSet ​-> trigger onParamChange -> trigger onHashChange
 (change a params part) -> trigger onParamChange only (change a params part) -> trigger onParamChange only
 (change a local hash part) -> trigger onHashChange only (change a local hash part) -> trigger onHashChange only
public/tellmaps_url_and_seo.1398434744.txt.gz · Last modified: 2014/04/25 14:05 by honzik