Uploaded image for project: 'ZK'
  1. ZK
  2. ZK-4924

Provide an API to rewrite a relative url to an absolute url in embedding context

XMLWordPrintable

    • Icon: New Feature New Feature
    • Resolution: Won't Do
    • Icon: Normal Normal
    • None
    • 9.6.0
    • ZK Client Engine
    • Security Level: Jimmy
    • None

      User Story

      As an developer, I must resolve relative urls used in my ZK application while embedded so that I can serve the relevant resources (scripts, files, urls, etc)

      Currently, there is no easy way to rewrite the urls received from server-side

      Acceptance Criteria

      Either have relative URLs for scripts, stylesheets, images, files, resources, etc automatically rewritten when the zEmbedded library is available in the page, or have an easy to use API on the zEmbedded object which accepts a relative url and rewrite it to match the current zEmbedded context for easy overrides to existing widgets. ideally both.

      Details

      Current override method require blind-fetch of resource URLs and using string operations:

       

      function retrieveZkUrlContext(){
        		if(!zEmbedded || !zEmbedded._zk_loadedResource){
        			return;
        		}
       		var resource = Object.keys(zEmbedded._zk_loadedResource)[0];
       		return resource.split("zkau")[0];
       	}
      	zk.afterLoad("zk", function () {
      	    var _xcmd0 = {};
      	    zk.override(zAu.cmd0, _xcmd0, {
      	        download: function(url) {
      	        	var newUrl = null;
      	        	if( retrieveZkUrlContext()){
      		        	newUrl = retrieveZkUrlContext() + "zkau" + url.split("zkau")[1];
      	        	} else{
      	        		newUrl = url;
      	        	}
      				var result = _xcmd0.download.apply(this, [newUrl]);
      				return result;
      	        }
      	     });
      	});
      

            DevChu DevChu
            MDuchemin MDuchemin
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: